Exemple #1
0
 public QueryDescriptor(string queryName, Type queryModel, QueryModelAttribute attribute, ModelDescriptor modelDescriptor)
 {
     if (string.IsNullOrEmpty(queryName))
     {
         throw new ArgumentException($"{nameof(queryName)} is required", nameof(queryName));
     }
     QueryModel = queryModel ?? throw new ArgumentNullException(nameof(queryModel));
     if (attribute == null)
     {
         throw new ArgumentNullException(nameof(attribute));
     }
     ModelDescriptor = modelDescriptor ?? throw new ArgumentNullException(nameof(modelDescriptor));
     QueryName       = queryName.Trim().ToLower();
     SubNames        = attribute.SubNames?.Split(Separators, StringSplitOptions.RemoveEmptyEntries).Select(p => p.ToLower().Trim()).ToArray() ?? new string[0];
     Init(attribute);
 }
Exemple #2
0
        private void Init(QueryModelAttribute attribute)
        {
            Permissions      = attribute.Permissions;
            AcceptQueryRules =
                attribute.AcceptQueryRules?.Split(Separators, StringSplitOptions.RemoveEmptyEntries)
                .Select(p => p.Trim().ToLower()).ToArray() ?? new string[0];
            DefaultQueryRules =
                attribute.DefaultQueryRules?.Split(Separators, StringSplitOptions.RemoveEmptyEntries)
                .Select(p => p.Trim().ToLower()).ToArray() ?? new string[0];
            AcceptActions = attribute.AcceptActions?.Split(Separators, StringSplitOptions.RemoveEmptyEntries)
                            .Select(p => p.Trim().ToLower()).ToArray() ?? new string[0];
            ExcludeActions = AcceptActions.Length > 0
                                ? new string[0]
                                : attribute.ExcludeActions?.Split(Separators, StringSplitOptions.RemoveEmptyEntries)
                             .Select(p => p.Trim().ToLower()).ToArray() ?? new string[0];

            ReadPolicy   = attribute.ReadPolicy;
            CreatePolicy = attribute.CreatePolicy;
            UpdatePolicy = attribute.UpdatePolicy;
            DeletePolicy = attribute.DeletePolicy;
            if (OnlyOwnerCanRead && string.IsNullOrEmpty(ReadPolicy))
            {
                throw new InspectException($"When {nameof(QueryPermission.OnlyOwnerRead)} is enabled the {nameof(ReadPolicy)} must be required");
            }
            if (OnlyOwnerCanCreate && string.IsNullOrEmpty(CreatePolicy))
            {
                throw new InspectException($"When {nameof(QueryPermission.OnlyOwnerCreate)} is enabled the {nameof(CreatePolicy)} must be required");
            }
            if (OnlyOwnerCanUpdate && string.IsNullOrEmpty(UpdatePolicy))
            {
                throw new InspectException($"When {nameof(QueryPermission.OnlyOwnerUpdate)} is enabled the {nameof(UpdatePolicy)} must be required");
            }
            if (OnlyOwnerCanDelete && string.IsNullOrEmpty(DeletePolicy))
            {
                throw new InspectException($"When {nameof(QueryPermission.OnlyOwnerDelete)} is enabled the {nameof(DeletePolicy)} must be required");
            }
            Validate       = attribute.Validate;
            DefaultOrderBy = attribute.DefaultOrderBy;
        }