From f33fb4d001a441da3a4ea4f332f69124b46a3608 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Fri, 16 Oct 2020 10:23:17 -0500 Subject: [PATCH] Factoring out Constants.AdminPane and Constants.HostUser --- Oqtane.Client/Modules/Admin/Sites/Add.razor | 4 ++-- Oqtane.Client/UI/Pane.razor | 4 ++-- Oqtane.Client/UI/SiteRouter.razor | 2 +- Oqtane.Server/Controllers/UserController.cs | 6 +++--- Oqtane.Server/Infrastructure/DatabaseManager.cs | 8 ++++---- Oqtane.Shared/Shared/Constants.cs | 7 +++++-- Oqtane.Shared/Shared/PaneNames.cs | 9 +++++++++ Oqtane.Shared/Shared/UserNames.cs | 9 +++++++++ 8 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 Oqtane.Shared/Shared/PaneNames.cs create mode 100644 Oqtane.Shared/Shared/UserNames.cs diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index 042e168b..7ee36435 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -216,7 +216,7 @@ else private string _username = string.Empty; private string _password = string.Empty; private bool _integratedsecurity = true; - private string _hostusername = Constants.HostUser; + private string _hostusername = UserNames.Host; private string _hostpassword = string.Empty; private string _name = string.Empty; @@ -311,7 +311,7 @@ else // validate host credentials var user = new User(); user.SiteId = PageState.Site.SiteId; - user.Username = Constants.HostUser; + user.Username = UserNames.Host; user.Password = _hostpassword; user = await UserService.LoginUserAsync(user, false, false); if (user.IsAuthenticated) diff --git a/Oqtane.Client/UI/Pane.razor b/Oqtane.Client/UI/Pane.razor index 5ddd4d70..32abb374 100644 --- a/Oqtane.Client/UI/Pane.razor +++ b/Oqtane.Client/UI/Pane.razor @@ -31,7 +31,7 @@ else protected override void OnParametersSet() { - if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) && Name != Constants.AdminPane) + if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) && Name != PaneNames.Admin) { _useadminborder = true; _paneadminborder = "app-pane-admin-border"; @@ -47,7 +47,7 @@ else { if (PageState.ModuleId != -1 && PageState.Action != Constants.DefaultAction) { - if (Name.ToLower() == Constants.AdminPane.ToLower()) + if (Name.ToLower() == PaneNames.Admin.ToLower()) { Module module = PageState.Modules.FirstOrDefault(item => item.ModuleId == PageState.ModuleId); if (module != null && !module.IsDeleted) diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index b79ea29d..ae34d6f8 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -505,7 +505,7 @@ // ensure module's pane exists in current page and if not, assign it to the Admin pane if (page.Panes == null || page.Panes.FindIndex(item => item.Equals(module.Pane, StringComparison.OrdinalIgnoreCase)) == -1) { - module.Pane = Constants.AdminPane; + module.Pane = PaneNames.Admin; } // calculate module position within pane diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index e03f1022..1a42ccd8 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -118,7 +118,7 @@ namespace Oqtane.Controllers bool verified; bool allowregistration; - if (user.Username == Constants.HostUser || User.IsInRole(RoleNames.Admin)) + if (user.Username == UserNames.Host || User.IsInRole(RoleNames.Admin)) { verified = true; allowregistration = true; @@ -164,7 +164,7 @@ namespace Oqtane.Controllers } // assign to host role if this is the host user ( initial installation ) - if (user.Username == Constants.HostUser) + if (user.Username == UserNames.Host) { int hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == RoleNames.Host).FirstOrDefault().RoleId; UserRole userrole = new UserRole(); @@ -206,7 +206,7 @@ namespace Oqtane.Controllers } } - if (newUser != null && user.Username != Constants.HostUser) + if (newUser != null && user.Username != UserNames.Host) { // add auto assigned roles to user for site List roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList(); diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index 79c72c58..28228280 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -83,7 +83,7 @@ namespace Oqtane.Infrastructure if (!string.IsNullOrEmpty(install.ConnectionString) && !string.IsNullOrEmpty(install.Aliases) && !string.IsNullOrEmpty(install.HostPassword) && !string.IsNullOrEmpty(install.HostEmail)) { // silent install - install.HostName = Constants.HostUser; + install.HostName = UserNames.Host; install.SiteTemplate = GetInstallationConfig(SettingKeys.SiteTemplateKey, Constants.DefaultSiteTemplate); install.DefaultTheme = GetInstallationConfig(SettingKeys.DefaultThemeKey, Constants.DefaultTheme); install.DefaultLayout = GetInstallationConfig(SettingKeys.DefaultLayoutKey, Constants.DefaultLayout); @@ -439,17 +439,17 @@ namespace Oqtane.Infrastructure }; site = sites.AddSite(site); - IdentityUser identityUser = identityUserManager.FindByNameAsync(Constants.HostUser).GetAwaiter().GetResult(); + IdentityUser identityUser = identityUserManager.FindByNameAsync(UserNames.Host).GetAwaiter().GetResult(); if (identityUser == null) { - identityUser = new IdentityUser { UserName = Constants.HostUser, Email = install.HostEmail, EmailConfirmed = true }; + identityUser = new IdentityUser { UserName = UserNames.Host, Email = install.HostEmail, EmailConfirmed = true }; var create = identityUserManager.CreateAsync(identityUser, install.HostPassword).GetAwaiter().GetResult(); if (create.Succeeded) { var user = new User { SiteId = site.SiteId, - Username = Constants.HostUser, + Username = UserNames.Host, Password = install.HostPassword, Email = install.HostEmail, DisplayName = install.HostName, diff --git a/Oqtane.Shared/Shared/Constants.cs b/Oqtane.Shared/Shared/Constants.cs index ec6d7df7..a4eeffb4 100644 --- a/Oqtane.Shared/Shared/Constants.cs +++ b/Oqtane.Shared/Shared/Constants.cs @@ -18,7 +18,9 @@ namespace Oqtane.Shared { public const string ActionToken = "{Action}"; public const string DefaultAction = "Index"; - public const string AdminPane = "Admin"; + + [Obsolete("Use PaneNames.Admin")] + public const string AdminPane = PaneNames.Admin; public const string ModuleDelimiter = "*"; public const string UrlParametersDelimiter = "!"; @@ -35,7 +37,8 @@ namespace Oqtane.Shared { public const string ContentUrl = "/api/file/download/"; - public const string HostUser = "host"; + [Obsolete("Use UserNames.Host instead.")] + public const string HostUser = UserNames.Host; public const string MasterTenant = "Master"; public const string DefaultSite = "Default Site"; diff --git a/Oqtane.Shared/Shared/PaneNames.cs b/Oqtane.Shared/Shared/PaneNames.cs new file mode 100644 index 00000000..063924f9 --- /dev/null +++ b/Oqtane.Shared/Shared/PaneNames.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Oqtane.Shared { + public class PaneNames { + public const string Admin = "Admin"; + } +} diff --git a/Oqtane.Shared/Shared/UserNames.cs b/Oqtane.Shared/Shared/UserNames.cs new file mode 100644 index 00000000..fdb83800 --- /dev/null +++ b/Oqtane.Shared/Shared/UserNames.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Oqtane.Shared { + public class UserNames { + public const string Host = "host"; + } +}