コード例 #1
0
        public FieldValueViewModel(CustomFieldsViewModel model, [NotNull] FieldWithValue ch, ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            if (ch.Field.SupportsMarkdown())
            {
                DisplayString = new MarkdownString(ch.DisplayString).ToHtmlString(renderer);
            }
            else
            {
                DisplayString = ch.DisplayString.SanitizeHtml();
            }
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;
            Description   = ch.Field.Description.ToHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasValue || !ch.Field.CanHaveValue();

            var hasViewAccess = ch.Field.IsPublic ||
                                model.HasMasterAccess
                                ||
                                (model.HasPlayerAccessToCharacter && ch.Field.CanPlayerView &&
                                 ch.Field.FieldBoundTo == FieldBoundTo.Character)
                                ||
                                (model.HasPlayerClaimAccess && ch.Field.CanPlayerView &&
                                 ch.Field.FieldBoundTo == FieldBoundTo.Claim);

            CanView = hasViewAccess &&
                      (ch.HasValue || (!ch.Field.CanHaveValue() && ch.Field.IsAvailableForTarget(model.Target)));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(
                model.HasMasterAccess,
                model.HasPlayerAccessToCharacter,
                model.HasPlayerClaimAccess,
                model.Target);

            if (ch.Field.HasValueList())
            {
                ValueList         = ch.GetDropdownValues().ToArray();
                PossibleValueList = ch.GetPossibleValues();
            }
            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus;
        }
コード例 #2
0
            public void EnsureEditAccess(FieldWithValue field)
            {
                var accessArguments = Character != null
                    ? new AccessArguments(Character, CurrentUserId)
                    : new AccessArguments(Claim, CurrentUserId);

                var editAccess = field.HasEditAccess(accessArguments);

                if (!editAccess)
                {
                    throw new NoAccessToProjectException(Project, CurrentUserId);
                }
            }
コード例 #3
0
            public void EnsureEditAccess(FieldWithValue field)
            {
                var hasMasterAccess       = Project.HasMasterAccess(CurrentUserId);
                var characterAccess       = Character?.HasPlayerAccess(CurrentUserId) ?? false;
                var hasPlayerAccesToClaim = Claim?.HasPlayerAccesToClaim(CurrentUserId) ?? false;
                var editAccess            = field.HasEditAccess(hasMasterAccess,
                                                                characterAccess, hasPlayerAccesToClaim, Character ?? Claim.GetTarget());

                if (!editAccess)
                {
                    throw new NoAccessToProjectException(Project, CurrentUserId);
                }
            }
コード例 #4
0
        public FieldValueViewModel(
            CustomFieldsViewModel model,
            [NotNull] FieldWithValue ch,
            ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            DisplayString = ch.Field.SupportsMarkdown()
        ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer)
        : ch.DisplayString.SanitizeHtml();
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;
            Description   = ch.Field.Description.ToHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasViewableValue;

            var hasViewAccess = ch.HasViewableValue &&
                                ch.HasViewAccess(model.AccessArguments);

            CanView = hasViewAccess && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(model.AccessArguments, model.Target) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            //if not "HasValues" types, will be empty
            ValueList         = ch.GetDropdownValues().Select(v => new FieldPossibleValueViewModel(v)).ToArray();
            PossibleValueList = ch.GetPossibleValues().Select(v => new FieldPossibleValueViewModel(v)).ToList();

            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus;

            ProjectId = ch.Field.ProjectId;
        }
コード例 #5
0
        public FieldValueViewModel(
            CustomFieldsViewModel model,
            [NotNull] FieldWithValue ch,
            ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            DisplayString = ch.Field.SupportsMarkdown()
                ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer)
                : ch.DisplayString.SanitizeHtml();
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;

            HasMasterAccess = model.AccessArguments.MasterAccess;
            Description     = ch.Field.Description.ToHtmlString();

            MasterDescription = HasMasterAccess ? ch.Field.MasterDescription.ToHtmlString() : "".MarkAsHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasViewableValue;

            CanView = ch.HasViewableValue &&
                      ch.HasViewAccess(model.AccessArguments) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(model.AccessArguments) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));


            // Detecting if field (or its values) has a price or not
            HasPrice = ch.SupportsPricing();

            //if not "HasValues" types, will be empty
            ValueList = ch.GetDropdownValues()
                        .Select(v => new FieldPossibleValueViewModel(v, HasPrice, true)).ToList();
            PossibleValueList = ch.GetPossibleValues(model.AccessArguments).Select(v => new FieldPossibleValueViewModel(v,
                                                                                                                        HasPrice,
                                                                                                                        ValueList.Any(sv =>
                                                                                                                                      sv.ProjectFieldDropdownValueId == v.ProjectFieldDropdownValueId)))
                                .ToArray();

            if (HasPrice)
            {
                if (FieldViewType.SupportsPricingOnField())
                {
                    Price = ch.Field.Price;
                }

                Fee = ch.GetCurrentFee();
            }

            ShowPrice = HasPrice && model.AccessArguments.AnyAccessToClaim;

            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted
                ? MandatoryStatusViewType.Optional
                : (MandatoryStatusViewType)ch.Field.MandatoryStatus;

            ProjectId = ch.Field.ProjectId;

            SetFieldLabels(ch);
        }