diff --git a/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor b/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor index 4c3f9f0cf..45ac9d272 100644 --- a/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor +++ b/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor @@ -471,6 +471,12 @@ private async Task ToggleEditMode(bool EditMode) { + Page page = null; + if (PageState.Page.IsPersonalizable && PageState.User != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Registered)) + { + page = await PageService.AddPageAsync(PageState.Page.PageId, PageState.User.UserId); + } + if (_showEditMode) { if (EditMode) @@ -490,9 +496,8 @@ } else { - if (PageState.Page.IsPersonalizable && PageState.User != null) + if (PageState.Page.IsPersonalizable && PageState.User != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Registered)) { - var page = await PageService.AddPageAsync(PageState.Page.PageId, PageState.User.UserId); PageState.EditMode = true; NavigationManager.NavigateTo(NavigateUrl(page.Path, "edit=" + ((PageState.EditMode) ? "true" : "false"))); } diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index cd3a1764a..e1224b161 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -223,12 +223,12 @@ } if (page == null) { - // look for personalized page page = await PageService.GetPageAsync(route.PagePath, site.SiteId); } else { - if (user != null && page.IsPersonalizable) + // look for personalized page + if (user != null && page.IsPersonalizable && !UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList)) { var personalized = await PageService.GetPageAsync(route.PagePath + "/" + user.Username, site.SiteId); if (personalized != null) diff --git a/Oqtane.Server/Controllers/PageController.cs b/Oqtane.Server/Controllers/PageController.cs index e6adba2f3..1cb3eee09 100644 --- a/Oqtane.Server/Controllers/PageController.cs +++ b/Oqtane.Server/Controllers/PageController.cs @@ -9,6 +9,7 @@ using Oqtane.Enums; using Oqtane.Infrastructure; using Oqtane.Repository; +using System.IO; namespace Oqtane.Controllers { @@ -177,64 +178,68 @@ public Page Post(int id, string userid) User user = _userPermissions.GetUser(User); if (parent != null && parent.SiteId == _alias.SiteId && parent.IsPersonalizable && user.UserId == int.Parse(userid)) { - page = new Page(); - page.SiteId = parent.SiteId; - page.ParentId = parent.PageId; - page.Name = user.Username; - page.Path = parent.Path + "/" + page.Name; - page.Title = page.Name + " - " + parent.Name; - page.Order = 0; - page.IsNavigation = false; - page.Url = ""; - page.ThemeType = parent.ThemeType; - page.DefaultContainerType = parent.DefaultContainerType; - page.Icon = parent.Icon; - page.PermissionList = new List() + page = _pages.GetPage(parent.Path + "/" + user.Username, parent.SiteId); + if (page == null) { - new Permission(PermissionNames.View, int.Parse(userid), true), - new Permission(PermissionNames.View, RoleNames.Everyone, true), - new Permission(PermissionNames.Edit, int.Parse(userid), true) - }; - page.IsPersonalizable = false; - page.UserId = int.Parse(userid); - page = _pages.AddPage(page); - - // copy modules - List pagemodules = _pageModules.GetPageModules(page.SiteId).ToList(); - foreach (PageModule pm in pagemodules.Where(item => item.PageId == parent.PageId && !item.IsDeleted)) - { - Module module = new Module(); - module.SiteId = page.SiteId; - module.PageId = page.PageId; - module.ModuleDefinitionName = pm.Module.ModuleDefinitionName; - module.AllPages = false; - module.PermissionList = new List() + page = new Page(); + page.SiteId = parent.SiteId; + page.ParentId = parent.PageId; + page.Name = (!string.IsNullOrEmpty(user.DisplayName)) ? user.DisplayName : user.Username; + page.Path = parent.Path + "/" + user.Username; + page.Title = page.Name + " - " + parent.Name; + page.Order = 0; + page.IsNavigation = false; + page.Url = ""; + page.ThemeType = parent.ThemeType; + page.DefaultContainerType = parent.DefaultContainerType; + page.Icon = parent.Icon; + page.PermissionList = new List() { new Permission(PermissionNames.View, int.Parse(userid), true), new Permission(PermissionNames.View, RoleNames.Everyone, true), new Permission(PermissionNames.Edit, int.Parse(userid), true) }; - module = _modules.AddModule(module); + page.IsPersonalizable = false; + page.UserId = int.Parse(userid); + page = _pages.AddPage(page); - string content = _modules.ExportModule(pm.ModuleId); - if (content != "") + // copy modules + List pagemodules = _pageModules.GetPageModules(page.SiteId).ToList(); + foreach (PageModule pm in pagemodules.Where(item => item.PageId == parent.PageId && !item.IsDeleted)) { - _modules.ImportModule(module.ModuleId, content); - } + Module module = new Module(); + module.SiteId = page.SiteId; + module.PageId = page.PageId; + module.ModuleDefinitionName = pm.Module.ModuleDefinitionName; + module.AllPages = false; + module.PermissionList = new List() + { + new Permission(PermissionNames.View, int.Parse(userid), true), + new Permission(PermissionNames.View, RoleNames.Everyone, true), + new Permission(PermissionNames.Edit, int.Parse(userid), true) + }; + module = _modules.AddModule(module); + + string content = _modules.ExportModule(pm.ModuleId); + if (content != "") + { + _modules.ImportModule(module.ModuleId, content); + } - PageModule pagemodule = new PageModule(); - pagemodule.PageId = page.PageId; - pagemodule.ModuleId = module.ModuleId; - pagemodule.Title = pm.Title; - pagemodule.Pane = pm.Pane; - pagemodule.Order = pm.Order; - pagemodule.ContainerType = pm.ContainerType; + PageModule pagemodule = new PageModule(); + pagemodule.PageId = page.PageId; + pagemodule.ModuleId = module.ModuleId; + pagemodule.Title = pm.Title; + pagemodule.Pane = pm.Pane; + pagemodule.Order = pm.Order; + pagemodule.ContainerType = pm.ContainerType; - _pageModules.AddPageModule(pagemodule); - } + _pageModules.AddPageModule(pagemodule); + } - _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Page, page.PageId, SyncEventActions.Create); - _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId, SyncEventActions.Refresh); + _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Page, page.PageId, SyncEventActions.Create); + _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId, SyncEventActions.Refresh); + } } else { diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 0090dd436..5f28029e0 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -648,10 +648,14 @@ private string GetUserRoles(int userId, int siteId) foreach (UserRole userrole in userroles) { roles += userrole.Role.Name + ";"; - if (userrole.Role.Name == RoleNames.Host && userroles.Where(item => item.Role.Name == RoleNames.Admin).FirstOrDefault() == null) + if (userrole.Role.Name == RoleNames.Host && !userroles.Any(item => item.Role.Name == RoleNames.Admin)) { roles += RoleNames.Admin + ";"; } + if (userrole.Role.Name == RoleNames.Host && !userroles.Any(item => item.Role.Name == RoleNames.Registered)) + { + roles += RoleNames.Registered + ";"; + } } if (roles != "") roles = ";" + roles; return roles;