From 636f7310355865c5d6715d04562c6d00b15595a3 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sun, 3 Oct 2021 12:45:44 -0400 Subject: [PATCH 1/3] Resolved an issue where the wrong RedirectAfter tabs where showing for localized sites. The settings for the current portal alias local where returned to the UI instead of the requested language picked in the Page Settings editor. This caused an issue where you would get let's say the english tabs for a french site settings if the last page you happend to visit was english instead of french. The user would then save any setting and all the RedirectAfters would save the wrong thing for that locale. Closes #4232 Closes #4260 --- .../Services/SiteSettingsController.cs | 759 +++++++++--------- 1 file changed, 382 insertions(+), 377 deletions(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs index 3beef6e9968..00a1117ceee 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs @@ -2,84 +2,84 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information -namespace Dnn.PersonaBar.SiteSettings.Services -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Data; - using System.Dynamic; - using System.Globalization; - using System.IO; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Text.RegularExpressions; - using System.Threading; - using System.Web; - using System.Web.Http; - - using Dnn.PersonaBar.Library; - using Dnn.PersonaBar.Library.Attributes; - using Dnn.PersonaBar.SiteSettings.Services.Dto; - using DotNetNuke.Abstractions; - using DotNetNuke.Common; - using DotNetNuke.Common.Lists; - using DotNetNuke.Common.Utilities; - using DotNetNuke.Entities.Controllers; - using DotNetNuke.Entities.Host; - using DotNetNuke.Entities.Icons; - using DotNetNuke.Entities.Modules; - using DotNetNuke.Entities.Portals; - using DotNetNuke.Entities.Profile; - using DotNetNuke.Entities.Tabs; - using DotNetNuke.Entities.Urls; - using DotNetNuke.Entities.Users; - using DotNetNuke.Instrumentation; - using DotNetNuke.Security.Roles; - using DotNetNuke.Services.Exceptions; - using DotNetNuke.Services.FileSystem; - using DotNetNuke.Services.Installer.Packages; - using DotNetNuke.Services.Localization; - using DotNetNuke.Services.Personalization; - using DotNetNuke.Services.Search.Internals; - using DotNetNuke.UI.Internals; - using DotNetNuke.UI.Skins; - using DotNetNuke.Web.Api; - using DotNetNuke.Web.UI.WebControls; - - using Constants = Dnn.PersonaBar.Library.Constants; - using FileInfo = System.IO.FileInfo; +namespace Dnn.PersonaBar.SiteSettings.Services +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Data; + using System.Dynamic; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Text.RegularExpressions; + using System.Threading; + using System.Web; + using System.Web.Http; + + using Dnn.PersonaBar.Library; + using Dnn.PersonaBar.Library.Attributes; + using Dnn.PersonaBar.SiteSettings.Services.Dto; + using DotNetNuke.Abstractions; + using DotNetNuke.Common; + using DotNetNuke.Common.Lists; + using DotNetNuke.Common.Utilities; + using DotNetNuke.Entities.Controllers; + using DotNetNuke.Entities.Host; + using DotNetNuke.Entities.Icons; + using DotNetNuke.Entities.Modules; + using DotNetNuke.Entities.Portals; + using DotNetNuke.Entities.Profile; + using DotNetNuke.Entities.Tabs; + using DotNetNuke.Entities.Urls; + using DotNetNuke.Entities.Users; + using DotNetNuke.Instrumentation; + using DotNetNuke.Security.Roles; + using DotNetNuke.Services.Exceptions; + using DotNetNuke.Services.FileSystem; + using DotNetNuke.Services.Installer.Packages; + using DotNetNuke.Services.Localization; + using DotNetNuke.Services.Personalization; + using DotNetNuke.Services.Search.Internals; + using DotNetNuke.UI.Internals; + using DotNetNuke.UI.Skins; + using DotNetNuke.Web.Api; + using DotNetNuke.Web.UI.WebControls; + + using Constants = Dnn.PersonaBar.Library.Constants; + using FileInfo = System.IO.FileInfo; [MenuPermission(MenuName = Components.Constants.Constants.MenuName)] public class SiteSettingsController : PersonaBarApiController { - - // Field Boost Settings - they are scaled down by 10. - private const int DefaultSearchTitleBoost = 50; - private const string AuthFailureMessage = "Authorization has been denied for this request."; - private const int DefaultSearchTagBoost = 40; - private const int DefaultSearchContentBoost = 35; - private const int DefaultSearchDescriptionBoost = 20; - private const int DefaultSearchAuthorBoost = 15; - - // Field Bosst Setting Names - private const string SearchTitleBoostSetting = "Search_Title_Boost"; - private const string SearchTagBoostSetting = "Search_Tag_Boost"; - private const string SearchContentBoostSetting = "Search_Content_Boost"; - private const string SearchDescriptionBoostSetting = "Search_Description_Boost"; - private const string SearchAuthorBoostSetting = "Search_Author_Boost"; - - private const double DefaultMessagingThrottlingInterval = 0.5; // set default MessagingThrottlingInterval value to 30 seconds. - private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(SiteSettingsController)); - private readonly Components.SiteSettingsController _controller = new Components.SiteSettingsController(); - - protected INavigationManager NavigationManager { get; } - - public SiteSettingsController(INavigationManager navigationManager) - { - this.NavigationManager = navigationManager; - } + + // Field Boost Settings - they are scaled down by 10. + private const int DefaultSearchTitleBoost = 50; + private const string AuthFailureMessage = "Authorization has been denied for this request."; + private const int DefaultSearchTagBoost = 40; + private const int DefaultSearchContentBoost = 35; + private const int DefaultSearchDescriptionBoost = 20; + private const int DefaultSearchAuthorBoost = 15; + + // Field Bosst Setting Names + private const string SearchTitleBoostSetting = "Search_Title_Boost"; + private const string SearchTagBoostSetting = "Search_Tag_Boost"; + private const string SearchContentBoostSetting = "Search_Content_Boost"; + private const string SearchDescriptionBoostSetting = "Search_Description_Boost"; + private const string SearchAuthorBoostSetting = "Search_Author_Boost"; + + private const double DefaultMessagingThrottlingInterval = 0.5; // set default MessagingThrottlingInterval value to 30 seconds. + private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(SiteSettingsController)); + private readonly Components.SiteSettingsController _controller = new Components.SiteSettingsController(); + + protected INavigationManager NavigationManager { get; } + + public SiteSettingsController(INavigationManager navigationManager) + { + this.NavigationManager = navigationManager; + } #region Site Info API @@ -310,7 +310,11 @@ public HttpResponseMessage GetDefaultPagesSettings(int? portalId, string culture } var portal = PortalController.Instance.GetPortal(pid, cultureCode); - var portalSettings = new PortalSettings(portal); + var localizedPortalSettings = PortalController.Instance.GetPortalSettings(portal.PortalID, cultureCode); + + int redirectAfterLoginTabId = int.TryParse(localizedPortalSettings["Redirect_AfterLogin"], out redirectAfterLoginTabId) ? redirectAfterLoginTabId : -1; + int redirectAfterLogoutTabId = int.TryParse(localizedPortalSettings["Redirect_AfterLogout"], out redirectAfterLogoutTabId) ? redirectAfterLogoutTabId : -1; + int redirectAfterRegistrationTabId = int.TryParse(localizedPortalSettings["Redirect_AfterRegistration"], out redirectAfterRegistrationTabId) ? redirectAfterRegistrationTabId : -1; return this.Request.CreateResponse(HttpStatusCode.OK, new { @@ -338,13 +342,13 @@ public HttpResponseMessage GetDefaultPagesSettings(int? portalId, string culture TermsTabName = this.TabSanitizer(portal.TermsTabId, pid)?.TabName, PrivacyTabId = this.TabSanitizer(portal.PrivacyTabId, pid)?.TabID, PrivacyTabName = this.TabSanitizer(portal.PrivacyTabId, pid)?.TabName, - RedirectAfterLoginTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogin, pid)?.TabID, - RedirectAfterLoginTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogin, pid)?.TabName, - RedirectAfterLogoutTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogout, pid)?.TabID, - RedirectAfterLogoutTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogout, pid)?.TabName, - RedirectAfterRegistrationTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterRegistration, pid)?.TabID, - RedirectAfterRegistrationTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterRegistration, pid)?.TabName, - portalSettings.PageHeadText, + RedirectAfterLoginTabId = this.TabSanitizer(redirectAfterLoginTabId, pid)?.TabID, + RedirectAfterLoginTabName = this.TabSanitizer(redirectAfterLoginTabId, pid)?.TabName, + RedirectAfterLogoutTabId = this.TabSanitizer(redirectAfterLogoutTabId, pid)?.TabID, + RedirectAfterLogoutTabName = this.TabSanitizer(redirectAfterLogoutTabId, pid)?.TabName, + RedirectAfterRegistrationTabId = this.TabSanitizer(redirectAfterRegistrationTabId, pid)?.TabID, + RedirectAfterRegistrationTabName = this.TabSanitizer(redirectAfterRegistrationTabId, pid)?.TabName, + PageHeadText = localizedPortalSettings["PageHeadText"], }, }); } @@ -394,10 +398,11 @@ public HttpResponseMessage UpdateDefaultPagesSettings(UpdateDefaultPagesSettings portalInfo.TermsTabId = this.ValidateTabId(request.TermsTabId, pid); portalInfo.PrivacyTabId = this.ValidateTabId(request.PrivacyTabId, pid); PortalController.Instance.UpdatePortalInfo(portalInfo); - - PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogin", this.ValidateTabId(request.RedirectAfterLoginTabId, pid).ToString(), false, cultureCode); - PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogout", this.ValidateTabId(request.RedirectAfterLogoutTabId, pid).ToString(), false, cultureCode); - PortalController.UpdatePortalSetting(pid, "Redirect_AfterRegistration", this.ValidateTabId(request.RedirectAfterRegistrationTabId, pid).ToString(), false, cultureCode); + + var portalSettings = PortalController.Instance.GetCurrentSettings(); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogin", this.ValidateTabId(request.RedirectAfterLoginTabId, pid).ToString(), false, cultureCode); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogout", this.ValidateTabId(request.RedirectAfterLogoutTabId, pid).ToString(), false, cultureCode); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterRegistration", this.ValidateTabId(request.RedirectAfterRegistrationTabId, pid).ToString(), false, cultureCode); PortalController.UpdatePortalSetting(pid, "PageHeadText", string.IsNullOrEmpty(request.PageHeadText) ? "false" : request.PageHeadText); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -3212,40 +3217,40 @@ public HttpResponseMessage UpdateOtherSettings(UpdateOtherSettingsRequest reques return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } } - - private static void GetResourceFiles(SortedList fileList, string path) - { - var folders = Directory.GetDirectories(path); - - foreach (var folder in folders) - { - var objFolder = new DirectoryInfo(folder); - - bool resxFilesDirectory = (objFolder.Name.ToLowerInvariant() == Localization.LocalResourceDirectory.ToLowerInvariant()) || - (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", "").ToLowerInvariant()) || - (folder.ToLowerInvariant().EndsWith("\\portals\\_default")); - - if (resxFilesDirectory) - { - var sysLocale = Localization.SystemLocale.ToLowerInvariant(); - foreach (var file in Directory.GetFiles(objFolder.FullName, "*.resx")) - { - var fileInfo = new FileInfo(file); - var match = LanguagesController.FileInfoRegex.Match(fileInfo.Name); - - if (match.Success && match.Groups[1].Value.ToLowerInvariant() != sysLocale) - { - continue; - } - fileList.Add(fileInfo.FullName, fileInfo); - } - } - else - { - GetResourceFiles(fileList, folder); - } - } - } + + private static void GetResourceFiles(SortedList fileList, string path) + { + var folders = Directory.GetDirectories(path); + + foreach (var folder in folders) + { + var objFolder = new DirectoryInfo(folder); + + bool resxFilesDirectory = (objFolder.Name.ToLowerInvariant() == Localization.LocalResourceDirectory.ToLowerInvariant()) || + (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", "").ToLowerInvariant()) || + (folder.ToLowerInvariant().EndsWith("\\portals\\_default")); + + if (resxFilesDirectory) + { + var sysLocale = Localization.SystemLocale.ToLowerInvariant(); + foreach (var file in Directory.GetFiles(objFolder.FullName, "*.resx")) + { + var fileInfo = new FileInfo(file); + var match = LanguagesController.FileInfoRegex.Match(fileInfo.Name); + + if (match.Success && match.Groups[1].Value.ToLowerInvariant() != sysLocale) + { + continue; + } + fileList.Add(fileInfo.FullName, fileInfo); + } + } + else + { + GetResourceFiles(fileList, folder); + } + } + } #endregion @@ -3261,263 +3266,263 @@ private bool IsLanguagePublished(int portalId, string code) } return isPublished; } - - private string GetTranslatedPages(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated && !t.IsDeleted select t).Count(); - status = translatedCount.ToString(CultureInfo.InvariantCulture); - } - return status; - } - - private string GetLocalizedStatus(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int defaultPageCount = this.GetLocalizedPages(portalSettings.PortalId, portalSettings.DefaultLanguage, false).Count; - int currentPageCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; - status = $"{currentPageCount / (float)defaultPageCount:#0%}"; - } - return status; - } - - private string GetLocalizablePages(int portalId, string code) - { - int count = this.GetLocalizedPages(portalId, code, false).Count(t => !t.Value.IsDeleted); - return count.ToString(CultureInfo.CurrentUICulture); - } - - private TabCollection GetLocalizedPages(int portalId, string code, bool includeNeutral) - { - return TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, includeNeutral); - } - - private int GetPublishedLocalizedPages(int portalId, string code) - { - var localizedTabs = TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, false); - return localizedTabs.Count(t => TabController.Instance.IsTabPublished(t.Value)); - } - - private string GetTranslatedStatus(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int localizedCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; - int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated select t).Count(); - status = $"{translatedCount / (float)localizedCount:#0%}"; - } - return status; - } - - private bool IsDefaultLanguage(PortalSettings portalSettings, string code) - { - return code == portalSettings.DefaultLanguage; - } - - private bool IsLocalized(PortalSettings portalSettings, string code) - { - return (code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0); - } - - private bool CanDeleteProperty(ProfilePropertyDefinition definition) - { - switch (definition.PropertyName.ToLowerInvariant()) - { - case "lastname": - case "firstname": - case "preferredtimezone": - case "preferredlocale": - return false; - default: - return true; - } - } - - private string GetAbsoluteServerPath() - { - var httpContext = this.Request.Properties["MS_HttpContext"] as HttpContextWrapper; - if (httpContext != null) - { - var strServerPath = httpContext.Request.MapPath(httpContext.Request.ApplicationPath); - if (!strServerPath.EndsWith("\\")) - { - strServerPath += "\\"; - } - return strServerPath; - } - else - { - return string.Empty; - } - } - - private string DisplayDataType(int dataType) - { - var retValue = Null.NullString; - var listController = new ListController(); - var definitionEntry = listController.GetListEntryInfo("DataType", dataType); - if (definitionEntry != null) - { - retValue = definitionEntry.Value; - } - return retValue; - } - - private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResponseMessage httpPropertyValidationError) - { - bool isValid = true; - httpPropertyValidationError = null; - var objListController = new ListController(); - string strDataType = objListController.GetListEntryInfo("DataType", definition.DataType).Value; - Regex propertyNameRegex = new Regex("^[a-zA-Z0-9]+$"); - if (!propertyNameRegex.Match(definition.PropertyName).Success) - { - isValid = false; - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("NoSpecialCharacterName.Text", Components.Constants.Constants.LocalResourcesFile))); - } - - switch (strDataType) - { - case "Text": - if (definition.Required && definition.Length == 0) - { - isValid = Null.NullBoolean; - } - break; - } - - if (isValid == false) - { - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("RequiredTextBox", Components.Constants.Constants.LocalResourcesFile))); - } - return isValid; - } - - private bool IsHttpAliasValid(string strAlias) - { - bool isValid = true; - if (string.IsNullOrEmpty(strAlias)) - { - isValid = false; - } - else - { - if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1) - { - strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3); - } - if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1) - { - strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2); - } - - // Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables - if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false)) - { - isValid = false; - } - } - return isValid; - } - - private static string ResourceFile(string filename, string language) - { - return Localization.GetResourceFileName(filename, language, "", Globals.GetPortalSettings().PortalId); - } - - private bool IsLanguageEnabled(int portalId, string code) - { - Locale enabledLanguage; - return LocaleController.Instance.GetLocales(portalId).TryGetValue(code, out enabledLanguage); - } - - private bool CanEnableDisable(PortalSettings portalSettings, string code) - { - bool canEnable; - if (this.IsLanguageEnabled(portalSettings.PortalId, code)) - { - canEnable = !this.IsDefaultLanguage(portalSettings, code) && !this.IsLanguagePublished(portalSettings.PortalId, code); - } - else - { - canEnable = !this.IsDefaultLanguage(portalSettings, code); - } - return canEnable; - } - - private CultureDropDownTypes GetCultureDropDownType(int portalId) - { - CultureDropDownTypes displayType; - string viewType = this.GetLanguageDisplayMode(portalId); - switch (viewType) - { - case "NATIVE": - displayType = CultureDropDownTypes.NativeName; - break; - case "ENGLISH": - displayType = CultureDropDownTypes.EnglishName; - break; - default: - displayType = CultureDropDownTypes.DisplayName; - break; - } - return displayType; - } - - private string GetLanguageDisplayMode(int portalId) - { - string viewTypePersonalizationKey = "LanguageDisplayMode:ViewType" + portalId; - var personalizationController = new PersonalizationController(); - var personalization = personalizationController.LoadProfile(this.UserInfo.UserID, portalId); - - string viewType = Convert.ToString(personalization.Profile[viewTypePersonalizationKey]); - return string.IsNullOrEmpty(viewType) ? "NATIVE" : viewType; - } - - private SearchStatistics GetSearchStatistics() - { - try - { - return InternalSearchController.Instance.GetSearchStatistics(); - } - catch (SearchIndexEmptyException) - { - return null; - } - } - - private void ClearEntriesCache(string listName, int portalId) - { - string cacheKey = string.Format(DataCache.ListEntriesCacheKey, portalId, listName); - DataCache.RemoveCache(cacheKey); - } - - private TabInfo TabSanitizer(int tabId, int portalId) - { - var tab = TabController.Instance.GetTab(tabId, portalId); - if (tab != null && !tab.IsDeleted) - { - return tab; - } - else - { - return null; - } - } - - private int ValidateTabId(int tabId, int portalId) - { - var tab = TabController.Instance.GetTab(tabId, portalId); - return tab != null && !tab.IsDeleted ? tab.TabID : Null.NullInteger; - } + + private string GetTranslatedPages(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated && !t.IsDeleted select t).Count(); + status = translatedCount.ToString(CultureInfo.InvariantCulture); + } + return status; + } + + private string GetLocalizedStatus(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int defaultPageCount = this.GetLocalizedPages(portalSettings.PortalId, portalSettings.DefaultLanguage, false).Count; + int currentPageCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; + status = $"{currentPageCount / (float)defaultPageCount:#0%}"; + } + return status; + } + + private string GetLocalizablePages(int portalId, string code) + { + int count = this.GetLocalizedPages(portalId, code, false).Count(t => !t.Value.IsDeleted); + return count.ToString(CultureInfo.CurrentUICulture); + } + + private TabCollection GetLocalizedPages(int portalId, string code, bool includeNeutral) + { + return TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, includeNeutral); + } + + private int GetPublishedLocalizedPages(int portalId, string code) + { + var localizedTabs = TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, false); + return localizedTabs.Count(t => TabController.Instance.IsTabPublished(t.Value)); + } + + private string GetTranslatedStatus(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int localizedCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; + int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated select t).Count(); + status = $"{translatedCount / (float)localizedCount:#0%}"; + } + return status; + } + + private bool IsDefaultLanguage(PortalSettings portalSettings, string code) + { + return code == portalSettings.DefaultLanguage; + } + + private bool IsLocalized(PortalSettings portalSettings, string code) + { + return (code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0); + } + + private bool CanDeleteProperty(ProfilePropertyDefinition definition) + { + switch (definition.PropertyName.ToLowerInvariant()) + { + case "lastname": + case "firstname": + case "preferredtimezone": + case "preferredlocale": + return false; + default: + return true; + } + } + + private string GetAbsoluteServerPath() + { + var httpContext = this.Request.Properties["MS_HttpContext"] as HttpContextWrapper; + if (httpContext != null) + { + var strServerPath = httpContext.Request.MapPath(httpContext.Request.ApplicationPath); + if (!strServerPath.EndsWith("\\")) + { + strServerPath += "\\"; + } + return strServerPath; + } + else + { + return string.Empty; + } + } + + private string DisplayDataType(int dataType) + { + var retValue = Null.NullString; + var listController = new ListController(); + var definitionEntry = listController.GetListEntryInfo("DataType", dataType); + if (definitionEntry != null) + { + retValue = definitionEntry.Value; + } + return retValue; + } + + private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResponseMessage httpPropertyValidationError) + { + bool isValid = true; + httpPropertyValidationError = null; + var objListController = new ListController(); + string strDataType = objListController.GetListEntryInfo("DataType", definition.DataType).Value; + Regex propertyNameRegex = new Regex("^[a-zA-Z0-9]+$"); + if (!propertyNameRegex.Match(definition.PropertyName).Success) + { + isValid = false; + httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + string.Format(Localization.GetString("NoSpecialCharacterName.Text", Components.Constants.Constants.LocalResourcesFile))); + } + + switch (strDataType) + { + case "Text": + if (definition.Required && definition.Length == 0) + { + isValid = Null.NullBoolean; + } + break; + } + + if (isValid == false) + { + httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + string.Format(Localization.GetString("RequiredTextBox", Components.Constants.Constants.LocalResourcesFile))); + } + return isValid; + } + + private bool IsHttpAliasValid(string strAlias) + { + bool isValid = true; + if (string.IsNullOrEmpty(strAlias)) + { + isValid = false; + } + else + { + if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1) + { + strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3); + } + if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1) + { + strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2); + } + + // Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables + if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false)) + { + isValid = false; + } + } + return isValid; + } + + private static string ResourceFile(string filename, string language) + { + return Localization.GetResourceFileName(filename, language, "", Globals.GetPortalSettings().PortalId); + } + + private bool IsLanguageEnabled(int portalId, string code) + { + Locale enabledLanguage; + return LocaleController.Instance.GetLocales(portalId).TryGetValue(code, out enabledLanguage); + } + + private bool CanEnableDisable(PortalSettings portalSettings, string code) + { + bool canEnable; + if (this.IsLanguageEnabled(portalSettings.PortalId, code)) + { + canEnable = !this.IsDefaultLanguage(portalSettings, code) && !this.IsLanguagePublished(portalSettings.PortalId, code); + } + else + { + canEnable = !this.IsDefaultLanguage(portalSettings, code); + } + return canEnable; + } + + private CultureDropDownTypes GetCultureDropDownType(int portalId) + { + CultureDropDownTypes displayType; + string viewType = this.GetLanguageDisplayMode(portalId); + switch (viewType) + { + case "NATIVE": + displayType = CultureDropDownTypes.NativeName; + break; + case "ENGLISH": + displayType = CultureDropDownTypes.EnglishName; + break; + default: + displayType = CultureDropDownTypes.DisplayName; + break; + } + return displayType; + } + + private string GetLanguageDisplayMode(int portalId) + { + string viewTypePersonalizationKey = "LanguageDisplayMode:ViewType" + portalId; + var personalizationController = new PersonalizationController(); + var personalization = personalizationController.LoadProfile(this.UserInfo.UserID, portalId); + + string viewType = Convert.ToString(personalization.Profile[viewTypePersonalizationKey]); + return string.IsNullOrEmpty(viewType) ? "NATIVE" : viewType; + } + + private SearchStatistics GetSearchStatistics() + { + try + { + return InternalSearchController.Instance.GetSearchStatistics(); + } + catch (SearchIndexEmptyException) + { + return null; + } + } + + private void ClearEntriesCache(string listName, int portalId) + { + string cacheKey = string.Format(DataCache.ListEntriesCacheKey, portalId, listName); + DataCache.RemoveCache(cacheKey); + } + + private TabInfo TabSanitizer(int tabId, int portalId) + { + var tab = TabController.Instance.GetTab(tabId, portalId); + if (tab != null && !tab.IsDeleted) + { + return tab; + } + else + { + return null; + } + } + + private int ValidateTabId(int tabId, int portalId) + { + var tab = TabController.Instance.GetTab(tabId, portalId); + return tab != null && !tab.IsDeleted ? tab.TabID : Null.NullInteger; + } #endregion } -} +} From c7f9dec41ccbb9afd5df09affcc65e1717e5c59a Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sun, 3 Oct 2021 13:48:59 -0400 Subject: [PATCH 2/3] Resolved about 200 stylecop warnings --- .../Services/SiteSettingsController.cs | 357 ++++++++++-------- 1 file changed, 208 insertions(+), 149 deletions(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs index 00a1117ceee..89325581e24 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs @@ -51,10 +51,12 @@ namespace Dnn.PersonaBar.SiteSettings.Services using Constants = Dnn.PersonaBar.Library.Constants; using FileInfo = System.IO.FileInfo; + /// + /// Provides Web API methods for the Site Settings module to use. + /// [MenuPermission(MenuName = Components.Constants.Constants.MenuName)] public class SiteSettingsController : PersonaBarApiController { - // Field Boost Settings - they are scaled down by 10. private const int DefaultSearchTitleBoost = 50; private const string AuthFailureMessage = "Authorization has been denied for this request."; @@ -72,24 +74,31 @@ public class SiteSettingsController : PersonaBarApiController private const double DefaultMessagingThrottlingInterval = 0.5; // set default MessagingThrottlingInterval value to 30 seconds. private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(SiteSettingsController)); - private readonly Components.SiteSettingsController _controller = new Components.SiteSettingsController(); - - protected INavigationManager NavigationManager { get; } + private readonly Components.SiteSettingsController controller = new Components.SiteSettingsController(); + private readonly INavigationManager navigationManager; + /// + /// Initializes a new instance of the class. + /// + /// A manager to provide navigation services. public SiteSettingsController(INavigationManager navigationManager) { - this.NavigationManager = navigationManager; + this.navigationManager = navigationManager; } - #region Site Info API + /// + /// Provides navigation services. + /// + [Obsolete("Deprecated in v9.10.2, please use DI to register your own navigation manager. Schedule for removal in v11")] + protected INavigationManager NavigationManager => this.navigationManager; /// GET: api/SiteSettings/GetPortalSettings /// /// Gets site settings. /// - /// - /// - /// site settings. + /// The ID of the portal to get the settings for. + /// The culture in which to get the settings in. + /// Localized site settings. [HttpGet] [AdvancedPermission(MenuName = Components.Constants.Constants.MenuName, Permission = Components.Constants.Constants.SiteInfoView)] public HttpResponseMessage GetPortalSettings(int? portalId, string cultureCode) @@ -109,7 +118,8 @@ public HttpResponseMessage GetPortalSettings(int? portalId, string cultureCode) var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -135,16 +145,18 @@ public HttpResponseMessage GetPortalSettings(int? portalId, string cultureCode) folderPath = logoFile.Folder, fileId = logoFile.FileId, folderId = logoFile.FolderId, - } : null, + } + : null, FavIcon = favIcon != null ? new FileDto() { fileName = favIcon.FileName, folderPath = favIcon.Folder, fileId = favIcon.FileId, folderId = favIcon.FolderId, - } : null, + } + : null, new DnnFileUploadOptions().ValidationCode, - IconSet = PortalController.GetPortalSetting("DefaultIconLocation", pid, "Sigma", cultureCode).Replace("icons/", ""), + IconSet = PortalController.GetPortalSetting("DefaultIconLocation", pid, "Sigma", cultureCode).Replace("icons/", string.Empty), }; return this.Request.CreateResponse(HttpStatusCode.OK, new { @@ -168,7 +180,7 @@ public HttpResponseMessage GetPortalSettings(int? portalId, string cultureCode) /// /// Gets culture list. /// - /// + /// The ID of the portal for which to get the list of cultures. /// Culture List. [HttpGet] [AdvancedPermission(MenuName = Components.Constants.Constants.MenuName, Permission = Components.Constants.Constants.SiteInfoView)] @@ -211,13 +223,12 @@ public HttpResponseMessage GetCultureList(int? portalId) } } - /// POST: api/SiteSettings/UpdatePortalSettings /// /// Updates site settings. /// - /// - /// + /// . + /// A success or error message. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = Components.Constants.Constants.MenuName, Permission = Components.Constants.Constants.SiteInfoView + "&" + Components.Constants.Constants.SiteInfoEdit)] @@ -236,18 +247,19 @@ public HttpResponseMessage UpdatePortalSettings(UpdateSiteSettingsRequest reques var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } var portalInfo = PortalController.Instance.GetPortal(pid, cultureCode); portalInfo.PortalName = request.PortalName; - if (request.LogoFile != null && request.LogoFile.fileId != Null.NullInteger && !String.IsNullOrEmpty(request.LogoFile.fileName)) + if (request.LogoFile != null && request.LogoFile.fileId != Null.NullInteger && !string.IsNullOrEmpty(request.LogoFile.fileName)) { portalInfo.LogoFile = FileManager.Instance.GetFile(request.LogoFile.fileId).RelativePath; } - else // Set LogoFile to blank when no file is specified. + else { portalInfo.LogoFile = string.Empty; } @@ -275,16 +287,12 @@ public HttpResponseMessage UpdatePortalSettings(UpdateSiteSettingsRequest reques } } - #endregion - - #region Site Behavior API - /// GET: api/SiteSettings/GetDefaultPagesSettings /// /// Gets default pages settings. /// - /// - /// + /// The ID of the portal for which to getting the settings for. + /// The culture code for which to get the page settings in. /// default pages settings. [HttpGet] [DnnAuthorize(StaticRoles = Constants.AdminsRoleName)] @@ -305,7 +313,8 @@ public HttpResponseMessage GetDefaultPagesSettings(int? portalId, string culture var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -382,7 +391,8 @@ public HttpResponseMessage UpdateDefaultPagesSettings(UpdateDefaultPagesSettings var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -447,7 +457,7 @@ public HttpResponseMessage GetMessagingSettings(int? portalId) AllowAttachments = PortalController.GetPortalSettingAsBoolean("MessagingAllowAttachments", pid, false), ProfanityFilters = PortalController.GetPortalSettingAsBoolean("MessagingProfanityFilters", pid, false), IncludeAttachments = PortalController.GetPortalSettingAsBoolean("MessagingIncludeAttachments", pid, false), - SendEmail = PortalController.GetPortalSetting("MessagingSendEmail", pid, "YES") == "YES" + SendEmail = PortalController.GetPortalSetting("MessagingSendEmail", pid, "YES") == "YES", }, }); } @@ -532,7 +542,7 @@ public HttpResponseMessage GetProfileSettings(int? portalId) v => new { label = v.ToString(), - value = (int)v + value = (int)v, }).ToList(), }); } @@ -566,6 +576,7 @@ public HttpResponseMessage UpdateProfileSettings(UpdateProfileSettingsRequest re { PortalController.UpdatePortalSetting(pid, FriendlyUrlSettings.RedirectOldProfileUrlSetting, request.RedirectOldProfileUrl ? "Y" : "N", false); } + PortalController.UpdatePortalSetting(pid, FriendlyUrlSettings.VanityUrlPrefixSetting, request.VanityUrlPrefix, false); PortalController.UpdatePortalSetting(pid, "Profile_DefaultVisibility", request.ProfileDefaultVisibility.ToString(), false); PortalController.UpdatePortalSetting(pid, "Profile_DisplayVisibility", request.ProfileDisplayVisibility.ToString(), true); @@ -646,7 +657,7 @@ public HttpResponseMessage GetProfileProperty(int? propertyId, int? portalId) var profileProperty = ProfileController.GetPropertyDefinition(propertyId ?? -1, pid); var listController = new ListController(); - var cultureList = Localization.LoadCultureInListItems(this.GetCultureDropDownType(pid), Thread.CurrentThread.CurrentUICulture.Name, "", false); + var cultureList = Localization.LoadCultureInListItems(this.GetCultureDropDownType(pid), Thread.CurrentThread.CurrentUICulture.Name, string.Empty, false); var response = new { @@ -666,7 +677,8 @@ public HttpResponseMessage GetProfileProperty(int? propertyId, int? portalId) profileProperty.Visible, profileProperty.ViewOrder, DefaultVisibility = (int)profileProperty.DefaultVisibility, - } : null, + } + : null, UserVisibilityOptions = Enum.GetValues(typeof(UserVisibilityMode)).Cast().Select( v => new { @@ -685,7 +697,7 @@ public HttpResponseMessage GetProfileProperty(int? propertyId, int? portalId) Icon = Globals.ResolveUrl( string.IsNullOrEmpty(c.Value) ? "~/images/Flags/none.gif" - : $"~/images/Flags/{c.Value}.gif") + : $"~/images/Flags/{c.Value}.gif"), }), }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -701,11 +713,11 @@ public HttpResponseMessage GetProfileProperty(int? propertyId, int? portalId) /// /// Gets profile property localization. /// - /// - /// - /// - /// - /// profile property. + /// The ID of the portal for which to get the profile properties for. + /// The name of the property to get. + /// The category of the property to get. + /// The culture code in which to get the category in. + /// Profile property. [HttpGet] [DnnAuthorize(StaticRoles = Constants.AdminsRoleName)] public HttpResponseMessage GetProfilePropertyLocalization(int? portalId, string cultureCode, string propertyName, string propertyCategory) @@ -723,7 +735,8 @@ public HttpResponseMessage GetProfilePropertyLocalization(int? portalId, string var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -734,11 +747,11 @@ public HttpResponseMessage GetProfilePropertyLocalization(int? portalId, string PropertyLocalization = new { Language = cultureCode, - PropertyName = Localization.GetString("ProfileProperties_" + propertyName, resourceFile, cultureCode) ?? "", - PropertyHelp = Localization.GetString("ProfileProperties_" + propertyName + ".Help", resourceFile, cultureCode) ?? "", - PropertyRequired = Localization.GetString("ProfileProperties_" + propertyName + ".Required", resourceFile, cultureCode) ?? "", - PropertyValidation = Localization.GetString("ProfileProperties_" + propertyName + ".Validation", resourceFile, cultureCode) ?? "", - CategoryName = Localization.GetString("ProfileProperties_" + propertyCategory + ".Header", resourceFile, cultureCode) ?? "" + PropertyName = Localization.GetString("ProfileProperties_" + propertyName, resourceFile, cultureCode) ?? string.Empty, + PropertyHelp = Localization.GetString("ProfileProperties_" + propertyName + ".Help", resourceFile, cultureCode) ?? string.Empty, + PropertyRequired = Localization.GetString("ProfileProperties_" + propertyName + ".Required", resourceFile, cultureCode) ?? string.Empty, + PropertyValidation = Localization.GetString("ProfileProperties_" + propertyName + ".Validation", resourceFile, cultureCode) ?? string.Empty, + CategoryName = Localization.GetString("ProfileProperties_" + propertyCategory + ".Header", resourceFile, cultureCode) ?? string.Empty, }, }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -772,12 +785,21 @@ public HttpResponseMessage UpdateProfilePropertyLocalization(UpdateProfileProper var language = LocaleController.Instance.GetLocale(pid, request.Language); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), request.Language)); } - this._controller.SaveLocalizedKeys(pid, request.PropertyName, request.PropertyCategory, request.Language, request.PropertyNameString, - request.PropertyHelpString, request.PropertyRequiredString, request.PropertyValidationString, request.CategoryNameString); + this.controller.SaveLocalizedKeys( + pid, + request.PropertyName, + request.PropertyCategory, + request.Language, + request.PropertyNameString, + request.PropertyHelpString, + request.PropertyRequiredString, + request.PropertyValidationString, + request.CategoryNameString); DataCache.ClearCache(); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -830,7 +852,8 @@ public HttpResponseMessage AddProfileProperty(UpdateProfilePropertyRequest reque var propertyId = ProfileController.AddPropertyDefinition(property); if (propertyId < Null.NullInteger) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("DuplicateName", Components.Constants.Constants.LocalResourcesFile))); } else @@ -1026,7 +1049,8 @@ public HttpResponseMessage GetUrlMappingSettings(int? portalId) var portalAliasMappingModes = new List> { - new KeyValuePair(Localization.GetString("Canonical", Components.Constants.Constants.LocalResourcesFile), + new KeyValuePair( + Localization.GetString("Canonical", Components.Constants.Constants.LocalResourcesFile), "CANONICALURL"), new KeyValuePair(Localization.GetString("Redirect", Components.Constants.Constants.LocalResourcesFile), "REDIRECT"), new KeyValuePair(Localization.GetString("None", Components.Constants.Constants.LocalResourcesFile), "NONE"), @@ -1168,7 +1192,7 @@ public HttpResponseMessage GetSiteAlias(int portalAliasId) BrowserType = alias.BrowserType.ToString(), alias.Skin, alias.IsPrimary, - alias.CultureCode + alias.CultureCode, }, }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -1210,7 +1234,8 @@ public HttpResponseMessage AddSiteAlias(UpdateSiteAliasRequest request) var aliases = PortalAliasController.Instance.GetPortalAliases(); if (aliases.Contains(strAlias)) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("DuplicateAlias", Components.Constants.Constants.LocalResourcesFile))); } @@ -1230,8 +1255,9 @@ public HttpResponseMessage AddSiteAlias(UpdateSiteAliasRequest request) } else { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("InvalidAlias", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + string.Format(Localization.GetString("InvalidAlias", Components.Constants.Constants.LocalResourcesFile))); } return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -1289,14 +1315,16 @@ public HttpResponseMessage UpdateSiteAlias(UpdateSiteAliasRequest request) } else { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidAlias", Components.Constants.Constants.LocalResourcesFile))); } } else { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("InvalidAlias", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + string.Format(Localization.GetString("InvalidAlias", Components.Constants.Constants.LocalResourcesFile))); } return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -1395,17 +1423,17 @@ public HttpResponseMessage GetListInfo(string listName, int? portalId) } var listController = new ListController(); - var entries = listController.GetListEntryInfoItems(listName, "", pid); + var entries = listController.GetListEntryInfoItems(listName, string.Empty, pid); var response = new { Success = true, - listController.GetListInfo(listName, "", pid)?.EnableSortOrder, + listController.GetListInfo(listName, string.Empty, pid)?.EnableSortOrder, Entries = entries.Select(t => new { t.EntryID, t.Text, t.Value, - t.SortOrder + t.SortOrder, }), }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -1595,7 +1623,7 @@ public HttpResponseMessage GetPrivacySettings(int? portalId) DataConsentConsentRedirectName = this.TabSanitizer(portalSettings.DataConsentConsentRedirect, pid)?.TabName, DataConsentUserDeleteAction = (int)portalSettings.DataConsentUserDeleteAction, this.PortalSettings.DataConsentDelay, - this.PortalSettings.DataConsentDelayMeasurement + this.PortalSettings.DataConsentDelayMeasurement, }, }); } @@ -1631,6 +1659,7 @@ public HttpResponseMessage UpdatePrivacySettings(UpdatePrivacySettingsRequest re { HostController.Instance.Update("CheckUpgrade", request.CheckUpgrade ? "Y" : "N", false); } + PortalController.UpdatePortalSetting(pid, "DataConsentActive", request.DataConsentActive.ToString(), false); PortalController.UpdatePortalSetting(pid, "DataConsentConsentRedirect", this.ValidateTabId(request.DataConsentConsentRedirect, pid).ToString(), false); PortalController.UpdatePortalSetting(pid, "DataConsentUserDeleteAction", request.DataConsentUserDeleteAction.ToString(), false); @@ -1665,6 +1694,7 @@ public HttpResponseMessage ResetTermsAgreement(ResetTermsAgreementRequest reques { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, AuthFailureMessage); } + UserController.ResetTermsAgreement(pid); PortalController.UpdatePortalSetting(pid, "DataConsentTermsLastChange", DateTime.Now.ToString("O", CultureInfo.InvariantCulture), true); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -1676,10 +1706,6 @@ public HttpResponseMessage ResetTermsAgreement(ResetTermsAgreementRequest reques } } - #endregion - - #region Search Settings API - /// GET: api/SiteSettings/GetBasicSearchSettings /// /// Gets basic search settings. @@ -1706,7 +1732,7 @@ public HttpResponseMessage GetBasicSearchSettings() SearchStatistics searchStatistics = this.GetSearchStatistics(); if (searchStatistics != null) { - settings.SearchIndexDbSize = ((searchStatistics.IndexDbSize / 1024f) / 1024f).ToString("N") + " MB"; + settings.SearchIndexDbSize = (searchStatistics.IndexDbSize / 1024f / 1024f).ToString("N") + " MB"; settings.SearchIndexLastModifedOn = DateUtils.CalculateDateForDisplay(searchStatistics.LastModifiedOn); settings.SearchIndexTotalActiveDocuments = searchStatistics.TotalActiveDocuments.ToString(CultureInfo.InvariantCulture); settings.SearchIndexTotalDeletedDocuments = searchStatistics.TotalDeletedDocuments.ToString(CultureInfo.InvariantCulture); @@ -1716,7 +1742,7 @@ public HttpResponseMessage GetBasicSearchSettings() { Success = true, Settings = settings, - SearchCustomAnalyzers = this._controller.GetAvailableAnalyzers(), + SearchCustomAnalyzers = this.controller.GetAvailableAnalyzers(), }; return this.Request.CreateResponse(HttpStatusCode.OK, response); } @@ -1742,18 +1768,21 @@ public HttpResponseMessage UpdateBasicSearchSettings(UpdateBasicSearchSettingsRe { if (request.MinWordLength == Null.NullInteger || request.MinWordLength == 0) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("valIndexWordMinLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + string.Format(Localization.GetString("valIndexWordMinLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); } else if (request.MaxWordLength == Null.NullInteger || request.MaxWordLength == 0) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("valIndexWordMaxLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + string.Format(Localization.GetString("valIndexWordMaxLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); } else if (request.MinWordLength >= request.MaxWordLength) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("valIndexWordMaxLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + string.Format(Localization.GetString("valIndexWordMaxLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile))); } var oldMinLength = HostController.Instance.GetInteger("Search_MinKeyWordLength", 3); @@ -1780,6 +1809,7 @@ public HttpResponseMessage UpdateBasicSearchSettings(UpdateBasicSearchSettingsRe if (!oldAnalyzer.Equals(newAnalyzer)) { HostController.Instance.Update("Search_CustomAnalyzer", newAnalyzer); + // force the app restart to use new analyzer. Config.Touch(); } @@ -1870,7 +1900,6 @@ public HttpResponseMessage PortalSearchReindex(int? portalId) /// /// Gets portals. /// - /// /// List of portals. [HttpGet] [RequireHost] @@ -1920,10 +1949,12 @@ public HttpResponseMessage GetSynonymsGroups(int? portalId, string cultureCode) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, AuthFailureMessage); } + var language = LocaleController.Instance.GetLocaleOrCurrent(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -1936,7 +1967,7 @@ public HttpResponseMessage GetSynonymsGroups(int? portalId, string cultureCode) SynonymsGroups = groups.Select(g => new { g.SynonymsGroupId, - g.SynonymsTags + g.SynonymsTags, }), }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -1974,7 +2005,8 @@ public HttpResponseMessage AddSynonymsGroup(UpdateSynonymsGroupRequest request) var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -1982,13 +2014,15 @@ public HttpResponseMessage AddSynonymsGroup(UpdateSynonymsGroupRequest request) var synonymsGroupId = SearchHelper.Instance.AddSynonymsGroup(request.SynonymsTags, pid, cultureCode, out duplicateWord); if (synonymsGroupId > 0) { - return this.Request.CreateResponse(HttpStatusCode.OK, + return this.Request.CreateResponse( + HttpStatusCode.OK, new { Success = true, Id = synonymsGroupId }); } else { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "[" + duplicateWord + "] " + - string.Format(Localization.GetString("SynonymsTagDuplicated", Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + $"[{duplicateWord}] {string.Format(Localization.GetString("SynonymsTagDuplicated", Components.Constants.Constants.LocalResourcesFile))}"); } } catch (Exception exc) @@ -2024,26 +2058,29 @@ public HttpResponseMessage UpdateSynonymsGroup(UpdateSynonymsGroupRequest reques var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } if (request.SynonymsGroupID != null) { string duplicateWord; - var synonymsGroupId = SearchHelper.Instance.UpdateSynonymsGroup(request.SynonymsGroupID.Value, - request.SynonymsTags, pid, cultureCode, out duplicateWord); + var synonymsGroupId = SearchHelper.Instance.UpdateSynonymsGroup( + request.SynonymsGroupID.Value, + request.SynonymsTags, + pid, + cultureCode, + out duplicateWord); if (synonymsGroupId > 0) { return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); } else { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "[" + duplicateWord + "] " + - string.Format( - Localization.GetString( - "SynonymsTagDuplicated", - Components.Constants.Constants.LocalResourcesFile))); + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, + $"[{duplicateWord}] {string.Format(Localization.GetString("SynonymsTagDuplicated", Components.Constants.Constants.LocalResourcesFile))}"); } } else @@ -2112,10 +2149,12 @@ public HttpResponseMessage GetIgnoreWords(int? portalId, string cultureCode) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, AuthFailureMessage); } + var language = LocaleController.Instance.GetLocaleOrCurrent(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -2163,7 +2202,8 @@ public HttpResponseMessage AddIgnoreWords(UpdateIgnoreWordsRequest request) var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -2203,7 +2243,8 @@ public HttpResponseMessage UpdateIgnoreWords(UpdateIgnoreWordsRequest request) var language = LocaleController.Instance.GetLocale(pid, cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -2249,10 +2290,6 @@ public HttpResponseMessage DeleteIgnoreWords(UpdateIgnoreWordsRequest request) } } - #endregion - - #region Language Settings API - /// GET: api/SiteSettings/GetLanguageSettings /// /// Gets language settings. @@ -2268,7 +2305,8 @@ public HttpResponseMessage GetLanguageSettings(int? portalId) var pid = portalId ?? this.PortalId; if (!this.UserInfo.IsSuperUser && pid != this.PortalId) { - return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, + return this.Request.CreateErrorResponse( + HttpStatusCode.Unauthorized, "Authorization has been denied for this request."); } @@ -2278,7 +2316,8 @@ public HttpResponseMessage GetLanguageSettings(int? portalId) var languageDisplayModes = new List> { new KeyValuePair(Localization.GetString("NativeName", Components.Constants.Constants.LocalResourcesFile), "NATIVE"), - new KeyValuePair(Localization.GetString("EnglishName", Components.Constants.Constants.LocalResourcesFile), + new KeyValuePair( + Localization.GetString("EnglishName", Components.Constants.Constants.LocalResourcesFile), "ENGLISH"), }; @@ -2438,7 +2477,7 @@ public HttpResponseMessage GetLanguages(int? portalId) TranslatedStatus = this.GetTranslatedStatus(portalSettings, l.Code), Active = this.IsLanguagePublished(pid, l.Code), IsLocalized = this.IsLocalized(portalSettings, l.Code), - PublishedPages = this.GetPublishedLocalizedPages(pid, l.Code) + PublishedPages = this.GetPublishedLocalizedPages(pid, l.Code), }), }); } @@ -2457,7 +2496,7 @@ public HttpResponseMessage GetLanguages(int? portalId) l.NativeName, l.EnglishName, Enabled = this.IsLanguageEnabled(pid, l.Code), - IsDefault = l.Code == portalSettings.DefaultLanguage + IsDefault = l.Code == portalSettings.DefaultLanguage, }), }); } @@ -2519,7 +2558,7 @@ public HttpResponseMessage GetLanguage(int? portalId, int? languageId) { NativeName = Localization.GetString("System_Default", Components.Constants.Constants.LocalResourcesFile), EnglishName = Localization.GetString("System_Default", Components.Constants.Constants.LocalResourcesFile), - Name = "", + Name = string.Empty, Icon = Globals.ResolveUrl("~/images/Flags/none.gif"), }); @@ -2537,18 +2576,19 @@ public HttpResponseMessage GetLanguage(int? portalId, int? languageId) CanEnableDisable = this.CanEnableDisable(portalSettings, language.Code), IsDefault = language.Code == portalSettings.DefaultLanguage, Roles = PortalController.GetPortalSetting($"DefaultTranslatorRoles-{language.Code}", pid, "Administrators"), - } : new + } + : new { PortalId = pid, LanguageId = Null.NullInteger, - NativeName = "", - EnglishName = "", - Code = "", - Fallback = "", + NativeName = string.Empty, + EnglishName = string.Empty, + Code = string.Empty, + Fallback = string.Empty, Enabled = false, CanEnableDisable = false, IsDefault = false, - Roles = "", + Roles = string.Empty, }, SupportedFallbacks = fallbacks, }); @@ -2594,7 +2634,7 @@ public HttpResponseMessage GetAllLanguages() Icon = Globals.ResolveUrl( string.IsNullOrEmpty(c.Name) ? "~/images/Flags/none.gif" - : $"~/images/Flags/{c.Name}.gif") + : $"~/images/Flags/{c.Name}.gif"), }), }); } @@ -2699,8 +2739,8 @@ public HttpResponseMessage UpdateLanguage(UpdateLanguageRequest request) if (request.LanguageId != null) { var language = LocaleController.Instance.GetLocale(request.LanguageId.Value) ?? - (LocaleController.Instance.GetLocale(request.Code) ?? - new Locale { Code = request.Code }); + LocaleController.Instance.GetLocale(request.Code) ?? + new Locale { Code = request.Code }; if (this.UserInfo.IsSuperUser) { language.Fallback = request.Fallback; @@ -2734,7 +2774,7 @@ public HttpResponseMessage UpdateLanguage(UpdateLanguageRequest request) if (LocaleController.Instance.GetLocales(pid).Count == 2) { - redirectUrl = this.NavigationManager.NavigateURL(); + redirectUrl = this.navigationManager.NavigateURL(); } } else @@ -2744,13 +2784,17 @@ public HttpResponseMessage UpdateLanguage(UpdateLanguageRequest request) // if the disable language is current language, should redirect to default language. if ( - request.Code.Equals(Thread.CurrentThread.CurrentUICulture.ToString(), + request.Code.Equals( + Thread.CurrentThread.CurrentUICulture.ToString(), StringComparison.OrdinalIgnoreCase) || LocaleController.Instance.GetLocales(pid).Count == 1) { - redirectUrl = this.NavigationManager.NavigateURL(this.PortalSettings.ActiveTab.TabID, + redirectUrl = this.navigationManager.NavigateURL( + this.PortalSettings.ActiveTab.TabID, this.PortalSettings.ActiveTab.IsSuperTab, - this.PortalSettings, "", defaultLocale.Code); + this.PortalSettings, + string.Empty, + defaultLocale.Code); } // delete the tabs in this language @@ -2761,7 +2805,7 @@ public HttpResponseMessage UpdateLanguage(UpdateLanguageRequest request) } } - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, RedirectUrl = pid == this.PortalId ? redirectUrl : "" }); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, RedirectUrl = pid == this.PortalId ? redirectUrl : string.Empty }); } else { @@ -2807,7 +2851,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() { tableMissing.Add( ResourceFile(file.Key.ToString(), locale.Code) - .Replace(HttpContext.Current.Server.MapPath("~"), "")); + .Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); } else { @@ -2820,9 +2864,10 @@ public HttpResponseMessage VerifyLanguageResourceFiles() } catch { - tableError.Add(file.Key.ToString().Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableError.Add(file.Key.ToString().Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); dsDef = null; } + try { dsRes.ReadXml(ResourceFile(file.Key.ToString(), locale.Code)); @@ -2831,7 +2876,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() { if (locale.Text != Localization.SystemLocale) { - tableError.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableError.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); dsRes = null; } } @@ -2854,7 +2899,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() } catch { - tableDuplicate.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableDuplicate.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); } // Check for missing entries in localized file @@ -2865,7 +2910,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() } catch { - tableEntries.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableEntries.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); } finally { @@ -2880,7 +2925,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() } catch { - tableObsolete.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableObsolete.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); } finally { @@ -2891,7 +2936,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() var resFile = new FileInfo(ResourceFile(file.Key.ToString(), locale.Code)); if (((FileInfo)file.Value).LastWriteTime > resFile.LastWriteTime) { - tableOld.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), "")); + tableOld.Add(ResourceFile(file.Key.ToString(), locale.Code).Replace(HttpContext.Current.Server.MapPath("~"), string.Empty)); } } } @@ -2929,6 +2974,7 @@ public HttpResponseMessage VerifyLanguageResourceFiles() /// /// Gets module list by type. /// + /// The type of extension to get such as Module, Provider or AuthSystem. /// list of modules. [HttpGet] [RequireHost] @@ -2953,11 +2999,13 @@ DesktopModuleInfo objDm in else { modules.Add( - new KeyValuePair(objDm.FriendlyName + " [" + objDm.Version + "]", + new KeyValuePair( + objDm.FriendlyName + " [" + objDm.Version + "]", objDm.DesktopModuleID)); } } } + break; case "Provider": modules.AddRange(PackageController.Instance.GetExtensionPackages(Null.NullInteger, p => p.PackageType == "Provider").Select(objPackage => Null.IsNull(objPackage.Version) ? new KeyValuePair(objPackage.FriendlyName, objPackage.PackageID) : new KeyValuePair(objPackage.FriendlyName + " [" + Globals.FormatVersion(objPackage.Version) + "]", objPackage.PackageID)).Cast()); @@ -2996,13 +3044,13 @@ public HttpResponseMessage CreateLanguagePack(CreateLanguagePackRequest request) switch (request.PackType) { case "Core": - created = this._controller.CreateCorePackage(request.CultureCode, request.FileName, true); + created = this.controller.CreateCorePackage(request.CultureCode, request.FileName, true); break; case "Module": foreach (int moduleId in request.ModuleIds) { DesktopModuleInfo desktopModule = DesktopModuleController.GetDesktopModule(moduleId, Null.NullInteger); - created = this._controller.CreateModulePackage(request.CultureCode, desktopModule, true); + created = this.controller.CreateModulePackage(request.CultureCode, desktopModule, true); } break; @@ -3010,7 +3058,7 @@ public HttpResponseMessage CreateLanguagePack(CreateLanguagePackRequest request) foreach (int moduleId in request.ModuleIds) { PackageInfo provider = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == moduleId); - created = this._controller.CreateProviderPackage(request.CultureCode, provider, true); + created = this.controller.CreateProviderPackage(request.CultureCode, provider, true); } break; @@ -3018,12 +3066,12 @@ public HttpResponseMessage CreateLanguagePack(CreateLanguagePackRequest request) foreach (int moduleId in request.ModuleIds) { PackageInfo authSystem = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == moduleId); - created = this._controller.CreateAuthSystemPackage(request.CultureCode, authSystem, true); + created = this.controller.CreateAuthSystemPackage(request.CultureCode, authSystem, true); } break; case "Full": - this._controller.CreateFullPackage(request.CultureCode, request.FileName); + this.controller.CreateFullPackage(request.CultureCode, request.FileName); created = true; break; } @@ -3052,6 +3100,9 @@ public HttpResponseMessage CreateLanguagePack(CreateLanguagePackRequest request) /// /// Gets roles. /// + /// The Id of the portal for which to get the translator roles for. + /// The Id of the role group to filter the results. + /// The culture code for which to get the translators for. /// list of translator roles. [HttpGet] [DnnAuthorize(StaticRoles = Constants.AdminsRoleName)] @@ -3068,7 +3119,8 @@ public HttpResponseMessage GetTranslatorRoles(int? portalId, int groupId, string var language = LocaleController.Instance.GetLocale(cultureCode); if (language == null) { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + return this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("InvalidLocale.ErrorMessage", Components.Constants.Constants.LocalResourcesFile), cultureCode)); } @@ -3101,6 +3153,7 @@ public HttpResponseMessage GetTranslatorRoles(int? portalId, int groupId, string /// /// Gets role groups. /// + /// The ID of the portal for which to get the translator role groups for. /// list of translator role groups. [HttpGet] [DnnAuthorize(StaticRoles = Constants.AdminsRoleName)] @@ -3134,14 +3187,11 @@ public HttpResponseMessage GetTranslatorRoleGroups(int? portalId) } } - #endregion - - #region Other Settings API - /// GET: api/SiteSettings/GetOtherSettings /// /// Gets other settings. /// + /// The ID of the portal for which to get the other settings for. /// other settings. [HttpGet] [DnnAuthorize(StaticRoles = Constants.AdminsRoleName)] @@ -3227,8 +3277,8 @@ private static void GetResourceFiles(SortedList fileList, string path) var objFolder = new DirectoryInfo(folder); bool resxFilesDirectory = (objFolder.Name.ToLowerInvariant() == Localization.LocalResourceDirectory.ToLowerInvariant()) || - (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", "").ToLowerInvariant()) || - (folder.ToLowerInvariant().EndsWith("\\portals\\_default")); + (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", string.Empty).ToLowerInvariant()) || + folder.ToLowerInvariant().EndsWith("\\portals\\_default"); if (resxFilesDirectory) { @@ -3242,6 +3292,7 @@ private static void GetResourceFiles(SortedList fileList, string path) { continue; } + fileList.Add(fileInfo.FullName, fileInfo); } } @@ -3252,9 +3303,10 @@ private static void GetResourceFiles(SortedList fileList, string path) } } - #endregion - - #region Private Methods + private static string ResourceFile(string filename, string language) + { + return Localization.GetResourceFileName(filename, language, string.Empty, Globals.GetPortalSettings().PortalId); + } private bool IsLanguagePublished(int portalId, string code) { @@ -3264,29 +3316,32 @@ private bool IsLanguagePublished(int portalId, string code) { isPublished = enabledLanguage.IsPublished; } + return isPublished; } private string GetTranslatedPages(PortalSettings portalSettings, string code) { - string status = ""; + string status = string.Empty; if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) { int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated && !t.IsDeleted select t).Count(); status = translatedCount.ToString(CultureInfo.InvariantCulture); } + return status; } private string GetLocalizedStatus(PortalSettings portalSettings, string code) { - string status = ""; + string status = string.Empty; if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) { int defaultPageCount = this.GetLocalizedPages(portalSettings.PortalId, portalSettings.DefaultLanguage, false).Count; int currentPageCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; status = $"{currentPageCount / (float)defaultPageCount:#0%}"; } + return status; } @@ -3309,13 +3364,14 @@ private int GetPublishedLocalizedPages(int portalId, string code) private string GetTranslatedStatus(PortalSettings portalSettings, string code) { - string status = ""; + string status = string.Empty; if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) { int localizedCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated select t).Count(); status = $"{translatedCount / (float)localizedCount:#0%}"; } + return status; } @@ -3326,7 +3382,7 @@ private bool IsDefaultLanguage(PortalSettings portalSettings, string code) private bool IsLocalized(PortalSettings portalSettings, string code) { - return (code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0); + return code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0; } private bool CanDeleteProperty(ProfilePropertyDefinition definition) @@ -3353,6 +3409,7 @@ private string GetAbsoluteServerPath() { strServerPath += "\\"; } + return strServerPath; } else @@ -3370,6 +3427,7 @@ private string DisplayDataType(int dataType) { retValue = definitionEntry.Value; } + return retValue; } @@ -3383,7 +3441,8 @@ private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResp if (!propertyNameRegex.Match(definition.PropertyName).Success) { isValid = false; - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + httpPropertyValidationError = this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("NoSpecialCharacterName.Text", Components.Constants.Constants.LocalResourcesFile))); } @@ -3394,14 +3453,17 @@ private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResp { isValid = Null.NullBoolean; } + break; } if (isValid == false) { - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + httpPropertyValidationError = this.Request.CreateErrorResponse( + HttpStatusCode.BadRequest, string.Format(Localization.GetString("RequiredTextBox", Components.Constants.Constants.LocalResourcesFile))); } + return isValid; } @@ -3418,6 +3480,7 @@ private bool IsHttpAliasValid(string strAlias) { strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3); } + if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1) { strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2); @@ -3429,12 +3492,8 @@ private bool IsHttpAliasValid(string strAlias) isValid = false; } } - return isValid; - } - private static string ResourceFile(string filename, string language) - { - return Localization.GetResourceFileName(filename, language, "", Globals.GetPortalSettings().PortalId); + return isValid; } private bool IsLanguageEnabled(int portalId, string code) @@ -3454,6 +3513,7 @@ private bool CanEnableDisable(PortalSettings portalSettings, string code) { canEnable = !this.IsDefaultLanguage(portalSettings, code); } + return canEnable; } @@ -3473,6 +3533,7 @@ private CultureDropDownTypes GetCultureDropDownType(int portalId) displayType = CultureDropDownTypes.DisplayName; break; } + return displayType; } @@ -3522,7 +3583,5 @@ private int ValidateTabId(int tabId, int portalId) var tab = TabController.Instance.GetTab(tabId, portalId); return tab != null && !tab.IsDeleted ? tab.TabID : Null.NullInteger; } - - #endregion } } From ce247f54f0f21f6c768363211981a73c36405c9b Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sun, 3 Oct 2021 20:10:06 -0400 Subject: [PATCH 3/3] Removed unused line, this was added by mistake while trying to fix this bug in the wrong place --- .../Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs index 89325581e24..f59e7ef0963 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs @@ -409,7 +409,6 @@ public HttpResponseMessage UpdateDefaultPagesSettings(UpdateDefaultPagesSettings portalInfo.PrivacyTabId = this.ValidateTabId(request.PrivacyTabId, pid); PortalController.Instance.UpdatePortalInfo(portalInfo); - var portalSettings = PortalController.Instance.GetCurrentSettings(); PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogin", this.ValidateTabId(request.RedirectAfterLoginTabId, pid).ToString(), false, cultureCode); PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogout", this.ValidateTabId(request.RedirectAfterLogoutTabId, pid).ToString(), false, cultureCode); PortalController.UpdatePortalSetting(pid, "Redirect_AfterRegistration", this.ValidateTabId(request.RedirectAfterRegistrationTabId, pid).ToString(), false, cultureCode);