Esempio n. 1
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            RuleId ruleId = new RuleId(id);

            Site site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);

            Rule rule = AuthorizationHelper.GetRule(site, ruleId.Path, ruleId.Users, ruleId.Roles, ruleId.Verbs);

            if (rule == null)
            {
                return(NotFound());
            }

            rule = AuthorizationHelper.UpdateRule(rule, model);

            ManagementUnit.Current.Commit();

            dynamic r = AuthorizationHelper.RuleToJsonModel(rule, site, ruleId.Path);

            if (r.id != id)
            {
                return(LocationChanged(AuthorizationHelper.GetRuleLocation(r.id), r));
            }
            ;

            return(r);
        }
Esempio n. 2
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.authorization == null || !(model.authorization is JObject))
            {
                throw new ApiArgumentException("authorization");
            }

            string authorizationUuid = DynamicHelper.Value(model.authorization.id);

            if (authorizationUuid == null)
            {
                throw new ApiArgumentException("authorization.id");
            }

            // Get the feature id
            AuthorizationId authId = new AuthorizationId(authorizationUuid);
            Site            site   = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);

            if (authId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = ManagementUnit.ResolveConfigScope(model);
            var    section    = AuthorizationHelper.GetSection(site, authId.Path, configPath);

            Rule rule = AuthorizationHelper.CreateRule(model, section);

            if (AuthorizationHelper.GetRule(site, authId.Path, rule.Users, rule.Roles, rule.Verbs) != null)
            {
                throw new AlreadyExistsException("rule");
            }

            section.Rules.Add(rule.AccessType, rule.Users, rule.Roles, rule.Verbs);

            ManagementUnit.Current.Commit();

            dynamic r = AuthorizationHelper.RuleToJsonModel(rule, site, authId.Path);

            return(Created(AuthorizationHelper.GetRuleLocation(r.id), r));
        }