Ejemplo n.º 1
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Decode default document id from uuid parameter
            DefaultDocumentId docId = new DefaultDocumentId(id);

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

            if (docId.SiteId != null && site == null)
            {
                // The document id specified a site but we couldn't find it,
                // therefore we can't get the settings for that site
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath);

            DefaultDocumentHelper.UpdateFeatureSettings(model, section);

            ManagementUnit.Current.Commit();

            return(DefaultDocumentHelper.ToJsonModel(site, docId.Path));
        }
Ejemplo n.º 2
0
        public object Get(string id)
        {
            // Decode default document id from uuid parameter
            DefaultDocumentId docId = new DefaultDocumentId(id);

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

            return(DefaultDocumentHelper.ToJsonModel(site, docId.Path));
        }
Ejemplo n.º 3
0
        public object Post([FromBody] dynamic model)
        {
            File file = null;
            DefaultDocumentId docId = null;
            Site site = null;


            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.default_document == null)
            {
                throw new ApiArgumentException("default_document");
            }
            if (!(model.default_document is JObject))
            {
                throw new ApiArgumentException("default_document");
            }
            // Creating a a file instance requires referencing the target feature
            string docUuid = DynamicHelper.Value(model.default_document.id);

            if (docUuid == null)
            {
                throw new ApiArgumentException("default_document.id");
            }

            // Get the default document feature id
            docId = new DefaultDocumentId(docUuid);

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

            // Get target configuration section for addition of file
            string configPath = ManagementUnit.ResolveConfigScope(model);
            DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath);

            // Create default document
            file = FilesHelper.CreateFile(model, section);

            // Add it
            FilesHelper.AddFile(file, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic f = FilesHelper.ToJsonModel(file, site, docId.Path);

            return(Created(FilesHelper.GetLocation(f.id), f));
        }
        public static object ToJsonModelRef(Site site, string path)
        {
            var section = GetDefaultDocumentSection(site, path);

            // Construct id passing possible site and application associated
            DefaultDocumentId docId = new DefaultDocumentId(site?.Id, path, section.IsLocallyStored);

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

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj, false));
        }
        internal static object ToJsonModel(Site site, string path)
        {
            var section = GetDefaultDocumentSection(site, path);

            // Construct id passing possible site and application associated
            DefaultDocumentId docId = new DefaultDocumentId(site?.Id, path, section.IsLocallyStored);

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

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
Ejemplo n.º 6
0
        public void Delete(string id)
        {
            DefaultDocumentId docId = new DefaultDocumentId(id);

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

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

            if (site == null)
            {
                return;
            }

            var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
Ejemplo n.º 7
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Decode default document id from uuid parameter
            DefaultDocumentId docId = new DefaultDocumentId(id);

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

            if (docId.SiteId != null && site == null)
            {
                // The document id specified a site but we couldn't find it,
                // therefore we can't get the settings for that site
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath);

            try {
                // Handle patching of any feature settings
                DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v);

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            ManagementUnit.Current.Commit();

            return(DefaultDocumentHelper.ToJsonModel(site, docId.Path));
        }
Ejemplo n.º 8
0
        public object Get()
        {
            string docUuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(docUuid))
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            DefaultDocumentId docId = new DefaultDocumentId(docUuid);

            // Get site and application file is for if applicable
            Site site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value);

            List <File> files = FilesHelper.GetFiles(site, docId.Path);

            return(new {
                files = files.Select(f => FilesHelper.ToJsonModelRef(f, site, docId.Path))
            });
        }
Ejemplo n.º 9
0
        public async Task Delete(string id)
        {
            DefaultDocumentId docId = new DefaultDocumentId(id);

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

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

            if (site != null)
            {
                var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }

            // When target is webserver, uninstall
            if (docId.SiteId == null && DefaultDocumentHelper.IsFeatureEnabled())
            {
                await DefaultDocumentHelper.SetFeatureEnabled(false);
            }
        }