From fca61aa3779287fc272cd25079ca49930822a250 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sun, 3 Oct 2021 13:48:59 -0400 Subject: [PATCH] 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 } }