EntityNames replacements
This commit is contained in:
parent
d7b95f5b2c
commit
7feee22b32
|
@ -100,12 +100,12 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
parentid = folders[0].FolderId;
|
||||
_parentId = _folders[0].FolderId;
|
||||
List<PermissionString> permissionstrings = new List<PermissionString>();
|
||||
permissionstrings.Add(new PermissionString { PermissionName = PermissionNames.Browse, Permissions = Constants.AdminRole });
|
||||
permissionstrings.Add(new PermissionString { PermissionName = PermissionNames.View, Permissions = Constants.AdminRole });
|
||||
permissionstrings.Add(new PermissionString { PermissionName = PermissionNames.Edit, Permissions = Constants.AdminRole });
|
||||
permissions = UserSecurity.SetPermissionStrings(permissionstrings);
|
||||
_permissions = UserSecurity.SetPermissionStrings(permissionstrings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<label class="control-label">Permissions: </label>
|
||||
</td>
|
||||
<td>
|
||||
<PermissionGrid EntityName="ModuleDefinition" PermissionNames=PermissionNames.Utilize Permissions="@permissions" @ref="permissiongrid" />
|
||||
<PermissionGrid EntityName="ModuleDefinition" PermissionNames=PermissionNames.Utilize Permissions="@_permissions" @ref="_permissionGrid" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public Models.File Put(int id, [FromBody] Models.File File)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Folder", File.Folder.FolderId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, File.Folder.FolderId, PermissionNames.Edit))
|
||||
{
|
||||
File = _files.UpdateFile(File);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "File Updated {File}", File);
|
||||
|
@ -140,7 +140,7 @@ namespace Oqtane.Controllers
|
|||
public void Delete(int id)
|
||||
{
|
||||
Models.File file = _files.GetFile(id);
|
||||
if (_userPermissions.IsAuthorized(User, "Folder", file.Folder.FolderId, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Folder, file.Folder.FolderId, PermissionNames.Edit))
|
||||
{
|
||||
_files.DeleteFile(id);
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public Folder Put(int id, [FromBody] Folder Folder)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Folder", Folder.FolderId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, Folder.FolderId, PermissionNames.Edit))
|
||||
{
|
||||
if (string.IsNullOrEmpty(Folder.Path) && Folder.ParentId != null)
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public void Put(int siteid, int folderid, int? parentid)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "Folder", folderid, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Folder, folderid, PermissionNames.Edit))
|
||||
{
|
||||
int order = 1;
|
||||
List<Folder> folders = _folders.GetFolders(siteid).ToList();
|
||||
|
@ -175,7 +175,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "Folder", id, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Folder, id, PermissionNames.Edit))
|
||||
{
|
||||
_folders.DeleteFolder(id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Folder Deleted {FolderId}", id);
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public Models.Module Post([FromBody] Models.Module Module)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Page", Module.PageId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, Module.PageId, PermissionNames.Edit))
|
||||
{
|
||||
Module = _modules.AddModule(Module);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module);
|
||||
|
@ -108,7 +108,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public Models.Module Put(int id, [FromBody] Models.Module Module)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Module", Module.ModuleId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, Module.ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
Module = _modules.UpdateModule(Module);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Updated {Module}", Module);
|
||||
|
@ -127,7 +127,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "Module", id, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Module, id, PermissionNames.Edit))
|
||||
{
|
||||
_modules.DeleteModule(id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Deleted {ModuleId}", id);
|
||||
|
@ -145,7 +145,7 @@ namespace Oqtane.Controllers
|
|||
public string Export(int moduleid)
|
||||
{
|
||||
string content = "";
|
||||
if (_userPermissions.IsAuthorized(User, "Module", moduleid, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Module, moduleid, PermissionNames.Edit))
|
||||
{
|
||||
content = _modules.ExportModule(moduleid);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ namespace Oqtane.Controllers
|
|||
public bool Import(int moduleid, [FromBody] string Content)
|
||||
{
|
||||
bool success = false;
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Module", moduleid, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, moduleid, PermissionNames.Edit))
|
||||
{
|
||||
success = _modules.ImportModule(moduleid, Content);
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace Oqtane.Controllers
|
|||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
{
|
||||
Page = _pages.AddPage(Page);
|
||||
_syncManager.AddSyncEvent("Site", Page.SiteId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, Page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", Page);
|
||||
}
|
||||
else
|
||||
|
@ -156,7 +156,7 @@ namespace Oqtane.Controllers
|
|||
page.IsPersonalizable = false;
|
||||
page.UserId = int.Parse(userid);
|
||||
page = _pages.AddPage(page);
|
||||
_syncManager.AddSyncEvent("Site", page.SiteId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, page.SiteId);
|
||||
|
||||
// copy modules
|
||||
List<PageModule> pagemodules = _pageModules.GetPageModules(page.SiteId).ToList();
|
||||
|
@ -197,10 +197,10 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public Page Put(int id, [FromBody] Page Page)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Page", Page.PageId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, Page.PageId, PermissionNames.Edit))
|
||||
{
|
||||
Page = _pages.UpdatePage(Page);
|
||||
_syncManager.AddSyncEvent("Site", Page.SiteId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, Page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", Page);
|
||||
}
|
||||
else
|
||||
|
@ -217,7 +217,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public void Put(int siteid, int pageid, int? parentid)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "Page", pageid, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, pageid, PermissionNames.Edit))
|
||||
{
|
||||
int order = 1;
|
||||
List<Page> pages = _pages.GetPages(siteid).ToList();
|
||||
|
@ -230,7 +230,7 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
order += 2;
|
||||
}
|
||||
_syncManager.AddSyncEvent("Site", siteid);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, siteid);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Order Updated {SiteId} {PageId} {ParentId}", siteid, pageid, parentid);
|
||||
}
|
||||
else
|
||||
|
@ -246,10 +246,10 @@ namespace Oqtane.Controllers
|
|||
public void Delete(int id)
|
||||
{
|
||||
Page page = _pages.GetPage(id);
|
||||
if (_userPermissions.IsAuthorized(User, "Page", page.PageId, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, page.PageId, PermissionNames.Edit))
|
||||
{
|
||||
_pages.DeletePage(page.PageId);
|
||||
_syncManager.AddSyncEvent("Site", page.SiteId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Deleted {PageId}", page.PageId);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -67,10 +67,10 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public PageModule Post([FromBody] PageModule PageModule)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Page", PageModule.PageId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, PageModule.PageId, PermissionNames.Edit))
|
||||
{
|
||||
PageModule = _pageModules.AddPageModule(PageModule);
|
||||
_syncManager.AddSyncEvent("Page", PageModule.PageId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Page, PageModule.PageId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", PageModule);
|
||||
}
|
||||
else
|
||||
|
@ -87,10 +87,10 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public PageModule Put(int id, [FromBody] PageModule PageModule)
|
||||
{
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, "Module", PageModule.ModuleId, PermissionNames.Edit))
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, PageModule.ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
PageModule = _pageModules.UpdatePageModule(PageModule);
|
||||
_syncManager.AddSyncEvent("Page", PageModule.PageId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Page, PageModule.PageId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Updated {PageModule}", PageModule);
|
||||
}
|
||||
else
|
||||
|
@ -107,7 +107,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
public void Put(int pageid, string pane)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "Page", pageid, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, pageid, PermissionNames.Edit))
|
||||
{
|
||||
int order = 1;
|
||||
List<PageModule> pagemodules = _pageModules.GetPageModules(pageid, pane).OrderBy(item => item.Order).ToList();
|
||||
|
@ -120,7 +120,7 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
order += 2;
|
||||
}
|
||||
_syncManager.AddSyncEvent("Page", pageid);
|
||||
_syncManager.AddSyncEvent(EntityNames.Page, pageid);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Order Updated {PageId} {Pane}", pageid, pane);
|
||||
}
|
||||
else
|
||||
|
@ -136,10 +136,10 @@ namespace Oqtane.Controllers
|
|||
public void Delete(int id)
|
||||
{
|
||||
PageModule pagemodule = _pageModules.GetPageModule(id);
|
||||
if (_userPermissions.IsAuthorized(User, "Page", pagemodule.PageId, PermissionNames.Edit))
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, pagemodule.PageId, PermissionNames.Edit))
|
||||
{
|
||||
_pageModules.DeletePageModule(id);
|
||||
_syncManager.AddSyncEvent("Page", pagemodule.PageId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Page, pagemodule.PageId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Module Deleted {PageModuleId}", id);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -116,25 +116,25 @@ namespace Oqtane.Controllers
|
|||
private bool IsAuthorized(string EntityName, int EntityId, string PermissionName)
|
||||
{
|
||||
bool authorized = false;
|
||||
if (EntityName == "PageModule")
|
||||
if (EntityName == EntityNames.PageModule)
|
||||
{
|
||||
EntityName = "Module";
|
||||
EntityName = EntityNames.Module;
|
||||
EntityId = _pageModules.GetPageModule(EntityId).ModuleId;
|
||||
}
|
||||
switch (EntityName)
|
||||
{
|
||||
case "Host":
|
||||
case EntityNames.Host:
|
||||
authorized = User.IsInRole(Constants.HostRole);
|
||||
break;
|
||||
case "Site":
|
||||
case EntityNames.Site:
|
||||
authorized = User.IsInRole(Constants.AdminRole);
|
||||
break;
|
||||
case "Page":
|
||||
case "Module":
|
||||
case "Folder":
|
||||
case EntityNames.Page:
|
||||
case EntityNames.Module:
|
||||
case EntityNames.Folder:
|
||||
authorized = _userPermissions.IsAuthorized(User, EntityName, EntityId, PermissionName);
|
||||
break;
|
||||
case "User":
|
||||
case EntityNames.User:
|
||||
authorized = true;
|
||||
if (PermissionName == PermissionNames.Edit)
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace Oqtane.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
Site = _sites.UpdateSite(Site);
|
||||
_syncManager.AddSyncEvent("Site", Site.SiteId);
|
||||
_syncManager.AddSyncEvent(EntityNames.Site, Site.SiteId);
|
||||
_logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", Site);
|
||||
}
|
||||
return Site;
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
}
|
||||
User = _users.UpdateUser(User);
|
||||
_syncManager.AddSyncEvent("User", User.UserId);
|
||||
_syncManager.AddSyncEvent(EntityNames.User, User.UserId);
|
||||
User.Password = ""; // remove sensitive information
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", User);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Oqtane.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
UserRole = _userRoles.AddUserRole(UserRole);
|
||||
_syncManager.AddSyncEvent("User", UserRole.UserId);
|
||||
_syncManager.AddSyncEvent(EntityNames.User, UserRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", UserRole);
|
||||
}
|
||||
return UserRole;
|
||||
|
@ -60,7 +60,7 @@ namespace Oqtane.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
UserRole = _userRoles.UpdateUserRole(UserRole);
|
||||
_syncManager.AddSyncEvent("User", UserRole.UserId);
|
||||
_syncManager.AddSyncEvent(EntityNames.User, UserRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Role Updated {UserRole}", UserRole);
|
||||
}
|
||||
return UserRole;
|
||||
|
@ -73,7 +73,7 @@ namespace Oqtane.Controllers
|
|||
{
|
||||
UserRole userRole = _userRoles.GetUserRole(id);
|
||||
_userRoles.DeleteUserRole(id);
|
||||
_syncManager.AddSyncEvent("User", userRole.UserId);
|
||||
_syncManager.AddSyncEvent(EntityNames.User, userRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Deleted {UserRole}", userRole);
|
||||
}
|
||||
}
|
||||
|
|
13
Oqtane.Shared/Shared/EntityNames.cs
Normal file
13
Oqtane.Shared/Shared/EntityNames.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Oqtane.Shared
|
||||
{
|
||||
public class EntityNames
|
||||
{
|
||||
public const string Module = "Module";
|
||||
public const string PageModule = "PageModule";
|
||||
public const string Host = "Host";
|
||||
public const string Site = "Site";
|
||||
public const string Page = "Page";
|
||||
public const string Folder = "Folder";
|
||||
public const string User = "User";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user