Ejemplo n.º 1
0
        public async Task <OpenApiResult> SetResourceAccessRuleSetResourceAccessRulesAsync(
            string tenantId,
            string resourceAccessRuleSetId,
            IEnumerable <ResourceAccessRule> body)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            ResourceAccessRuleSet ruleSet;

            try
            {
                ruleSet = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }

            ruleSet.Rules = body.ToList();

            await store.PersistAsync(ruleSet).ConfigureAwait(false);

            return(this.OkResult());
        }
Ejemplo n.º 2
0
        public async Task <OpenApiResult> GetResourceAccessRuleSetAsync(
            string tenantId,
            string resourceAccessRuleSetId)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            try
            {
                ResourceAccessRuleSet result = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);

                return(this.OkResult(result, "application/json"));
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }
        }
Ejemplo n.º 3
0
        public async Task <OpenApiResult> UpdateResourceAccessRuleSetResourceAccessRulesAsync(
            string tenantId,
            string resourceAccessRuleSetId,
            UpdateOperation operation,
            IEnumerable <ResourceAccessRule> body)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            ResourceAccessRuleSet ruleSet;

            try
            {
                ruleSet = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }

            switch (operation)
            {
            case UpdateOperation.Add:
                ruleSet.Rules.AddRange(body);
                break;

            case UpdateOperation.Remove:
                body.ForEach(rc => ruleSet.Rules.Remove(rc));
                break;
            }

            await store.PersistAsync(ruleSet).ConfigureAwait(false);

            return(this.CreatedResult());
        }