Html encode job log messages, add new IModule property to allow modules to specify Runtime support, provide feedback during module content import, remove default EditMode option at the Page level (should be implemented at Module level) - resolves issue where Admin modules could not be deleted, include link to Event Log in AddModuleMessage for Error message type, fixed fallback support for themes in siterouter, integrated auth policy into site templates for Module Creator
This commit is contained in:
@ -122,7 +122,7 @@ namespace Oqtane.Controllers
|
||||
var pages = _pages.GetPages(module.SiteId).ToList();
|
||||
foreach (Page page in pages)
|
||||
{
|
||||
if (page.PageId != pageModule.PageId && !page.EditMode)
|
||||
if (page.PageId != pageModule.PageId && !page.Path.StartsWith("admin/"))
|
||||
{
|
||||
_pageModules.AddPageModule(new PageModule { PageId = page.PageId, ModuleId = pageModule.ModuleId, Title = pageModule.Title, Pane = pageModule.Pane, Order = pageModule.Order, ContainerType = pageModule.ContainerType });
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ namespace Oqtane.Controllers
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page);
|
||||
|
||||
if (!page.EditMode)
|
||||
if (!page.Path.StartsWith("admin/"))
|
||||
{
|
||||
var modules = _modules.GetModules(page.SiteId).Where(item => item.AllPages).ToList();
|
||||
foreach (Module module in modules)
|
||||
@ -163,7 +163,6 @@ namespace Oqtane.Controllers
|
||||
page.Order = 0;
|
||||
page.IsNavigation = false;
|
||||
page.Url = "";
|
||||
page.EditMode = false;
|
||||
page.ThemeType = parent.ThemeType;
|
||||
page.LayoutType = parent.LayoutType;
|
||||
page.DefaultContainerType = parent.DefaultContainerType;
|
||||
|
@ -38,7 +38,7 @@ namespace Oqtane.Infrastructure
|
||||
List<Site> sites = siteRepository.GetSites().ToList();
|
||||
foreach (Site site in sites)
|
||||
{
|
||||
log += "Processing Notifications For Site: " + site.Name + "\n\n";
|
||||
log += "Processing Notifications For Site: " + site.Name + "<br />";
|
||||
|
||||
// get site settings
|
||||
List<Setting> sitesettings = settingRepository.GetSettings(EntityNames.Site, site.SiteId).ToList();
|
||||
@ -101,14 +101,14 @@ namespace Oqtane.Infrastructure
|
||||
catch (Exception ex)
|
||||
{
|
||||
// error
|
||||
log += ex.Message + "\n\n";
|
||||
log += ex.Message + "<br />";
|
||||
}
|
||||
}
|
||||
log += "Notifications Delivered: " + sent + "\n\n";
|
||||
log += "Notifications Delivered: " + sent + "<br />";
|
||||
}
|
||||
else
|
||||
{
|
||||
log += "SMTP Not Configured" + "\n\n";
|
||||
log += "SMTP Not Configured" + "<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +116,6 @@ namespace Oqtane.Infrastructure
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<string, string> GetSettings(List<Setting> settings)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
|
@ -42,7 +42,6 @@ namespace Oqtane.SiteTemplates
|
||||
Icon = "home",
|
||||
IsNavigation = true,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -89,7 +88,6 @@ namespace Oqtane.SiteTemplates
|
||||
Icon = "lock-locked",
|
||||
IsNavigation = true,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, Constants.RegisteredRole, true),
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -114,7 +112,6 @@ namespace Oqtane.SiteTemplates
|
||||
Icon = "target",
|
||||
IsNavigation = true,
|
||||
IsPersonalizable = true,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
|
@ -30,7 +30,6 @@ namespace Oqtane.SiteTemplates
|
||||
Icon = "home",
|
||||
IsNavigation = true,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
|
@ -22,6 +22,9 @@
|
||||
<Content Remove="wwwroot\Modules\Templates\**" />
|
||||
<EmbeddedResource Remove="wwwroot\Modules\Templates\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Scripts\Tenant.01.00.02.01.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Scripts\Master.00.00.00.00.sql" />
|
||||
<EmbeddedResource Include="Scripts\Master.00.09.00.00.sql" />
|
||||
@ -32,6 +35,7 @@
|
||||
<EmbeddedResource Include="Scripts\Tenant.00.09.02.00.sql" />
|
||||
<EmbeddedResource Include="Scripts\Tenant.01.00.01.00.sql" />
|
||||
<EmbeddedResource Include="Scripts\Tenant.01.00.01.01.sql" />
|
||||
<EmbeddedResource Include="Scripts\Tenant.01.00.02.01.sql" />
|
||||
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.1.0.0.sql" />
|
||||
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.Uninstall.sql" />
|
||||
</ItemGroup>
|
||||
|
@ -58,7 +58,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.LockLocked,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -88,7 +87,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Person,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -119,7 +117,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Person,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -149,7 +146,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Person,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -175,7 +171,7 @@ namespace Oqtane.Repository
|
||||
// admin pages
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Admin", Parent = "", Path = "admin", Icon = "", IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "Admin", Parent = "", Path = "admin", Icon = "", IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -203,7 +199,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Home,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -231,7 +226,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Layers,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -259,7 +253,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.People,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -287,7 +280,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Person,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -315,7 +307,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.LockLocked,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -343,7 +334,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.File,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -371,7 +361,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.Trash,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.AdminRole, true),
|
||||
@ -401,7 +390,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.MagnifyingGlass,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -428,7 +416,6 @@ namespace Oqtane.Repository
|
||||
Icon = Icons.List,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -450,7 +437,7 @@ namespace Oqtane.Repository
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Site Management", Parent = "Admin", Path = "admin/sites", Icon = Icons.Globe, IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "Site Management", Parent = "Admin", Path = "admin/sites", Icon = Icons.Globe, IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -472,7 +459,7 @@ namespace Oqtane.Repository
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Module Management", Parent = "Admin", Path = "admin/modules", Icon = Icons.Browser, IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "Module Management", Parent = "Admin", Path = "admin/modules", Icon = Icons.Browser, IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -494,7 +481,7 @@ namespace Oqtane.Repository
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Theme Management", Parent = "Admin", Path = "admin/themes", Icon = Icons.Brush, IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "Theme Management", Parent = "Admin", Path = "admin/themes", Icon = Icons.Brush, IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -516,7 +503,7 @@ namespace Oqtane.Repository
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Scheduled Jobs", Parent = "Admin", Path = "admin/jobs", Icon = Icons.Timer, IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "Scheduled Jobs", Parent = "Admin", Path = "admin/jobs", Icon = Icons.Timer, IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -544,7 +531,6 @@ namespace Oqtane.Repository
|
||||
Icon = "spreadsheet",
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -572,7 +558,6 @@ namespace Oqtane.Repository
|
||||
Icon = "medical-cross",
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
EditMode = true,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -594,7 +579,7 @@ namespace Oqtane.Repository
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "System Update", Parent = "Admin", Path = "admin/update", Icon = Icons.Aperture, IsNavigation = false, IsPersonalizable = false, EditMode = true,
|
||||
Name = "System Update", Parent = "Admin", Path = "admin/update", Icon = Icons.Aperture, IsNavigation = false, IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, Constants.HostRole, true),
|
||||
@ -754,7 +739,6 @@ namespace Oqtane.Repository
|
||||
Order = 1,
|
||||
Url = "",
|
||||
IsNavigation = pagetemplate.IsNavigation,
|
||||
EditMode = pagetemplate.EditMode,
|
||||
ThemeType = "",
|
||||
LayoutType = "",
|
||||
DefaultContainerType = "",
|
||||
|
9
Oqtane.Server/Scripts/Tenant.01.00.02.01.sql
Normal file
9
Oqtane.Server/Scripts/Tenant.01.00.02.01.sql
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
|
||||
Version 1.0.2.1 migration script
|
||||
|
||||
*/
|
||||
|
||||
ALTER TABLE [dbo].[Page]
|
||||
DROP COLUMN EditMode
|
||||
GO
|
@ -50,7 +50,7 @@
|
||||
if (PageState.Action == "Edit")
|
||||
{
|
||||
_id = Int32.Parse(PageState.QueryString["id"]);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id, ModuleState.ModuleId);
|
||||
if ([Module] != null)
|
||||
{
|
||||
_name = [Module].Name;
|
||||
@ -82,7 +82,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id, ModuleState.ModuleId);
|
||||
[Module].Name = _name;
|
||||
await [Module]Service.Update[Module]Async([Module]);
|
||||
await logger.LogInformation("[Module] Updated {[Module]}", [Module]);
|
||||
|
@ -95,7 +95,7 @@ else
|
||||
{
|
||||
try
|
||||
{
|
||||
await [Module]Service.Delete[Module]Async([Module].[Module]Id);
|
||||
await [Module]Service.Delete[Module]Async([Module].[Module]Id, ModuleState.ModuleId);
|
||||
await logger.LogInformation("[Module] Deleted {[Module]}", [Module]);
|
||||
_[Module]s = await [Module]Service.Get[Module]sAsync(ModuleState.ModuleId);
|
||||
StateHasChanged();
|
||||
|
@ -8,12 +8,12 @@ namespace [Owner].[Module]s.Services
|
||||
{
|
||||
Task<List<[Module]>> Get[Module]sAsync(int ModuleId);
|
||||
|
||||
Task<[Module]> Get[Module]Async(int [Module]Id);
|
||||
Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
|
||||
|
||||
Task<[Module]> Add[Module]Async([Module] [Module]);
|
||||
|
||||
Task<[Module]> Update[Module]Async([Module] [Module]);
|
||||
|
||||
Task Delete[Module]Async(int [Module]Id);
|
||||
Task Delete[Module]Async(int [Module]Id, int ModuleId);
|
||||
}
|
||||
}
|
||||
|
@ -18,32 +18,44 @@ namespace [Owner].[Module]s.Services
|
||||
_siteState = siteState;
|
||||
}
|
||||
|
||||
private string Apiurl=> CreateApiUrl(_siteState.Alias, "[Module]");
|
||||
private string Apiurl => CreateApiUrl(_siteState.Alias, "[Module]");
|
||||
|
||||
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
|
||||
{
|
||||
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>($"{Apiurl}?moduleid={ModuleId}");
|
||||
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(CreateAuthPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
|
||||
return [Module]s.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<[Module]> Get[Module]Async(int [Module]Id)
|
||||
public async Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
|
||||
{
|
||||
return await GetJsonAsync<[Module]>($"{Apiurl}/{[Module]Id}");
|
||||
return await GetJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
|
||||
}
|
||||
|
||||
public async Task<[Module]> Add[Module]Async([Module] [Module])
|
||||
{
|
||||
return await PostJsonAsync<[Module]>($"{Apiurl}?entityid={[Module].ModuleId}", [Module]);
|
||||
return await PostJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}?entityid={[Module].ModuleId}", [Module].ModuleId), [Module]);
|
||||
}
|
||||
|
||||
public async Task<[Module]> Update[Module]Async([Module] [Module])
|
||||
{
|
||||
return await PutJsonAsync<[Module]>($"{Apiurl}/{[Module].[Module]Id}?entityid={[Module].ModuleId}", [Module]);
|
||||
return await PutJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
|
||||
}
|
||||
|
||||
public async Task Delete[Module]Async(int [Module]Id)
|
||||
public async Task Delete[Module]Async(int [Module]Id, int ModuleId)
|
||||
{
|
||||
await DeleteAsync($"{Apiurl}/{[Module]Id}");
|
||||
await DeleteAsync(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
|
||||
}
|
||||
|
||||
private string CreateAuthPolicyUrl(string Url, int ModuleId)
|
||||
{
|
||||
if (Url.Contains("?"))
|
||||
{
|
||||
return Url + "&entityid=" + ModuleId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Url + "?entityid=" + ModuleId.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
@ -14,16 +15,22 @@ namespace [Owner].[Module]s.Controllers
|
||||
{
|
||||
private readonly I[Module]Repository _[Module]s;
|
||||
private readonly ILogManager _logger;
|
||||
protected int _entityId = -1;
|
||||
|
||||
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger)
|
||||
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger, IHttpContextAccessor accessor)
|
||||
{
|
||||
_[Module]s = [Module]s;
|
||||
_logger = logger;
|
||||
|
||||
if (accessor.HttpContext.Request.Query.ContainsKey("entityid"))
|
||||
{
|
||||
_entityId = int.Parse(accessor.HttpContext.Request.Query["entityid"]);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/<controller>?moduleid=x
|
||||
[HttpGet]
|
||||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
[Authorize(Policy = "ViewModule")]
|
||||
public IEnumerable<[Module]> Get(string moduleid)
|
||||
{
|
||||
return _[Module]s.Get[Module]s(int.Parse(moduleid));
|
||||
@ -31,18 +38,23 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
[Authorize(Policy = "ViewModule")]
|
||||
public [Module] Get(int id)
|
||||
{
|
||||
return _[Module]s.Get[Module](id);
|
||||
[Module] [Module] = _[Module]s.Get[Module](id);
|
||||
if ([Module] != null && [Module].ModuleId != _entityId)
|
||||
{
|
||||
[Module] = null;
|
||||
}
|
||||
return [Module];
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public [Module] Post([FromBody] [Module] [Module])
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||
{
|
||||
[Module] = _[Module]s.Add[Module]([Module]);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "[Module] Added {[Module]}", [Module]);
|
||||
@ -52,10 +64,10 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public [Module] Put(int id, [FromBody] [Module] [Module])
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||
{
|
||||
[Module] = _[Module]s.Update[Module]([Module]);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "[Module] Updated {[Module]}", [Module]);
|
||||
@ -65,11 +77,15 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_[Module]s.Delete[Module](id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
|
||||
[Module] [Module] = _[Module]s.Get[Module](id);
|
||||
if ([Module] != null && [Module].ModuleId == _entityId)
|
||||
{
|
||||
_[Module]s.Delete[Module](id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
This is the location where static resources such as images, style sheets, or scripts for this module will be located. Static assets can be organized in subfolders. When the module package is deployed the assets will be extracted under the web root in a folder that matches the module namespace.
|
@ -28,8 +28,14 @@
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
||||
|
||||
public override string Actions => "Add,Edit";
|
||||
|
||||
public override List<Resource> Resources => new List<Resource>()
|
||||
{
|
||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
||||
};
|
||||
|
||||
int _id;
|
||||
string _name;
|
||||
string _createdby;
|
||||
@ -44,7 +50,7 @@
|
||||
if (PageState.Action == "Edit")
|
||||
{
|
||||
_id = Int32.Parse(PageState.QueryString["id"]);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id, ModuleState.ModuleId);
|
||||
if ([Module] != null)
|
||||
{
|
||||
_name = [Module].Name;
|
||||
@ -76,7 +82,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id);
|
||||
[Module] [Module] = await [Module]Service.Get[Module]Async(_id, ModuleState.ModuleId);
|
||||
[Module].Name = _name;
|
||||
await [Module]Service.Update[Module]Async([Module]);
|
||||
await logger.LogInformation("[Module] Updated {[Module]}", [Module]);
|
||||
|
@ -61,6 +61,11 @@ else
|
||||
<!-- The content above is for informational purposes only and can be safely removed -->
|
||||
|
||||
@code {
|
||||
public override List<Resource> Resources => new List<Resource>()
|
||||
{
|
||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
||||
};
|
||||
|
||||
List<[Module]> _[Module]s;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@ -80,7 +85,7 @@ else
|
||||
{
|
||||
try
|
||||
{
|
||||
await [Module]Service.Delete[Module]Async([Module].[Module]Id);
|
||||
await [Module]Service.Delete[Module]Async([Module].[Module]Id, ModuleState.ModuleId);
|
||||
await logger.LogInformation("[Module] Deleted {[Module]}", [Module]);
|
||||
_[Module]s = await [Module]Service.Get[Module]sAsync(ModuleState.ModuleId);
|
||||
StateHasChanged();
|
||||
|
@ -8,12 +8,12 @@ namespace [Owner].[Module]s.Services
|
||||
{
|
||||
Task<List<[Module]>> Get[Module]sAsync(int ModuleId);
|
||||
|
||||
Task<[Module]> Get[Module]Async(int [Module]Id);
|
||||
Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
|
||||
|
||||
Task<[Module]> Add[Module]Async([Module] [Module]);
|
||||
|
||||
Task<[Module]> Update[Module]Async([Module] [Module]);
|
||||
|
||||
Task Delete[Module]Async(int [Module]Id);
|
||||
Task Delete[Module]Async(int [Module]Id, int ModuleId);
|
||||
}
|
||||
}
|
||||
|
@ -18,32 +18,44 @@ namespace [Owner].[Module]s.Services
|
||||
_siteState = siteState;
|
||||
}
|
||||
|
||||
private string Apiurl=> CreateApiUrl(_siteState.Alias, "[Module]");
|
||||
private string Apiurl => CreateApiUrl(_siteState.Alias, "[Module]");
|
||||
|
||||
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
|
||||
{
|
||||
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>($"{Apiurl}?moduleid={ModuleId}");
|
||||
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(CreateAuthPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
|
||||
return [Module]s.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<[Module]> Get[Module]Async(int [Module]Id)
|
||||
public async Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
|
||||
{
|
||||
return await GetJsonAsync<[Module]>($"{Apiurl}/{[Module]Id}");
|
||||
return await GetJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
|
||||
}
|
||||
|
||||
public async Task<[Module]> Add[Module]Async([Module] [Module])
|
||||
{
|
||||
return await PostJsonAsync<[Module]>($"{Apiurl}?entityid={[Module].ModuleId}", [Module]);
|
||||
return await PostJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}?entityid={[Module].ModuleId}", [Module].ModuleId), [Module]);
|
||||
}
|
||||
|
||||
public async Task<[Module]> Update[Module]Async([Module] [Module])
|
||||
{
|
||||
return await PutJsonAsync<[Module]>($"{Apiurl}/{[Module].[Module]Id}?entityid={[Module].ModuleId}", [Module]);
|
||||
return await PutJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
|
||||
}
|
||||
|
||||
public async Task Delete[Module]Async(int [Module]Id)
|
||||
public async Task Delete[Module]Async(int [Module]Id, int ModuleId)
|
||||
{
|
||||
await DeleteAsync($"{Apiurl}/{[Module]Id}");
|
||||
await DeleteAsync(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
|
||||
}
|
||||
|
||||
private string CreateAuthPolicyUrl(string Url, int ModuleId)
|
||||
{
|
||||
if (Url.Contains("?"))
|
||||
{
|
||||
return Url + "&entityid=" + ModuleId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Url + "?entityid=" + ModuleId.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
@ -14,16 +15,22 @@ namespace [Owner].[Module]s.Controllers
|
||||
{
|
||||
private readonly I[Module]Repository _[Module]s;
|
||||
private readonly ILogManager _logger;
|
||||
protected int _entityId = -1;
|
||||
|
||||
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger)
|
||||
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger, IHttpContextAccessor accessor)
|
||||
{
|
||||
_[Module]s = [Module]s;
|
||||
_logger = logger;
|
||||
|
||||
if (accessor.HttpContext.Request.Query.ContainsKey("entityid"))
|
||||
{
|
||||
_entityId = int.Parse(accessor.HttpContext.Request.Query["entityid"]);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/<controller>?moduleid=x
|
||||
[HttpGet]
|
||||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
[Authorize(Policy = "ViewModule")]
|
||||
public IEnumerable<[Module]> Get(string moduleid)
|
||||
{
|
||||
return _[Module]s.Get[Module]s(int.Parse(moduleid));
|
||||
@ -31,18 +38,23 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
[Authorize(Policy = "ViewModule")]
|
||||
public [Module] Get(int id)
|
||||
{
|
||||
return _[Module]s.Get[Module](id);
|
||||
[Module] [Module] = _[Module]s.Get[Module](id);
|
||||
if ([Module] != null && [Module].ModuleId != _entityId)
|
||||
{
|
||||
[Module] = null;
|
||||
}
|
||||
return [Module];
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public [Module] Post([FromBody] [Module] [Module])
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||
{
|
||||
[Module] = _[Module]s.Add[Module]([Module]);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "[Module] Added {[Module]}", [Module]);
|
||||
@ -52,10 +64,10 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public [Module] Put(int id, [FromBody] [Module] [Module])
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||
{
|
||||
[Module] = _[Module]s.Update[Module]([Module]);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "[Module] Updated {[Module]}", [Module]);
|
||||
@ -65,11 +77,15 @@ namespace [Owner].[Module]s.Controllers
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
[Authorize(Policy = "EditModule")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_[Module]s.Delete[Module](id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
|
||||
[Module] [Module] = _[Module]s.Get[Module](id);
|
||||
if ([Module] != null && [Module].ModuleId == _entityId)
|
||||
{
|
||||
_[Module]s.Delete[Module](id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
This is the location where static resources such as images, style sheets, or scripts for this module will be located. Static assets can be organized in subfolders. When the module package is deployed the assets will be extracted under the web root in a folder that matches the module namespace.
|
Reference in New Issue
Block a user