public object Get(string id)
        {
            GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id);

            GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name));

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

            return(ModuleHelper.GlobalModuleToJsonModel(module));
        }
Exemplo n.º 2
0
        public object Get()
        {
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

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

            dynamic d = ModuleHelper.ModuleFeatureToJsonModel(site, path);

            return(LocationChanged(ModuleHelper.GetModuleGroupLocation(d.id), d));
        }
Exemplo n.º 3
0
        public object Get(string id)
        {
            ModulesId modulesId = new ModulesId(id);

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

            if (modulesId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            return(ModuleHelper.ModuleFeatureToJsonModel(site, modulesId.Path));
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id);

            GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name));

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

            module = ModuleHelper.UpdateGlobalModule(module, model);

            ManagementUnit.Current.Commit();

            return(ModuleHelper.GlobalModuleToJsonModel(module));
        }
        public object Post([FromBody] dynamic model)
        {
            GlobalModule module = null;

            // Create a global module
            module = ModuleHelper.CreateGlobalModule(model);

            // Save it
            ModuleHelper.AddGlobalModule(module);
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic gm = ModuleHelper.GlobalModuleToJsonModel(module);

            return(Created(ModuleHelper.GetGlobalModuleLocation(gm.id), gm));
        }
        public void Delete(string id, [FromBody] dynamic model)
        {
            GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id);

            GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name));

            if (module != null)
            {
                // Delete target global module
                ModuleHelper.DeleteGlobalModule(module);

                // Save changes
                ManagementUnit.Current.Commit();
            }

            // Success
            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
