Ejemplo n.º 1
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var globalRuleId = new InboundRuleId(id);

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

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

            InboundRulesSection section = GlobalRulesHelper.GetSection(site, globalRuleId.Path);
            InboundRule         rule    = (InboundRule)section.InboundRules.FirstOrDefault(r => r.Name.Equals(globalRuleId.Name, StringComparison.OrdinalIgnoreCase));

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

            GlobalRulesHelper.UpdateRule(model, rule, section);

            ManagementUnit.Current.Commit();

            dynamic updatedRule = GlobalRulesHelper.RuleToJsonModel(rule, site, globalRuleId.Path, Context.Request.GetFields(), true);

            if (updatedRule.id != id)
            {
                return(LocationChanged(GlobalRulesHelper.GetRuleLocation(updatedRule.id), updatedRule));
            }

            return(updatedRule);
        }
Ejemplo n.º 2
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);

            if (parentId == null)
            {
                throw new ApiArgumentException("url_rewrite");
            }

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

            string configPath           = ManagementUnit.ResolveConfigScope(model);
            InboundRulesSection section = GlobalRulesHelper.GetSection(site, parentId.Path, configPath);

            InboundRule rule = GlobalRulesHelper.CreateRule(model, section);

            GlobalRulesHelper.AddRule(rule, section, model);

            ManagementUnit.Current.Commit();

            dynamic r = GlobalRulesHelper.RuleToJsonModel(rule, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(GlobalRulesHelper.GetRuleLocation(r.id), r));
        }
Ejemplo n.º 3
0
        private void ConfigureGlobalRules()
        {
            var builder = Environment.Host.RouteBuilder;

            //
            // Use conditional hal to provide global rules only at webserver level
            var hal = Environment.Hal as IConditionalHalService;

            builder.MapWebApiRoute(Defines.GlobalRulesSectionResource.Guid, $"{Defines.GLOBAL_RULES_SECTION_PATH}/{{id?}}", new { controller = "GlobalRulesSection" });
            builder.MapWebApiRoute(Defines.GlobalRulesResource.Guid, $"{Defines.GLOBAL_RULES_PATH}/{{id?}}", new { controller = "GlobalRules" });

            if (hal != null)
            {
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetSectionLocation(ir.id) });
                hal.ProvideLink(Defines.GlobalRulesResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetRuleLocation(ir.id) });

                // Rewrite -> Section
                hal.ProvideLink(
                    Defines.Resource.Guid,
                    Defines.GlobalRulesSectionResource.Name,
                    rewrite => new { href = GlobalRulesHelper.GetSectionLocation(rewrite.id) },
                    rewrite => string.IsNullOrEmpty(rewrite.scope));

                // Section -> Rules
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, Defines.GlobalRulesResource.Name, globalRulesSection => new { href = $"/{Defines.GLOBAL_RULES_PATH}?{Defines.IDENTIFIER}={globalRulesSection.id}" });
            }
        }