Exemplo n.º 1
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.handler == null || !(model.handler is JObject))
            {
                throw new ApiArgumentException("handler");
            }
            string handlersUuid = DynamicHelper.Value(model.handler.id);

            if (handlersUuid == null)
            {
                throw new ApiArgumentException("handler.id");
            }

            // Get the feature id
            HandlersId handlersId = new HandlersId(handlersUuid);

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

            string          configPath = ManagementUnit.ResolveConfigScope(model);
            HandlersSection section    = HandlersHelper.GetHandlersSection(site, handlersId.Path, configPath);

            Mapping mapping = MappingsHelper.CreateMapping(model, section);

            MappingsHelper.AddMapping(mapping, section);

            ManagementUnit.Current.Commit();

            dynamic m = MappingsHelper.ToJsonModel(mapping, site, handlersId.Path);

            return(Created(MappingsHelper.GetLocation(m.id), m));
        }
        internal static object ToJsonModel(Site site, string path)
        {
            HandlersSection section = GetHandlersSection(site, path);

            HandlersId id = new HandlersId(site?.Id, path, section.IsLocallyStored);

            // Access Policy
            HandlerAccessPolicy accessPolicy = section.AccessPolicy;

            Dictionary <string, bool> allowedAccess = new Dictionary <string, bool>();

            allowedAccess.Add("read", accessPolicy.HasFlag(HandlerAccessPolicy.Read));
            allowedAccess.Add("write", accessPolicy.HasFlag(HandlerAccessPolicy.Write));
            allowedAccess.Add("execute", accessPolicy.HasFlag(HandlerAccessPolicy.Execute));
            allowedAccess.Add("source", accessPolicy.HasFlag(HandlerAccessPolicy.Source));
            allowedAccess.Add("script", accessPolicy.HasFlag(HandlerAccessPolicy.Script));

            Dictionary <string, bool> remoteAccessPrevention = new Dictionary <string, bool>();

            remoteAccessPrevention.Add("write", accessPolicy.HasFlag(HandlerAccessPolicy.NoRemoteWrite));
            remoteAccessPrevention.Add("read", accessPolicy.HasFlag(HandlerAccessPolicy.NoRemoteRead));
            remoteAccessPrevention.Add("execute", accessPolicy.HasFlag(HandlerAccessPolicy.NoRemoteExecute));
            remoteAccessPrevention.Add("script", accessPolicy.HasFlag(HandlerAccessPolicy.NoRemoteScript));

            var obj = new {
                id                       = id.Uuid,
                scope                    = site == null ? string.Empty : site.Name + path,
                metadata                 = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                allowed_access           = allowedAccess,
                remote_access_prevention = remoteAccessPrevention,
                website                  = SiteHelper.ToJsonModelRef(site)
            };

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
Exemplo n.º 3
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            HandlersId handlersId = new HandlersId(id);

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

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

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

            // Check for config_scope
            string          configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);;
            HandlersSection section    = HandlersHelper.GetHandlersSection(site, handlersId.Path, configPath);

            HandlersHelper.UpdateFeatureSettings(model, section);

            ManagementUnit.Current.Commit();

            return(HandlersHelper.ToJsonModel(site, handlersId.Path));
        }
Exemplo n.º 4
0
        public object Get(string id)
        {
            HandlersId handlersId = new HandlersId(id);

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

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

            return(HandlersHelper.ToJsonModel(site, handlersId.Path));
        }
        public static object ToJsonModelRef(Site site, string path)
        {
            HandlersSection section = GetHandlersSection(site, path);

            HandlersId id = new HandlersId(site?.Id, path, section.IsLocallyStored);


            var obj = new {
                id    = id.Uuid,
                scope = site == null ? string.Empty : site.Name + path
            };

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, false));
        }
Exemplo n.º 6
0
        public void Delete(string id)
        {
            HandlersId handlersId = new HandlersId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

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

            if (site == null)
            {
                return;
            }

            HandlersSection section = HandlersHelper.GetHandlersSection(site, handlersId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
Exemplo n.º 7
0
        public object Get()
        {
            string HandlersUuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(HandlersUuid))
            {
                return(NotFound());
            }

            HandlersId id = new HandlersId(HandlersUuid);

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

            List <Mapping> mappings = MappingsHelper.GetMappings(site, id.Path);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(mappings.Count());

            Fields fields = Context.Request.GetFields();

            return(new {
                entries = mappings.Select(mapping => MappingsHelper.ToJsonModelRef(mapping, site, id.Path, fields))
            });
        }