Exemplo n.º 7
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            ModulesId modulesId = new ModulesId(id);

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

            if (modulesId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ModuleHelper.EnsureValidScope(site, modulesId.Path);

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

            // Check for config_scope
            string         configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            ModulesSection section    = ModuleHelper.GetModulesSection(site, modulesId.Path, configPath);

            try {
                DynamicHelper.If <bool>((object)model.run_all_managed_modules_for_all_requests, v => section.RunAllManagedModulesForAllRequests = 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(ModuleHelper.ModuleFeatureToJsonModel(site, modulesId.Path));
        }
        public object Get()
        {
            // Check if the scope of the request is for site
            Site site = ApplicationHelper.ResolveSite();

            // Cannot target the global modules from site scope or deeper
            if (site != null)
            {
                return(NotFound());
            }

            List <GlobalModule> modules = ModuleHelper.GetGlobalModules();

            this.Context.Response.SetItemsCount(modules.Count());

            Fields fields = Context.Request.GetFields();

            return(new {
                global_modules = modules.Select(globalModule => ModuleHelper.GlobalModuleToJsonModelRef(globalModule, fields))
            });
        }
Exemplo n.º 9
0
        public void Delete(string id)
        {
            ModulesId modulesId = new ModulesId(id);

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

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

            if (site == null)
            {
                return;
            }

            ModuleHelper.EnsureValidScope(site, modulesId.Path);

            ModulesSection section = ModuleHelper.GetModulesSection(site, modulesId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
Exemplo n.º 10
0
        public object Get(string id)
        {
            EntryId entryId = new EntryId(id);

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

            Module module = null;

            // Get the enabled modules
            List <Module> modules = ModuleHelper.GetModules(site, entryId.Path);

            module = modules.FirstOrDefault(m => m.Name.Equals(entryId.Name));

            // Module id did not specify an enabled module
            if (module == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            return(ModuleHelper.ModuleToJsonModel(module, site, entryId.Path));
        }
Exemplo n.º 11
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            EntryId entryId = new EntryId(id);

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

            if (entryId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ModuleHelper.EnsureValidScope(site, entryId.Path);

            // Get the enabled modules
            string        configPath = ManagementUnit.ResolveConfigScope(model);
            List <Module> modules    = ModuleHelper.GetModules(site, entryId.Path, configPath);

            Module module = modules.FirstOrDefault(m => m.Name.Equals(entryId.Name));

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

            ModuleHelper.UpdateModule(module, model, site);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic entry = (dynamic)ModuleHelper.ModuleToJsonModel(module, site, entryId.Path);

            if (entry.id != id)
            {
                return(LocationChanged(ModuleHelper.GetModuleEntryLocation(entry.id), entry));
            }

            return(entry);
        }
Exemplo n.º 12
0
        public object Get()
        {
            string modulesUuid = Context.Request.Query[Defines.MODULES_IDENTIFIER];

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

            ModulesId id = new ModulesId(modulesUuid);

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

            List <Module> modules = ModuleHelper.GetModules(site, id.Path);

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

            Fields fields = Context.Request.GetFields();

            return(new {
                entries = modules.Select(module => ModuleHelper.ModuleToJsonModelRef(module, site, id.Path, fields))
            });
        }
Exemplo n.º 13
0
        private void ConfigureModules()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.ModulesResource.Guid, $"{Defines.MODULES_PATH}/{{id?}}", new { controller = "modulegroups" });

            Environment.Hal.ProvideLink(Defines.ModulesResource.Guid, "self", module => new { href = ModuleHelper.GetModuleFeatureLocation(module.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.ModulesResource.Name, _ => {
                var id = GetModulesId(null, null);
                return(new { href = ModuleHelper.GetModuleFeatureLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.ModulesResource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = GetModulesId(s, "/");
                return(new { href = ModuleHelper.GetModuleFeatureLocation(id.Uuid) });
            });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.ModulesResource.Name, app => {
                var appId = new ApplicationId((string)app.id);
                Site s    = SiteHelper.GetSite(appId.SiteId);
                var id    = GetModulesId(s, appId.Path);
                return(new { href = ModuleHelper.GetModuleFeatureLocation(id.Uuid) });
            });
        }
Exemplo n.º 14
0
 private ModulesId GetModulesId(Site site, string path)
 {
     return(new ModulesId(site?.Id, path, ModuleHelper.IsModulesSectionLocal(site, path)));
 }
Exemplo n.º 15
0
        private void ConfigureModuleEntries()
        {
            // Top level resource routes for plugin
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.ModuleEntriesResource.Guid, $"{ Defines.MODULE_ENTRIES_PATH}/{{id?}}", new { controller = "modules" });

            Environment.Hal.ProvideLink(Defines.ModuleEntriesResource.Guid, "self", entry => new { href = ModuleHelper.GetModuleEntryLocation(entry.id) });

            Environment.Hal.ProvideLink(Defines.ModulesResource.Guid, Defines.ModuleEntriesResource.Name, module => new { href = $"/{Defines.MODULE_ENTRIES_PATH}?{Defines.MODULES_IDENTIFIER}={module.id}" });
        }
Exemplo n.º 16
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.modules == null || !(model.modules is JObject))
            {
                throw new ApiArgumentException("modules");
            }

            string modulesUuid = DynamicHelper.Value(model.modules.id);

            if (modulesUuid == null)
            {
                throw new ApiArgumentException("modules.id");
            }

            // Get the feature id
            Module    module    = null;
            ModulesId modulesId = new ModulesId(modulesUuid);
            Site      site      = modulesId.SiteId == null ? null : SiteHelper.GetSite(modulesId.SiteId.Value);

            if (modulesId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ModuleHelper.EnsureValidScope(site, modulesId.Path);

            string         configPath = ManagementUnit.ResolveConfigScope(model);
            ModulesSection section    = ModuleHelper.GetModulesSection(site, modulesId.Path, configPath);

            // The post could either be creating a Managed module, or adding an existing
            // global module to the modules list.
            // This information is taken from the model's type value
            string type = DynamicHelper.Value(model.type);

            if (string.IsNullOrEmpty(type))
            {
                // The module being added is a global/native module

                string name = DynamicHelper.Value(model.name);

                if (string.IsNullOrEmpty(name))
                {
                    throw new ApiArgumentException("name");
                }

                GlobalModule existingGlobalModule = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(name));

                // Adding a global module to the modules list means it must already exist in global modules
                if (existingGlobalModule == null)
                {
                    throw new NotFoundException("name");
                }

                // Add the existing global module
                module = ModuleHelper.AddExistingGlobalModule(existingGlobalModule, section);
                ManagementUnit.Current.Commit();
            }
            else
            {
                // Module being added to enabled modules is a managed module

                // Create module from model
                module = ModuleHelper.CreateManagedModule(model, section);

                // Save it
                ModuleHelper.AddManagedModule(module, section);
                ManagementUnit.Current.Commit();
            }


            //
            // Create response
            dynamic moduleEntry = ModuleHelper.ModuleToJsonModel(module, site, modulesId.Path);

            return(Created(ModuleHelper.GetModuleEntryLocation(moduleEntry.id), moduleEntry));
        }
Exemplo n.º 17
0
        private void ConfigureGlobalModules()
        {
            // Establish MVC route for controller
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.GlobalModulesResource.Guid, $"{Defines.GLOBAL_MODULES_PATH}/{{id?}}", new { controller = "globalmodules" });

            // Self links for resources
            Environment.Hal.ProvideLink(Defines.GlobalModulesResource.Guid, "self", gMod => new { href = ModuleHelper.GetGlobalModuleLocation(gMod.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.GlobalModulesResource.Name, _ => new { href = $"/{Defines.GLOBAL_MODULES_PATH}" });
        }