public void Delete(string id) { 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.NoContent; return; } ModuleHelper.EnsureValidScope(site, entryId.Path); Module module = null; List <Module> modules = ModuleHelper.GetModules(site, entryId.Path); module = modules.FirstOrDefault(m => m.Name.Equals(entryId.Name)); if (module != null) { ModuleHelper.DeleteModule(module.Name, site, entryId.Path, ManagementUnit.ResolveConfigScope()); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
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 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(); }
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); }
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)); }