From 9d9006b2160627b73ef4730852211e69af389e08 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 01:18:11 -0400 Subject: [PATCH 01/10] Fixes about 200 Stylecop warnings --- .../Services/PagesController.cs | 648 +++++++++++------- 1 file changed, 410 insertions(+), 238 deletions(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs index 9fdd48f09f2..f6b680a54a5 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs @@ -39,56 +39,67 @@ namespace Dnn.PersonaBar.Pages.Services using Localization = Dnn.PersonaBar.Pages.Components.Localization; + /// + /// API controller for the Pages persona bar module. + /// [MenuPermission(MenuName = "Dnn.Pages")] [DnnExceptionFilter] public class PagesController : PersonaBarApiController { private const string LocalResourceFile = Library.Constants.PersonaBarRelativePath + "Modules/Dnn.Pages/App_LocalResources/Pages.resx"; private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(PagesController)); - private readonly IPagesController _pagesController; + private readonly IPagesController pagesController; - protected INavigationManager NavigationManager { get; } - private readonly IBulkPagesController _bulkPagesController; - private readonly IThemesController _themesController; - private readonly ITemplateController _templateController; - private readonly IDefaultPortalThemeController _defaultPortalThemeController; - - private readonly ITabController _tabController; - private readonly ILocaleController _localeController; - private readonly ISecurityService _securityService; - + private readonly IBulkPagesController bulkPagesController; + private readonly IThemesController themesController; + private readonly ITemplateController templateController; + private readonly IDefaultPortalThemeController defaultPortalThemeController; + + private readonly ITabController tabController; + private readonly ILocaleController localeController; + private readonly ISecurityService securityService; + + /// + /// Initializes a new instance of the class. + /// + /// the navigation manager to provide navigation features. public PagesController(INavigationManager navigationManager) { this.NavigationManager = navigationManager; - this._pagesController = Components.PagesController.Instance; - this._themesController = ThemesController.Instance; - this._bulkPagesController = BulkPagesController.Instance; - this._templateController = TemplateController.Instance; - this._defaultPortalThemeController = DefaultPortalThemeController.Instance; + this.pagesController = Components.PagesController.Instance; + this.themesController = ThemesController.Instance; + this.bulkPagesController = BulkPagesController.Instance; + this.templateController = TemplateController.Instance; + this.defaultPortalThemeController = DefaultPortalThemeController.Instance; - this._tabController = TabController.Instance; - this._localeController = LocaleController.Instance; - this._securityService = SecurityService.Instance; + this.tabController = TabController.Instance; + this.localeController = LocaleController.Instance; + this.securityService = SecurityService.Instance; } + /// + /// Gets the Navigation Manager that provides navigation features. + /// + protected INavigationManager NavigationManager { get; } + /// GET: api/Pages/GetPageDetails /// /// Get detail of a page. /// - /// - /// + /// The page (tab) id. + /// The page details. [HttpGet] public HttpResponseMessage GetPageDetails(int pageId) { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } try { - var page = this._pagesController.GetPageSettings(pageId); + var page = this.pagesController.GetPageSettings(pageId); return this.Request.CreateResponse(HttpStatusCode.OK, page); } catch (PageNotFoundException) @@ -101,77 +112,93 @@ public HttpResponseMessage GetPageDetails(int pageId) /// /// Get custom Urls of a page. /// - /// - /// + /// The page (tab) id. + /// A list of custom urls. [HttpGet] public HttpResponseMessage GetCustomUrls(int pageId) { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } - return this.Request.CreateResponse(HttpStatusCode.OK, this._pagesController.GetPageUrls(pageId)); + return this.Request.CreateResponse(HttpStatusCode.OK, this.pagesController.GetPageUrls(pageId)); } + /// + /// Creates a custom url for SEO purposes. + /// + /// DTO. + /// Information about success or failure as well as a possible error message and a new url suggestion. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage CreateCustomUrl(SeoUrl dto) { - if (!this._securityService.CanManagePage(dto.TabId)) + if (!this.securityService.CanManagePage(dto.TabId)) { return this.GetForbiddenResponse(); } - var result = this._pagesController.CreateCustomUrl(dto); + var result = this.pagesController.CreateCustomUrl(dto); - return this.Request.CreateResponse(HttpStatusCode.OK, - new - { - result.Id, - result.Success, - result.ErrorMessage, - result.SuggestedUrlPath - }); + return this.Request.CreateResponse( + HttpStatusCode.OK, + new + { + result.Id, + result.Success, + result.ErrorMessage, + result.SuggestedUrlPath, + }); } + /// + /// Updates a custom url. + /// + /// DTO. + /// the id, if the call succeeded or faile, a possible error message and a possible new url suggestion. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage UpdateCustomUrl(SeoUrl dto) { - if (!this._securityService.CanManagePage(dto.TabId)) + if (!this.securityService.CanManagePage(dto.TabId)) { return this.GetForbiddenResponse(); } - var result = this._pagesController.UpdateCustomUrl(dto); + var result = this.pagesController.UpdateCustomUrl(dto); return this.Request.CreateResponse(HttpStatusCode.OK, new { result.Id, result.Success, result.ErrorMessage, - result.SuggestedUrlPath + result.SuggestedUrlPath, }); } + /// + /// Deletes a custom URL. + /// + /// DTO. + /// A value indicating if the call succeeded. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage DeleteCustomUrl(UrlIdDto dto) { - if (!this._securityService.CanManagePage(dto.TabId)) + if (!this.securityService.CanManagePage(dto.TabId)) { return this.GetForbiddenResponse(); } - this._pagesController.DeleteCustomUrl(dto); + this.pagesController.DeleteCustomUrl(dto); var response = new { - Success = true + Success = true, }; return this.Request.CreateResponse(HttpStatusCode.OK, response); @@ -179,63 +206,75 @@ public HttpResponseMessage DeleteCustomUrl(UrlIdDto dto) /// GET: api/Pages/GetPageList /// - /// + /// Gets the list of pages for a given parent page. /// - /// - /// - /// + /// The page (tab) id for the parent. + /// An optional search string. + /// A list of pages. [HttpGet] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] public HttpResponseMessage GetPageList(int parentId = -1, string searchKey = "") - { var adminTabId = this.PortalSettings.AdminTabId; var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); - var pages = from p in this._pagesController.GetPageList(this.PortalSettings, parentId, searchKey) + var pages = from p in this.pagesController.GetPageList(this.PortalSettings, parentId, searchKey) select Converters.ConvertToPageItem(p, tabs); return this.Request.CreateResponse(HttpStatusCode.OK, pages); } /// GET: api/Pages/SearchPages /// - /// + /// Searches for pages. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The search string. + /// The type of page. + /// The page tags. + /// The publish status of the page. + /// The publish start date. + /// The publish end date. + /// The workflow id for the page. + /// What index of the pages paging to return. + /// How many pages to return per paging page. + /// Paged list of pages. [HttpGet] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] - public HttpResponseMessage SearchPages(string searchKey = "", string pageType = "", string tags = "", string publishStatus = "All", - string publishDateStart = "", string publishDateEnd = "", int workflowId = -1, int pageIndex = -1, int pageSize = -1) + public HttpResponseMessage SearchPages( + string searchKey = "", + string pageType = "", + string tags = "", + string publishStatus = "All", + string publishDateStart = "", + string publishDateEnd = "", + int workflowId = -1, + int pageIndex = -1, + int pageSize = -1) { int totalRecords; var adminTabId = this.PortalSettings.AdminTabId; var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); - var pages = from p in this._pagesController.SearchPages(out totalRecords, searchKey, pageType, tags, publishStatus, publishDateStart, publishDateEnd, workflowId, pageIndex, pageSize) + var pages = from p in this.pagesController.SearchPages(out totalRecords, searchKey, pageType, tags, publishStatus, publishDateStart, publishDateEnd, workflowId, pageIndex, pageSize) select Converters.ConvertToPageItem(p, tabs); var response = new { Success = true, Results = pages, - TotalResults = totalRecords + TotalResults = totalRecords, }; return this.Request.CreateResponse(HttpStatusCode.OK, response); } + /// + /// Gets the pages hierarchy. + /// + /// The page (tab) id. + /// The page hyerarchy. [HttpGet] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage GetPageHierarchy(int pageId) { try { - var paths = this._pagesController.GetPageHierarchy(pageId); + var paths = this.pagesController.GetPageHierarchy(pageId); return this.Request.CreateResponse(HttpStatusCode.OK, paths); } catch (PageNotFoundException) @@ -244,24 +283,33 @@ public HttpResponseMessage GetPageHierarchy(int pageId) } } + /// + /// Moves a page to another place in the hierarchy. + /// + /// DTO. + /// A status and information about the page at it's new location. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage MovePage(PageMoveRequest request) { - - if (!this._securityService.CanManagePage(request.PageId) - || !this._securityService.CanManagePage(request.ParentId) - || !this._securityService.CanManagePage(request.RelatedPageId) - || !this._securityService.CanManagePage(TabController.Instance.GetTab(request.RelatedPageId, this.PortalId)?.ParentId ?? -1)) + if (!this.securityService.CanManagePage(request.PageId) + || !this.securityService.CanManagePage(request.ParentId) + || !this.securityService.CanManagePage(request.RelatedPageId) + || !this.securityService.CanManagePage(TabController.Instance.GetTab(request.RelatedPageId, this.PortalId)?.ParentId ?? -1)) { return this.GetForbiddenResponse(); } try { - var tab = this._pagesController.MovePage(request); - var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, Null.NullInteger, false, true, false, + var tab = this.pagesController.MovePage(request); + var tabs = TabController.GetPortalTabs( + this.PortalSettings.PortalId, + Null.NullInteger, + false, + true, + false, true); var pageItem = Converters.ConvertToPageItem(tab, tabs); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, Page = pageItem }); @@ -276,41 +324,51 @@ public HttpResponseMessage MovePage(PageMoveRequest request) } } + /// + /// Deletes a page. + /// + /// The page to delete, DTO. + /// Should the page be hard-deleted or not. + /// The status of the page deletion. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage DeletePage(PageItem page, [FromUri] bool hardDelete = false) { - if (!this._securityService.CanDeletePage(page.Id)) + if (!this.securityService.CanDeletePage(page.Id)) { return this.GetForbiddenResponse(); } try { - this._pagesController.DeletePage(page, hardDelete, this.PortalSettings); + this.pagesController.DeletePage(page, hardDelete, this.PortalSettings); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); } catch (PageNotFoundException) { - return this.Request.CreateResponse(HttpStatusCode.NotFound); } } + /// + /// Deletes a module from a page. + /// + /// The module to delete, DTO. + /// A status code or an error. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage DeletePageModule(PageModuleItem module) { - if (!this._securityService.CanManagePage(module.PageId)) + if (!this.securityService.CanManagePage(module.PageId)) { return this.GetForbiddenResponse(); } try { - this._pagesController.DeleteTabModule(module.PageId, module.ModuleId); + this.pagesController.DeleteTabModule(module.PageId, module.ModuleId); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); } catch (PageModuleNotFoundException) @@ -319,33 +377,43 @@ public HttpResponseMessage DeletePageModule(PageModuleItem module) } } + /// + /// Copies the theme from a page to descendend pages. + /// + /// . + /// The status of the request. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage CopyThemeToDescendantPages(CopyThemeRequest copyTheme) { - if (!this._securityService.CanManagePage(copyTheme.PageId)) + if (!this.securityService.CanManagePage(copyTheme.PageId)) { return this.GetForbiddenResponse(); } - this._pagesController.CopyThemeToDescendantPages(copyTheme.PageId, copyTheme.Theme); + this.pagesController.CopyThemeToDescendantPages(copyTheme.PageId, copyTheme.Theme); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); } + /// + /// Copies permissions from a page to the descendent pages. + /// + /// DTO. + /// The status of the operation. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage CopyPermissionsToDescendantPages(CopyPermissionsRequest copyPermissions) { - if (!this._securityService.CanAdminPage(copyPermissions.PageId)) + if (!this.securityService.CanAdminPage(copyPermissions.PageId)) { return this.GetForbiddenResponse(); } try { - this._pagesController.CopyPermissionsToDescendantPages(copyPermissions.PageId); + this.pagesController.CopyPermissionsToDescendantPages(copyPermissions.PageId); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); } catch (PageNotFoundException) @@ -358,6 +426,11 @@ public HttpResponseMessage CopyPermissionsToDescendantPages(CopyPermissionsReque } } + /// + /// Sets a page in edit mode. + /// + /// the page (tab) id. + /// Sets a cookie for edit mode on the specified page then returns a success message. [HttpPost] public HttpResponseMessage EditModeForPage([FromUri] int id) { @@ -366,15 +439,20 @@ public HttpResponseMessage EditModeForPage([FromUri] int id) return this.GetForbiddenResponse(); } - this._pagesController.EditModeForPage(id, this.UserInfo.UserID); + this.pagesController.EditModeForPage(id, this.UserInfo.UserID); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); } + /// + /// Saves the page details. + /// + /// The new page settings, DTO. + /// The new page details. [HttpPost] [ValidateAntiForgeryToken] public HttpResponseMessage SavePageDetails(PageSettings pageSettings) { - if (!this._securityService.CanSavePageDetails(pageSettings)) + if (!this.securityService.CanSavePageDetails(pageSettings)) { return this.GetForbiddenResponse(); } @@ -382,14 +460,19 @@ public HttpResponseMessage SavePageDetails(PageSettings pageSettings) try { pageSettings.Clean(); - var tab = this._pagesController.SavePageDetails(this.PortalSettings, pageSettings); - var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, Null.NullInteger, false, true, false, + var tab = this.pagesController.SavePageDetails(this.PortalSettings, pageSettings); + var tabs = TabController.GetPortalTabs( + this.PortalSettings.PortalId, + Null.NullInteger, + false, + true, + false, true); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, - Page = Converters.ConvertToPageItem(tab, tabs) + Page = Converters.ConvertToPageItem(tab, tabs), }); } catch (PageNotFoundException) @@ -402,13 +485,22 @@ public HttpResponseMessage SavePageDetails(PageSettings pageSettings) } } + /// + /// Gets the default page settings. + /// + /// The page (tab) id. + /// The page default settings. [HttpGet] public HttpResponseMessage GetDefaultSettings(int pageId = 0) { - var settings = this._pagesController.GetDefaultSettings(pageId); + var settings = this.pagesController.GetDefaultSettings(pageId); return this.Request.CreateResponse(HttpStatusCode.OK, settings); } + /// + /// Gets the list of cache providers. + /// + /// List of cache providers. [HttpGet] public HttpResponseMessage GetCacheProviderList() { @@ -416,16 +508,20 @@ public HttpResponseMessage GetCacheProviderList() return this.Request.CreateResponse(HttpStatusCode.OK, providers); } + /// + /// Gets the available themes. + /// + /// Available themes. [HttpGet] public HttpResponseMessage GetThemes() { - var themes = this._themesController.GetLayouts(this.PortalSettings, ThemeLevel.All); + var themes = this.themesController.GetLayouts(this.PortalSettings, ThemeLevel.All); var defaultTheme = this.GetDefaultPortalTheme(); var defaultPortalThemeName = defaultTheme?.ThemeName; var defaultPortalThemeLevel = defaultTheme?.Level; - var defaultPortalLayout = this._defaultPortalThemeController.GetDefaultPortalLayout(); - var defaultPortalContainer = this._defaultPortalThemeController.GetDefaultPortalContainer(); + var defaultPortalLayout = this.defaultPortalThemeController.GetDefaultPortalLayout(); + var defaultPortalContainer = this.defaultPortalThemeController.GetDefaultPortalContainer(); return this.Request.CreateResponse(HttpStatusCode.OK, new { @@ -433,31 +529,42 @@ public HttpResponseMessage GetThemes() defaultPortalThemeName, defaultPortalThemeLevel, defaultPortalLayout, - defaultPortalContainer + defaultPortalContainer, }); } + /// + /// Gets the theme files for a given theme. + /// + /// The name of the theme. + /// The level of the theme, . + /// Returns a list of available layouts and containers for each theme. [HttpGet] public HttpResponseMessage GetThemeFiles(string themeName, ThemeLevel level) { - var themeLayout = this._themesController.GetLayouts(this.PortalSettings, level) + var themeLayout = this.themesController.GetLayouts(this.PortalSettings, level) .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); - var themeContainer = this._themesController.GetContainers(this.PortalSettings, level) + var themeContainer = this.themesController.GetContainers(this.PortalSettings, level) .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); return this.Request.CreateResponse(HttpStatusCode.OK, new { - layouts = themeLayout == null ? new List() : this._themesController.GetThemeFiles(this.PortalSettings, themeLayout), - containers = themeContainer == null ? new List() : this._themesController.GetThemeFiles(this.PortalSettings, themeContainer) + layouts = themeLayout == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeLayout), + containers = themeContainer == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeContainer), }); } + /// + /// Save bulk pages (Add multiple pages). + /// + /// DTO. + /// A status code and the result of adding the multiple pages. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) { - if (!this._securityService.IsPageAdminUser()) + if (!this.securityService.IsPageAdminUser()) { return this.GetForbiddenResponse(); } @@ -465,12 +572,12 @@ public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) try { bulkPage.Clean(); - var bulkPageResponse = this._bulkPagesController.AddBulkPages(bulkPage, validateOnly: false); + var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: false); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, - Response = bulkPageResponse + Response = bulkPageResponse, }); } catch (PageValidationException ex) @@ -479,12 +586,17 @@ public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) } } + /// + /// Validates if bulk pages (Add multiple pages) information is valid. + /// + /// DTO. + /// A status code and the result of the bulk pages check. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage PreSaveBulkPagesValidate(BulkPage bulkPage) { - if (!this._securityService.IsPageAdminUser()) + if (!this.securityService.IsPageAdminUser()) { return this.GetForbiddenResponse(); } @@ -492,12 +604,12 @@ public HttpResponseMessage PreSaveBulkPagesValidate(BulkPage bulkPage) try { bulkPage.Clean(); - var bulkPageResponse = this._bulkPagesController.AddBulkPages(bulkPage, validateOnly: true); + var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: true); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, - Response = bulkPageResponse + Response = bulkPageResponse, }); } catch (PageValidationException ex) @@ -506,12 +618,17 @@ public HttpResponseMessage PreSaveBulkPagesValidate(BulkPage bulkPage) } } + /// + /// Saves a page as a template. + /// + /// DTO. + /// The status of the operation with a possible error message. [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) { - if (!this._securityService.CanExportPage(pageTemplate.TabId)) + if (!this.securityService.CanExportPage(pageTemplate.TabId)) { return this.GetForbiddenResponse(); } @@ -519,13 +636,13 @@ public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) try { pageTemplate.Clean(); - var templateFilename = this._templateController.SaveAsTemplate(pageTemplate); + var templateFilename = this.templateController.SaveAsTemplate(pageTemplate); var response = string.Format(Localization.GetString("ExportedMessage"), templateFilename); return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, - Response = response + Response = response, }); } catch (TemplateException ex) @@ -534,10 +651,12 @@ public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) } } - // From inside Visual Studio editor press [CTRL]+[M] then [O] to collapse source code to definition - // From inside Visual Studio editor press [CTRL]+[M] then [P] to expand source code folding - - // POST /api/personabar/pages/MakePageNeutral?tabId=123 + /// + /// Makes a localized pages neutral. + /// + /// The page (tab) id. + /// A success status or an exception. + /// POST /api/personabar/pages/MakePageNeutral?tabId=123 . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -545,28 +664,34 @@ public HttpResponseMessage MakePageNeutral([FromUri] int pageId) { try { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } - if (this._tabController.GetTabsByPortal(this.PortalId).WithParentId(pageId).Count > 0) + if (this.tabController.GetTabsByPortal(this.PortalId).WithParentId(pageId).Count > 0) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("MakeNeutral.ErrorMessage")); } - var defaultLocale = this._localeController.GetDefaultLocale(this.PortalId); - this._tabController.ConvertTabToNeutralLanguage(this.PortalId, pageId, defaultLocale.Code, true); + var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); + this.tabController.ConvertTabToNeutralLanguage(this.PortalId, pageId, defaultLocale.Code, true); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to make this page neureal, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/MakePageTranslatable?tabId=123 + /// + /// Makes a neutral page localizable. + /// + /// the page (tab) id. + /// A status code or an error message. + /// POST /api/personabar/pages/MakePageTranslatable?tabId=123 . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -574,31 +699,37 @@ public HttpResponseMessage MakePageTranslatable([FromUri] int pageId) { try { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } - var currentTab = this._tabController.GetTab(pageId, this.PortalId, false); + var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); if (currentTab == null) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTab"); } - var defaultLocale = this._localeController.GetDefaultLocale(this.PortalId); - this._tabController.LocalizeTab(currentTab, defaultLocale, true); - this._tabController.AddMissingLanguages(this.PortalId, pageId); - this._tabController.ClearCache(this.PortalId); + var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); + this.tabController.LocalizeTab(currentTab, defaultLocale, true); + this.tabController.AddMissingLanguages(this.PortalId, pageId); + this.tabController.ClearCache(this.PortalId); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to make this page translatable."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/AddMissingLanguages?tabId=123 + /// + /// Adds all missing languages to a page. + /// + /// The page (tab) id. + /// A status code or an exception message. + /// POST /api/personabar/pages/AddMissingLanguages?tabId=123 . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -606,23 +737,29 @@ public HttpResponseMessage AddMissingLanguages([FromUri] int pageId) { try { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } - this._tabController.AddMissingLanguages(this.PortalId, pageId); - this._tabController.ClearCache(this.PortalId); + this.tabController.AddMissingLanguages(this.PortalId, pageId); + this.tabController.ClearCache(this.PortalId); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to add missing languages to this page, consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/NotifyTranslators + /// + /// Notifies the translators with a comment. + /// + /// DTO. + /// A status code and a message. + /// POST /api/personabar/pages/NotifyTranslators . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -630,21 +767,21 @@ public HttpResponseMessage NotifyTranslators(TranslatorsComment comment) { try { - if (!this._securityService.CanManagePage(comment.TabId)) + if (!this.securityService.CanManagePage(comment.TabId)) { return this.GetForbiddenResponse(); } // loop through all localized version of this page - var currentTab = this._tabController.GetTab(comment.TabId, this.PortalId, false); + var currentTab = this.tabController.GetTab(comment.TabId, this.PortalId, false); foreach (var localizedTab in currentTab.LocalizedTabs.Values) { var users = new Dictionary(); - //Give default translators for this language and administrators permissions - this._tabController.GiveTranslatorRoleEditRights(localizedTab, users); + // Give default translators for this language and administrators permissions + this.tabController.GiveTranslatorRoleEditRights(localizedTab, users); - //Send Messages to all the translators of new content + // Send Messages to all the translators of new content foreach (var translator in users.Values.Where(user => user.UserID != this.PortalSettings.AdministratorId)) { this.AddTranslationSubmittedNotification(localizedTab, translator, comment.Text); @@ -656,45 +793,53 @@ public HttpResponseMessage NotifyTranslators(TranslatorsComment comment) } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to notify the translators, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // GET /api/personabar/pages/GetTabLocalization?pageId=123 /// /// Gets the view data that used to be in the old ControlBar's localization tab /// under Page Settings ( /{page}/ctl/Tab/action/edit/activeTab/settingTab ). /// /// The ID of the tab to get localization for. - /// + /// Information about localiz. + /// /api/personabar/pages/GetTabLocalization?pageId=123. [HttpGet] public HttpResponseMessage GetTabLocalization(int pageId) { try { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } - var currentTab = this._tabController.GetTab(pageId, this.PortalId, false); + var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); var locales = new List(); var pages = new DnnPagesDto(locales); if (!currentTab.IsNeutralCulture) { pages = this.GetNonLocalizedPages(pageId); } + return this.Request.CreateResponse(HttpStatusCode.OK, pages); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured trying to get this page localization, consolt the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/UpdateTabLocalization + /// + /// Updates the page (tab) localization. + /// + /// DTO. + /// A status code or an exception message. + /// POST /api/personabar/pages/UpdateTabLocalization . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -702,7 +847,7 @@ public HttpResponseMessage UpdateTabLocalization(DnnPagesRequest request) { try { - if (request.Pages.Any(x => x.TabId > 0 && !this._securityService.CanManagePage(x.TabId))) + if (request.Pages.Any(x => x.TabId > 0 && !this.securityService.CanManagePage(x.TabId))) { return this.GetForbiddenResponse(); } @@ -712,12 +857,18 @@ public HttpResponseMessage UpdateTabLocalization(DnnPagesRequest request) } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured trying to update the page localization, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/RestoreModule?tabModuleId=123 + /// + /// Restores a deleted module on a page (tab). + /// + /// The TabModule id. + /// A success message or an exception message. + /// POST /api/personabar/pages/RestoreModule?tabModuleId=123 . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -726,7 +877,7 @@ public HttpResponseMessage RestoreModule(int tabModuleId) try { var module = ModuleController.Instance.GetTabModule(tabModuleId); - if (!this._securityService.CanManagePage(module.TabID)) + if (!this.securityService.CanManagePage(module.TabID)) { return this.GetForbiddenResponse(); } @@ -743,12 +894,18 @@ public HttpResponseMessage RestoreModule(int tabModuleId) } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to restore the module onto that page."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/DeleteModule?tabModuleId=123 + /// + /// Deletes a module from a page (tab). + /// + /// The TabModuleId. + /// A status message or an error message. + /// POST /api/personabar/pages/DeleteModule?tabModuleId=123 . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -757,7 +914,7 @@ public HttpResponseMessage DeleteModule(int tabModuleId) try { var module = ModuleController.Instance.GetTabModule(tabModuleId); - if (!this._securityService.CanManagePage(module.TabID)) + if (!this.securityService.CanManagePage(module.TabID)) { return this.GetForbiddenResponse(); } @@ -774,16 +931,17 @@ public HttpResponseMessage DeleteModule(int tabModuleId) } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to delete the module, consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // GET /api/personabar/pages/GetContentLocalizationEnabled /// - /// Gets ContentLocalizationEnabled. + /// Gets ContentLocalizationEnabled. /// - /// + /// A value indicating if content localization is enabled. + /// GET /api/personabar/pages/GetContentLocalizationEnabled. [HttpGet] public HttpResponseMessage GetContentLocalizationEnabled() { @@ -793,20 +951,24 @@ public HttpResponseMessage GetContentLocalizationEnabled() { return this.GetForbiddenResponse(); } + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, this.PortalSettings.ContentLocalizationEnabled }); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured while trying to find if content localization is enabled"; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // GET /api/personabar/pages/GetCachedItemCount /// - /// Gets GetCachedItemCount. + /// Gets GetCachedItemCount. /// - /// + /// The cache profider. + /// The page (tab) id. + /// Caching information. + /// GET /api/personabar/pages/GetCachedItemCount. [HttpGet] public HttpResponseMessage GetCachedItemCount(string cacheProvider, int pageId) { @@ -816,16 +978,24 @@ public HttpResponseMessage GetCachedItemCount(string cacheProvider, int pageId) { return this.GetForbiddenResponse(); } + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Count = OutputCachingProvider.Instance(cacheProvider).GetItemCount(pageId) }); } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var errorMessage = "An unexpected error occured trying to get the cached items count, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } } - // POST /api/personabar/pages/ClearCache + /// + /// Clears the page cache for a given page. + /// + /// The cache provider to clear the cache for. + /// The page (tab) id. + /// A status code or an error message. + /// POST /api/personabar/pages/ClearCache . [HttpPost] [ValidateAntiForgeryToken] [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] @@ -833,7 +1003,7 @@ public HttpResponseMessage ClearCache([FromUri] string cacheProvider, [FromUri] { try { - if (!this._securityService.CanManagePage(pageId)) + if (!this.securityService.CanManagePage(pageId)) { return this.GetForbiddenResponse(); } @@ -843,14 +1013,12 @@ public HttpResponseMessage ClearCache([FromUri] string cacheProvider, [FromUri] } catch (Exception ex) { - Logger.Error(ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()); + var message = "An unexpected error occured while trying to clear the cache for this page, see logs for more details."; + Logger.Error(message, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message); } } - // From inside Visual Studio editor press [CTRL]+[M] then [O] to collapse source code to definition - // From inside Visual Studio editor press [CTRL]+[M] then [P] to expand source code folding - private static string LocalizeString(string key) { return DotNetNuke.Services.Localization.Localization.GetString(key, LocalResourceFile); @@ -870,31 +1038,38 @@ private static void EnableTabVersioningAndWorkflow(TabInfo tab) { tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, true); } - } + } + + private static void DisableTabVersioningAndWorkflow(TabInfo tab) + { + var tabVersionSettings = TabVersionSettings.Instance; + var tabWorkflowSettings = TabWorkflowSettings.Instance; - //private bool IsDefaultLanguage(string cultureCode) - //{ - // return string.Equals(cultureCode, PortalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase); - //} + if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) + { + tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, false); + } - //private bool IsLanguageEnabled(string cultureCode) - //{ - // return _localeController.GetLocales(PortalId).ContainsKey(cultureCode); - //} + if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) + { + tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, false); + } + } private DnnPagesDto GetNonLocalizedPages(int tabId) { - var currentTab = this._tabController.GetTab(tabId, this.PortalId, false); + var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); - //Unique id of default language page + // Unique id of default language page var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid ? currentTab.DefaultLanguageGuid : currentTab.UniqueId; // get all non admin pages and not deleted - var allPages = this._tabController.GetTabsByPortal(this.PortalId).Values.Where( + var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); allPages = allPages.Where(t => t.IsDeleted == false); + // get all localized pages of current page var tabInfos = allPages as IList ?? allPages.ToList(); var localizedPages = tabInfos.Where( @@ -909,24 +1084,23 @@ private DnnPagesDto GetNonLocalizedPages(int tabId) var localeDict = localeController.GetLocales(this.PortalId); if (localeDict.Count == 0) { - locales.Add(new LocaleInfoDto("")); + locales.Add(new LocaleInfoDto(string.Empty)); } else { - if (localizedPages.Count == 1 && localizedPages.First().CultureCode == "") + if (localizedPages.Count == 1 && localizedPages.First().CultureCode == string.Empty) { // locale neutral page - locales.Add(new LocaleInfoDto("")); + locales.Add(new LocaleInfoDto(string.Empty)); } else if (localizedPages.Count == 1 && localizedPages.First().CultureCode != this.PortalSettings.DefaultLanguage) { var first = localizedPages.First(); locales.Add(new LocaleInfoDto(first.CultureCode)); - //localizedTabs = new Dictionary { { first.CultureCode, first } }; } else { - //force sort order, so first add default language + // force sort order, so first add default language locales.Add(new LocaleInfoDto(this.PortalSettings.DefaultLanguage)); // build up a list of localized tabs. @@ -961,7 +1135,7 @@ where TabPermissionController.CanViewPage(localizedTab.Value) var dnnPages = new DnnPagesDto(locales) { - HasMissingLanguages = this._tabController.HasMissingLanguages(this.PortalId, tabId) + HasMissingLanguages = this.tabController.HasMissingLanguages(this.PortalId, tabId), }; // filter the list of localized pages to only those that have a culture we want to see @@ -978,34 +1152,36 @@ where TabPermissionController.CanViewPage(localizedTab.Value) dnnPages.Pages.Remove(dnnPage); break; } + dnnPage.TabId = localTabInfo.TabID; dnnPage.TabName = localTabInfo.TabName; dnnPage.Title = localTabInfo.Title; dnnPage.Description = localTabInfo.Description; - dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", ""); - dnnPage.HasChildren = (this._tabController.GetTabsByPortal(this.PortalId).WithParentId(tabInfo.TabID).Count != 0); + dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", string.Empty); + dnnPage.HasChildren = this.tabController.GetTabsByPortal(this.PortalId).WithParentId(tabInfo.TabID).Count != 0; dnnPage.CanAdminPage = TabPermissionController.CanAdminPage(tabInfo); dnnPage.CanViewPage = TabPermissionController.CanViewPage(tabInfo); dnnPage.LocalResourceFile = LocalResourceFile; - dnnPage.PageUrl = this.NavigationManager.NavigateURL(localTabInfo.TabID, false, this.PortalSettings, "", localTabInfo.CultureCode); + dnnPage.PageUrl = this.NavigationManager.NavigateURL(localTabInfo.TabID, false, this.PortalSettings, string.Empty, localTabInfo.CultureCode); dnnPage.IsSpecial = TabController.IsSpecialTab(localTabInfo.TabID, localTabInfo.PortalID); // calculate position in the form of 1.3.2... - var siblingTabs = tabInfos.Where(t => t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); + var siblingTabs = tabInfos.Where(t => (t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture); var parentTabId = localTabInfo.ParentId; while (parentTabId > 0) { var parentTab = tabInfos.Single(t => t.TabID == parentTabId); var id = parentTabId; - siblingTabs = tabInfos.Where(t => t.ParentId == id && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); + siblingTabs = tabInfos.Where(t => (t.ParentId == id && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position; parentTabId = parentTab.ParentId; } dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid; dnnPage.IsTranslated = localTabInfo.IsTranslated; - dnnPage.IsPublished = this._tabController.IsTabPublished(localTabInfo); + dnnPage.IsPublished = this.tabController.IsTabPublished(localTabInfo); + // generate modules information var moduleController = ModuleController.Instance; foreach (var moduleInfo in moduleController.GetTabModules(localTabInfo.TabID).Values) @@ -1014,6 +1190,7 @@ where TabPermissionController.CanViewPage(localizedTab.Value) var dnnModules = dnnPages.Module(guid); // modules of each language var dnnModule = dnnModules.Module(localTabInfo.CultureCode); + // detect error : 2 modules with same uniqueId on the same page dnnModule.LocalResourceFile = LocalResourceFile; if (dnnModule.TabModuleId > 0) @@ -1037,15 +1214,18 @@ where TabPermissionController.CanViewPage(localizedTab.Value) if (defaultLanguageModule != null) { dnnModule.DefaultModuleId = defaultLanguageModule.ModuleID; - if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid) - dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName; + if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid) + { + dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName; + } } } + dnnModule.SetModuleInfoHelp(); dnnModule.IsTranslated = moduleInfo.IsTranslated; dnnModule.IsLocalized = moduleInfo.IsLocalized; - dnnModule.IsShared = this._tabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1; + dnnModule.IsShared = this.tabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1; // detect error : the default language module is on an other page dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null; @@ -1065,7 +1245,7 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) // check all pages foreach (var page in pages.Pages) { - var tabInfo = this._tabController.GetTab(page.TabId, this.PortalId, true); + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); if (tabInfo != null && (tabInfo.TabName != page.TabName || tabInfo.Title != page.Title || @@ -1074,7 +1254,7 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) tabInfo.TabName = page.TabName; tabInfo.Title = page.Title; tabInfo.Description = page.Description; - this._tabController.UpdateTab(tabInfo); + this.tabController.UpdateTab(tabInfo); } } @@ -1099,11 +1279,15 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) if (tabModule.DefaultLanguageGuid != Null.NullGuid && tabModule.IsLocalized != moduleDto.IsLocalized) { - var locale = this._localeController.GetLocale(tabModule.CultureCode); - if (moduleDto.IsLocalized) - moduleController.LocalizeModule(tabModule, locale); - else - moduleController.DeLocalizeModule(tabModule); + var locale = this.localeController.GetLocale(tabModule.CultureCode); + if (moduleDto.IsLocalized) + { + moduleController.LocalizeModule(tabModule, locale); + } + else + { + moduleController.DeLocalizeModule(tabModule); + } } bool moduleTranslateOverride; @@ -1151,6 +1335,7 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) { moduleInfo.DefaultLanguageGuid = miDefault.UniqueId; } + moduleController.UpdateModule(moduleInfo); } } @@ -1165,7 +1350,7 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) foreach (var page in pages.Pages) { - var tabInfo = this._tabController.GetTab(page.TabId, this.PortalId, true); + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); if (tabInfo != null) { var moduleTranslateOverride = false; @@ -1173,7 +1358,7 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) { if (tabInfo.IsTranslated != page.IsTranslated) { - this._tabController.UpdateTranslationStatus(tabInfo, page.IsTranslated); + this.tabController.UpdateTranslationStatus(tabInfo, page.IsTranslated); if (page.IsTranslated) { moduleTranslateOverride = true; @@ -1203,24 +1388,24 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) // marks all modules as translated, marks page as translated foreach (var tabInfo in tabsToPublish) { - //First mark all modules as translated + // First mark all modules as translated foreach (var module in moduleController.GetTabModules(tabInfo.TabID).Values) { moduleController.UpdateTranslationStatus(module, true); } - //Second mark tab as translated - this._tabController.UpdateTranslationStatus(tabInfo, true); + // Second mark tab as translated + this.tabController.UpdateTranslationStatus(tabInfo, true); - //Third publish Tab (update Permissions) - this._tabController.PublishTab(tabInfo); + // Third publish Tab (update Permissions) + this.tabController.PublishTab(tabInfo); } // manage translated status of tab. In order to do that, we need to check if all modules on the page are translated var tabTranslatedStatus = true; foreach (var page in pages.Pages) { - var tabInfo = this._tabController.GetTab(page.TabId, this.PortalId, true); + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); if (tabInfo != null) { if (tabInfo.ChildModules.Any(moduleKvp => !moduleKvp.Value.IsTranslated)) @@ -1230,34 +1415,19 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) if (tabTranslatedStatus && !tabInfo.IsTranslated) { - this._tabController.UpdateTranslationStatus(tabInfo, true); + this.tabController.UpdateTranslationStatus(tabInfo, true); } } } } - private static void DisableTabVersioningAndWorkflow(TabInfo tab) - { - var tabVersionSettings = TabVersionSettings.Instance; - var tabWorkflowSettings = TabWorkflowSettings.Instance; - - if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) - { - tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, false); - } - - if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) - { - tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, false); - } - } - private void AddTranslationSubmittedNotification(TabInfo tabInfo, UserInfo translator, string comment) { var notificationsController = NotificationsController.Instance; var notificationType = notificationsController.GetNotificationType("TranslationSubmitted"); var subject = LocalizeString("NewContentMessage.Subject"); - var body = string.Format(LocalizeString("NewContentMessage.Body"), + var body = string.Format( + LocalizeString("NewContentMessage.Body"), tabInfo.TabName, this.NavigationManager.NavigateURL(tabInfo.TabID, false, this.PortalSettings, Null.NullString, tabInfo.CultureCode), comment); @@ -1269,7 +1439,7 @@ private void AddTranslationSubmittedNotification(TabInfo tabInfo, UserInfo trans Subject = subject, Body = body, IncludeDismissAction = true, - SenderUserID = sender.UserID + SenderUserID = sender.UserID, }; notificationsController.SendNotification(notification, this.PortalSettings.PortalId, null, new List { translator }); @@ -1282,28 +1452,30 @@ private HttpResponseMessage GetForbiddenResponse() private ThemeFileInfo GetDefaultPortalTheme() { - var layoutSrc = this._defaultPortalThemeController.GetDefaultPortalLayout(); + var layoutSrc = this.defaultPortalThemeController.GetDefaultPortalLayout(); if (string.IsNullOrWhiteSpace(layoutSrc)) { return null; } - var layout = this._themesController.GetThemeFile(PortalSettings.Current, layoutSrc, ThemeType.Skin); + + var layout = this.themesController.GetThemeFile(PortalSettings.Current, layoutSrc, ThemeType.Skin); return layout; } private TabInfo GetLocalizedTab(int tabId, string cultureCode) { - var currentTab = this._tabController.GetTab(tabId, this.PortalId, false); + var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); - //Unique id of default language page + // Unique id of default language page var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid ? currentTab.DefaultLanguageGuid : currentTab.UniqueId; // get all non admin pages and not deleted - var allPages = this._tabController.GetTabsByPortal(this.PortalId).Values.Where( + var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); allPages = allPages.Where(t => t.IsDeleted == false); + // get all localized pages of current page var tabInfos = allPages as IList ?? allPages.ToList(); return tabInfos.SingleOrDefault(t => (t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId) && t.CultureCode == cultureCode); From 454b7657484f5b035bdd3abe247257310dac483b Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 02:13:19 -0400 Subject: [PATCH 02/10] Fixes #3863 --- .../ClientSide/Dnn.React.Common/src/FileUpload/index.jsx | 2 +- .../Pages.Web/src/components/PageDetails/PageDetails.jsx | 4 +++- .../src/components/PageDetails/PageIcons/PageIcons.jsx | 3 +++ .../ClientSide/Pages.Web/src/services/pageService.js | 7 ++++--- .../Dnn.PersonaBar.Extensions/Services/PagesController.cs | 6 +++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/index.jsx b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/index.jsx index 28112c92948..e9b964b4e69 100644 --- a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/index.jsx +++ b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/index.jsx @@ -430,6 +430,7 @@ FileUpload.propTypes = { //---REQUIRED PROPS--- utils: PropTypes.object.isRequired, onSelectFile: PropTypes.func.isRequired, + validationCode: PropTypes.string.isRequired, //---OPTIONAL PROPS--- selectedFile: PropTypes.object, @@ -466,7 +467,6 @@ FileUpload.defaultProps = { cropImagePreview: false, portalId: -1, fileFormats: [], - browseButtonText: "Browse Filesystem", uploadButtonText: "Upload a File", linkButtonText: "Enter URL Link", diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx index d788b74c183..8e6a10a68da 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx @@ -5,6 +5,7 @@ import PageStandard from "./PageStandard/PageStandard"; import PageUrl from "./PageUrl/PageUrl"; import PageDetailsFooter from "./PageDetailsFooter/PageDetailsFooter"; import PageIcons from "./PageIcons/PageIcons"; +import { propTypes } from "react-widgets/lib/selectlist"; class PageDetail extends Component { @@ -28,7 +29,7 @@ class PageDetail extends Component { return (
- +
); @@ -37,6 +38,7 @@ class PageDetail extends Component { PageDetail.propTypes = { page: PropTypes.object.isRequired, + validationCode: propTypes.string.isRequired, errors: PropTypes.object.isRequired, onChangeField: PropTypes.func.isRequired, components: PropTypes.array.isRequired, diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageIcons/PageIcons.jsx b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageIcons/PageIcons.jsx index 4916a626e2b..4dd11e6e11b 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageIcons/PageIcons.jsx +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageIcons/PageIcons.jsx @@ -32,6 +32,7 @@ export default class PageIcons extends Component { selectedFile={props.page.iconFile} folderName={props.page.iconFile ? props.page.iconFile.folderName: null} fileFormats={["image/png", "image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/svg+xml"]} + validationCode={props.validationCode} browseActionText={Localization.get("BrowseAction")} // Press {save|[ENTER]} to save, or {cancel|[ESC]} to cancel browseButtonText={Localization.get("BrowseButton")} // Browse Filesystem defaultText={Localization.get("DragOver")} // Drag and Drop a File @@ -63,6 +64,7 @@ export default class PageIcons extends Component { selectedFile={props.page.iconFileLarge} folderName={props.page.iconFileLarge ? props.page.iconFileLarge.folderName : null} fileFormats={["image/png", "image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/svg+xml"]} + validationCode={props.validationCode} browseActionText={Localization.get("BrowseAction")} // Press {save|[ENTER]} to save, or {cancel|[ESC]} to cancel browseButtonText={Localization.get("BrowseButton")} // Browse Filesystem defaultText={Localization.get("DragOver")} // Drag and Drop a File @@ -91,6 +93,7 @@ export default class PageIcons extends Component { PageIcons.propTypes = { page: PropTypes.object.isRequired, + validationCode: PropTypes.string.isRequired, errors: PropTypes.object.isRequired, onChangeField: PropTypes.func.isRequired, components: PropTypes.array.isRequired diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js index 3d879c85747..e894a4c3395 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js @@ -115,10 +115,11 @@ const PageService = function () { }); }; - const toFrontEndPage = function (page) { + const toFrontEndPage = function (pageResult) { return { - ...page, - schedulingEnabled: page.startDate || page.endDate + ...pageResult.page, + schedulingEnabled: pageResult.page.startDate || page.endDate, + validationCode: pageResult.page.ValidationCode, }; }; diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs index f6b680a54a5..d29db2cfd45 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs @@ -35,8 +35,8 @@ namespace Dnn.PersonaBar.Pages.Services using DotNetNuke.Services.Localization; using DotNetNuke.Services.OutputCache; using DotNetNuke.Services.Social.Notifications; - using DotNetNuke.Web.Api; - + using DotNetNuke.Web.Api; + using DotNetNuke.Web.UI.WebControls; using Localization = Dnn.PersonaBar.Pages.Components.Localization; /// @@ -100,7 +100,7 @@ public HttpResponseMessage GetPageDetails(int pageId) try { var page = this.pagesController.GetPageSettings(pageId); - return this.Request.CreateResponse(HttpStatusCode.OK, page); + return this.Request.CreateResponse(HttpStatusCode.OK, new { page, new DnnFileUploadOptions().ValidationCode }); } catch (PageNotFoundException) { From 04ff51e8fa76071f40d0914201c6458da0dd1cb3 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 02:22:38 -0400 Subject: [PATCH 03/10] Fixed a type in pageServices.js --- .../ClientSide/Pages.Web/src/services/pageService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js index e894a4c3395..71a89462944 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js @@ -118,7 +118,7 @@ const PageService = function () { const toFrontEndPage = function (pageResult) { return { ...pageResult.page, - schedulingEnabled: pageResult.page.startDate || page.endDate, + schedulingEnabled: pageResult.page.startDate || pageResult.page.endDate, validationCode: pageResult.page.ValidationCode, }; }; From 6ef0c5b722d2f00bbbc54143c809db163e14b2e2 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 02:53:41 -0400 Subject: [PATCH 04/10] Adds proper support for popular mime-types --- .../src/FileUpload/Browse/index.jsx | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx index df35e008257..bfa9b4719ca 100644 --- a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx +++ b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx @@ -96,10 +96,56 @@ export default class Browse extends Component { sf.get("GetFolderDescendants", { parentId }, this.addChildFolders.bind(this, parentId), this.handleError.bind(this)); } + getExtensions(fileFormats) { + let result = ""; + + const extenstions = { + "text/html": "htm,html", + "text/css": "css", + "text/xml": "xml", + "image/gif": "gif", + "image/jpeg": "jpeg,jpg", + "application/x-javascript": "js", + "text/plain": "txt", + "image/png": "png", + "image/tiff": "tif,tiff", + "image/x-icon": "ico", + "image/x-ms-bmp": "bmp", + "image/xvg+xml": "svg", + "image/webp": "webp", + "application/msword": "doc", + "application/pdf": "pdf", + "application/rtf": "rtf", + "application/vnd.ms-excel": "xls", + "application.vnd.ms-powerpoint": "ppt", + "application/x-shockwave-flash": "swf", + "appliation/zip": "zip", + "audio/mpeg": "mp3", + "audio/ogg": "ogg", + "video/3gpp": "3gpp,3gp", + "video/mpeg": "mpeg,mpg", + "video/quicktime": "mov", + "video/x-flv": "flv", + "video/x-ms-wmv": "wmv", + "video/x-msvideo": "avi", + "video/mp4": "m4v,mp4", + } + + fileFormats.map(fileFormat => { + if (extensions[fileFormat]) { + results += extensions[fileFormat] + ','; + } + else { + result += fileFormat.split('/')[1] + ','; + } + }); + return result; + } + getFiles() { const sf = this.getServiceFramework(); let parentId = this.state.selectedFolder ? this.state.selectedFolder.key : null; - const extensions = this.props.fileFormats.map(format => format.split("/")[1]).join(","); + const extensions = this.getExtensions(fileFormats); if (parentId) { sf.get("GetFiles", { parentId, filter: extensions }, this.setFiles.bind(this), this.handleError.bind(this)); } else if (this.state.selectedFolder) { @@ -111,7 +157,7 @@ export default class Browse extends Component { setFolderId(result) { const selectedFolder = result.Tree.children[0].data; - const extensions = this.props.fileFormats.map(format => format.split("/")[1]).join(","); + const extensions = this.getExtensions(fileFormats); const sf = this.getServiceFramework(); sf.get("GetFiles", { parentId: selectedFolder.key, filter: extensions }, this.setFiles.bind(this), this.handleError.bind(this)); } From 7aaf4c24a36161d5f505c92d0bf4e3333a498ce3 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 18:06:00 -0400 Subject: [PATCH 05/10] Corrected some errors --- .../src/FileUpload/Browse/index.jsx | 14 ++++++++------ .../src/components/PageDetails/PageDetails.jsx | 6 +----- .../Pages.Web/src/services/pageService.js | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx index bfa9b4719ca..8e7afbc46d9 100644 --- a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx +++ b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx @@ -111,7 +111,7 @@ export default class Browse extends Component { "image/tiff": "tif,tiff", "image/x-icon": "ico", "image/x-ms-bmp": "bmp", - "image/xvg+xml": "svg", + "image/svg+xml": "svg", "image/webp": "webp", "application/msword": "doc", "application/pdf": "pdf", @@ -129,23 +129,25 @@ export default class Browse extends Component { "video/x-ms-wmv": "wmv", "video/x-msvideo": "avi", "video/mp4": "m4v,mp4", - } + }; fileFormats.map(fileFormat => { if (extensions[fileFormat]) { - results += extensions[fileFormat] + ','; + results += extensions[fileFormat] + ","; } else { - result += fileFormat.split('/')[1] + ','; + result += fileFormat.split("/")[1] + ","; } }); + console.log("getExtensions called with: ", fileFormats); + console.log("getExtensions returning: ", result); return result; } getFiles() { const sf = this.getServiceFramework(); let parentId = this.state.selectedFolder ? this.state.selectedFolder.key : null; - const extensions = this.getExtensions(fileFormats); + const extensions = this.getExtensions(this.props.fileFormats); if (parentId) { sf.get("GetFiles", { parentId, filter: extensions }, this.setFiles.bind(this), this.handleError.bind(this)); } else if (this.state.selectedFolder) { @@ -157,7 +159,7 @@ export default class Browse extends Component { setFolderId(result) { const selectedFolder = result.Tree.children[0].data; - const extensions = this.getExtensions(fileFormats); + const extensions = this.getExtensions(this.props.fileFormats); const sf = this.getServiceFramework(); sf.get("GetFiles", { parentId: selectedFolder.key, filter: extensions }, this.setFiles.bind(this), this.handleError.bind(this)); } diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx index 8e6a10a68da..a89131634d4 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/components/PageDetails/PageDetails.jsx @@ -5,7 +5,6 @@ import PageStandard from "./PageStandard/PageStandard"; import PageUrl from "./PageUrl/PageUrl"; import PageDetailsFooter from "./PageDetailsFooter/PageDetailsFooter"; import PageIcons from "./PageIcons/PageIcons"; -import { propTypes } from "react-widgets/lib/selectlist"; class PageDetail extends Component { @@ -24,12 +23,10 @@ class PageDetail extends Component { render() { const DetailComponent = this.getDetail(this.props.page.pageType); - - return (
- +
); @@ -38,7 +35,6 @@ class PageDetail extends Component { PageDetail.propTypes = { page: PropTypes.object.isRequired, - validationCode: propTypes.string.isRequired, errors: PropTypes.object.isRequired, onChangeField: PropTypes.func.isRequired, components: PropTypes.array.isRequired, diff --git a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js index 71a89462944..8d086eeb23f 100644 --- a/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js +++ b/Dnn.AdminExperience/ClientSide/Pages.Web/src/services/pageService.js @@ -119,7 +119,7 @@ const PageService = function () { return { ...pageResult.page, schedulingEnabled: pageResult.page.startDate || pageResult.page.endDate, - validationCode: pageResult.page.ValidationCode, + validationCode: pageResult.ValidationCode, }; }; From 30a9c503039cbb4d1f2ae09e0fd662d0e7cc413d Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 18:52:19 -0400 Subject: [PATCH 06/10] Fixed one more typo --- .../Dnn.React.Common/src/FileUpload/Browse/index.jsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx index 8e7afbc46d9..d613ac7b214 100644 --- a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx +++ b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx @@ -98,8 +98,8 @@ export default class Browse extends Component { getExtensions(fileFormats) { let result = ""; - - const extenstions = { + + const extensions = { "text/html": "htm,html", "text/css": "css", "text/xml": "xml", @@ -139,8 +139,6 @@ export default class Browse extends Component { result += fileFormat.split("/")[1] + ","; } }); - console.log("getExtensions called with: ", fileFormats); - console.log("getExtensions returning: ", result); return result; } From 9b2ac5d78e30475bbaf4c0a7f93f2cc13152fde7 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 19:33:24 -0400 Subject: [PATCH 07/10] Fixed one more typo --- .../ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx index d613ac7b214..f054889884b 100644 --- a/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx +++ b/Dnn.AdminExperience/ClientSide/Dnn.React.Common/src/FileUpload/Browse/index.jsx @@ -133,7 +133,7 @@ export default class Browse extends Component { fileFormats.map(fileFormat => { if (extensions[fileFormat]) { - results += extensions[fileFormat] + ","; + result += extensions[fileFormat] + ","; } else { result += fileFormat.split("/")[1] + ","; From 85224398053d28ffa772e1858ade0e8614bb09be Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 20:20:58 -0400 Subject: [PATCH 08/10] Update Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs Co-authored-by: David Poindexter --- .../Services/PagesController.cs | 2676 ++++++++--------- 1 file changed, 1338 insertions(+), 1338 deletions(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs index d29db2cfd45..af0efd89d1d 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs @@ -2,653 +2,653 @@ // 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.Pages.Services -{ - using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Web.Http; - - using Dnn.PersonaBar.Library; - using Dnn.PersonaBar.Library.Attributes; - using Dnn.PersonaBar.Library.DTO.Tabs; - using Dnn.PersonaBar.Pages.Components; - using Dnn.PersonaBar.Pages.Components.Dto; - using Dnn.PersonaBar.Pages.Components.Exceptions; - using Dnn.PersonaBar.Pages.Components.Security; - using Dnn.PersonaBar.Pages.Services.Dto; - using Dnn.PersonaBar.Themes.Components; - using Dnn.PersonaBar.Themes.Components.DTO; - using DotNetNuke.Abstractions; - using DotNetNuke.Common; - using DotNetNuke.Common.Utilities; - using DotNetNuke.Entities.Modules; - using DotNetNuke.Entities.Portals; - using DotNetNuke.Entities.Tabs; - using DotNetNuke.Entities.Tabs.TabVersions; - using DotNetNuke.Entities.Users; - using DotNetNuke.Instrumentation; - using DotNetNuke.Security.Permissions; - using DotNetNuke.Services.Localization; - using DotNetNuke.Services.OutputCache; - using DotNetNuke.Services.Social.Notifications; +namespace Dnn.PersonaBar.Pages.Services +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Web.Http; + + using Dnn.PersonaBar.Library; + using Dnn.PersonaBar.Library.Attributes; + using Dnn.PersonaBar.Library.DTO.Tabs; + using Dnn.PersonaBar.Pages.Components; + using Dnn.PersonaBar.Pages.Components.Dto; + using Dnn.PersonaBar.Pages.Components.Exceptions; + using Dnn.PersonaBar.Pages.Components.Security; + using Dnn.PersonaBar.Pages.Services.Dto; + using Dnn.PersonaBar.Themes.Components; + using Dnn.PersonaBar.Themes.Components.DTO; + using DotNetNuke.Abstractions; + using DotNetNuke.Common; + using DotNetNuke.Common.Utilities; + using DotNetNuke.Entities.Modules; + using DotNetNuke.Entities.Portals; + using DotNetNuke.Entities.Tabs; + using DotNetNuke.Entities.Tabs.TabVersions; + using DotNetNuke.Entities.Users; + using DotNetNuke.Instrumentation; + using DotNetNuke.Security.Permissions; + using DotNetNuke.Services.Localization; + using DotNetNuke.Services.OutputCache; + using DotNetNuke.Services.Social.Notifications; using DotNetNuke.Web.Api; using DotNetNuke.Web.UI.WebControls; - using Localization = Dnn.PersonaBar.Pages.Components.Localization; + using Localization = Dnn.PersonaBar.Pages.Components.Localization; /// /// API controller for the Pages persona bar module. /// - [MenuPermission(MenuName = "Dnn.Pages")] - [DnnExceptionFilter] - public class PagesController : PersonaBarApiController - { - private const string LocalResourceFile = Library.Constants.PersonaBarRelativePath + "Modules/Dnn.Pages/App_LocalResources/Pages.resx"; - private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(PagesController)); - private readonly IPagesController pagesController; - - private readonly IBulkPagesController bulkPagesController; - private readonly IThemesController themesController; - private readonly ITemplateController templateController; - private readonly IDefaultPortalThemeController defaultPortalThemeController; - - private readonly ITabController tabController; - private readonly ILocaleController localeController; + [MenuPermission(MenuName = "Dnn.Pages")] + [DnnExceptionFilter] + public class PagesController : PersonaBarApiController + { + private const string LocalResourceFile = Library.Constants.PersonaBarRelativePath + "Modules/Dnn.Pages/App_LocalResources/Pages.resx"; + private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(PagesController)); + private readonly IPagesController pagesController; + + private readonly IBulkPagesController bulkPagesController; + private readonly IThemesController themesController; + private readonly ITemplateController templateController; + private readonly IDefaultPortalThemeController defaultPortalThemeController; + + private readonly ITabController tabController; + private readonly ILocaleController localeController; private readonly ISecurityService securityService; /// /// Initializes a new instance of the class. /// /// the navigation manager to provide navigation features. - public PagesController(INavigationManager navigationManager) - { - this.NavigationManager = navigationManager; - - this.pagesController = Components.PagesController.Instance; - this.themesController = ThemesController.Instance; - this.bulkPagesController = BulkPagesController.Instance; - this.templateController = TemplateController.Instance; - this.defaultPortalThemeController = DefaultPortalThemeController.Instance; - - this.tabController = TabController.Instance; - this.localeController = LocaleController.Instance; - this.securityService = SecurityService.Instance; - } - + public PagesController(INavigationManager navigationManager) + { + this.NavigationManager = navigationManager; + + this.pagesController = Components.PagesController.Instance; + this.themesController = ThemesController.Instance; + this.bulkPagesController = BulkPagesController.Instance; + this.templateController = TemplateController.Instance; + this.defaultPortalThemeController = DefaultPortalThemeController.Instance; + + this.tabController = TabController.Instance; + this.localeController = LocaleController.Instance; + this.securityService = SecurityService.Instance; + } + /// /// Gets the Navigation Manager that provides navigation features. /// - protected INavigationManager NavigationManager { get; } - - /// GET: api/Pages/GetPageDetails - /// - /// Get detail of a page. - /// - /// The page (tab) id. - /// The page details. - [HttpGet] - public HttpResponseMessage GetPageDetails(int pageId) - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - try - { - var page = this.pagesController.GetPageSettings(pageId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { page, new DnnFileUploadOptions().ValidationCode }); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Page doesn't exists." }); - } - } - - /// GET: api/Pages/GetCustomUrls - /// - /// Get custom Urls of a page. - /// - /// The page (tab) id. - /// A list of custom urls. - [HttpGet] - public HttpResponseMessage GetCustomUrls(int pageId) - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - return this.Request.CreateResponse(HttpStatusCode.OK, this.pagesController.GetPageUrls(pageId)); - } - + protected INavigationManager NavigationManager { get; } + + /// GET: api/Pages/GetPageDetails + /// + /// Get detail of a page. + /// + /// The page (tab) id. + /// The page details. + [HttpGet] + public HttpResponseMessage GetPageDetails(int pageId) + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + try + { + var page = this.pagesController.GetPageSettings(pageId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { page, new DnnFileUploadOptions().ValidationCode }); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Page doesn't exists." }); + } + } + + /// GET: api/Pages/GetCustomUrls + /// + /// Get custom Urls of a page. + /// + /// The page (tab) id. + /// A list of custom urls. + [HttpGet] + public HttpResponseMessage GetCustomUrls(int pageId) + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + return this.Request.CreateResponse(HttpStatusCode.OK, this.pagesController.GetPageUrls(pageId)); + } + /// /// Creates a custom url for SEO purposes. /// /// DTO. - /// Information about success or failure as well as a possible error message and a new url suggestion. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage CreateCustomUrl(SeoUrl dto) - { - if (!this.securityService.CanManagePage(dto.TabId)) - { - return this.GetForbiddenResponse(); - } - - var result = this.pagesController.CreateCustomUrl(dto); - + /// Information about success or failure as well as a possible error message and a new url suggestion. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage CreateCustomUrl(SeoUrl dto) + { + if (!this.securityService.CanManagePage(dto.TabId)) + { + return this.GetForbiddenResponse(); + } + + var result = this.pagesController.CreateCustomUrl(dto); + return this.Request.CreateResponse( - HttpStatusCode.OK, - new - { - result.Id, - result.Success, - result.ErrorMessage, - result.SuggestedUrlPath, - }); - } - + HttpStatusCode.OK, + new + { + result.Id, + result.Success, + result.ErrorMessage, + result.SuggestedUrlPath, + }); + } + /// /// Updates a custom url. /// /// DTO. - /// the id, if the call succeeded or faile, a possible error message and a possible new url suggestion. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage UpdateCustomUrl(SeoUrl dto) - { - if (!this.securityService.CanManagePage(dto.TabId)) - { - return this.GetForbiddenResponse(); - } - - var result = this.pagesController.UpdateCustomUrl(dto); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - result.Id, - result.Success, - result.ErrorMessage, - result.SuggestedUrlPath, - }); - } - + /// the id, if the call succeeded or faile, a possible error message and a possible new url suggestion. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage UpdateCustomUrl(SeoUrl dto) + { + if (!this.securityService.CanManagePage(dto.TabId)) + { + return this.GetForbiddenResponse(); + } + + var result = this.pagesController.UpdateCustomUrl(dto); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + result.Id, + result.Success, + result.ErrorMessage, + result.SuggestedUrlPath, + }); + } + /// /// Deletes a custom URL. /// /// DTO. - /// A value indicating if the call succeeded. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage DeleteCustomUrl(UrlIdDto dto) - { - if (!this.securityService.CanManagePage(dto.TabId)) - { - return this.GetForbiddenResponse(); - } - - this.pagesController.DeleteCustomUrl(dto); - - var response = new - { - Success = true, - }; - - return this.Request.CreateResponse(HttpStatusCode.OK, response); - } - - /// GET: api/Pages/GetPageList - /// - /// Gets the list of pages for a given parent page. - /// - /// The page (tab) id for the parent. - /// An optional search string. - /// A list of pages. - [HttpGet] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] - public HttpResponseMessage GetPageList(int parentId = -1, string searchKey = "") - { - var adminTabId = this.PortalSettings.AdminTabId; - var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); - var pages = from p in this.pagesController.GetPageList(this.PortalSettings, parentId, searchKey) - select Converters.ConvertToPageItem(p, tabs); - return this.Request.CreateResponse(HttpStatusCode.OK, pages); - } - - /// GET: api/Pages/SearchPages - /// - /// Searches for pages. - /// - /// The search string. - /// The type of page. - /// The page tags. - /// The publish status of the page. - /// The publish start date. - /// The publish end date. - /// The workflow id for the page. - /// What index of the pages paging to return. - /// How many pages to return per paging page. - /// Paged list of pages. - [HttpGet] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] - public HttpResponseMessage SearchPages( - string searchKey = "", - string pageType = "", - string tags = "", - string publishStatus = "All", - string publishDateStart = "", - string publishDateEnd = "", - int workflowId = -1, - int pageIndex = -1, - int pageSize = -1) - { - int totalRecords; - var adminTabId = this.PortalSettings.AdminTabId; - var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); - var pages = from p in this.pagesController.SearchPages(out totalRecords, searchKey, pageType, tags, publishStatus, publishDateStart, publishDateEnd, workflowId, pageIndex, pageSize) - select Converters.ConvertToPageItem(p, tabs); - var response = new - { - Success = true, - Results = pages, - TotalResults = totalRecords, - }; - return this.Request.CreateResponse(HttpStatusCode.OK, response); - } - + /// A value indicating if the call succeeded. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage DeleteCustomUrl(UrlIdDto dto) + { + if (!this.securityService.CanManagePage(dto.TabId)) + { + return this.GetForbiddenResponse(); + } + + this.pagesController.DeleteCustomUrl(dto); + + var response = new + { + Success = true, + }; + + return this.Request.CreateResponse(HttpStatusCode.OK, response); + } + + /// GET: api/Pages/GetPageList + /// + /// Gets the list of pages for a given parent page. + /// + /// The page (tab) id for the parent. + /// An optional search string. + /// A list of pages. + [HttpGet] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] + public HttpResponseMessage GetPageList(int parentId = -1, string searchKey = "") + { + var adminTabId = this.PortalSettings.AdminTabId; + var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); + var pages = from p in this.pagesController.GetPageList(this.PortalSettings, parentId, searchKey) + select Converters.ConvertToPageItem(p, tabs); + return this.Request.CreateResponse(HttpStatusCode.OK, pages); + } + + /// GET: api/Pages/SearchPages + /// + /// Searches for pages. + /// + /// The search string. + /// The type of page. + /// The page tags. + /// The publish status of the page. + /// The publish start date. + /// The publish end date. + /// The workflow id for the page. + /// What index of the pages paging to return. + /// How many pages to return per paging page. + /// Paged list of pages. + [HttpGet] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "VIEW_PAGE_LIST,VIEW")] + public HttpResponseMessage SearchPages( + string searchKey = "", + string pageType = "", + string tags = "", + string publishStatus = "All", + string publishDateStart = "", + string publishDateEnd = "", + int workflowId = -1, + int pageIndex = -1, + int pageSize = -1) + { + int totalRecords; + var adminTabId = this.PortalSettings.AdminTabId; + var tabs = TabController.GetPortalTabs(this.PortalSettings.PortalId, adminTabId, false, true, false, true); + var pages = from p in this.pagesController.SearchPages(out totalRecords, searchKey, pageType, tags, publishStatus, publishDateStart, publishDateEnd, workflowId, pageIndex, pageSize) + select Converters.ConvertToPageItem(p, tabs); + var response = new + { + Success = true, + Results = pages, + TotalResults = totalRecords, + }; + return this.Request.CreateResponse(HttpStatusCode.OK, response); + } + /// /// Gets the pages hierarchy. /// /// The page (tab) id. - /// The page hyerarchy. - [HttpGet] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage GetPageHierarchy(int pageId) - { - try - { - var paths = this.pagesController.GetPageHierarchy(pageId); - return this.Request.CreateResponse(HttpStatusCode.OK, paths); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound); - } - } - + /// The page hyerarchy. + [HttpGet] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage GetPageHierarchy(int pageId) + { + try + { + var paths = this.pagesController.GetPageHierarchy(pageId); + return this.Request.CreateResponse(HttpStatusCode.OK, paths); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound); + } + } + /// /// Moves a page to another place in the hierarchy. /// /// DTO. - /// A status and information about the page at it's new location. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage MovePage(PageMoveRequest request) - { - if (!this.securityService.CanManagePage(request.PageId) - || !this.securityService.CanManagePage(request.ParentId) - || !this.securityService.CanManagePage(request.RelatedPageId) - || !this.securityService.CanManagePage(TabController.Instance.GetTab(request.RelatedPageId, this.PortalId)?.ParentId ?? -1)) - { - return this.GetForbiddenResponse(); - } - - try - { - var tab = this.pagesController.MovePage(request); - var tabs = TabController.GetPortalTabs( - this.PortalSettings.PortalId, - Null.NullInteger, - false, - true, - false, - true); - var pageItem = Converters.ConvertToPageItem(tab, tabs); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, Page = pageItem }); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound); - } - catch (PageException ex) - { - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Message }); - } - } - + /// A status and information about the page at it's new location. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage MovePage(PageMoveRequest request) + { + if (!this.securityService.CanManagePage(request.PageId) + || !this.securityService.CanManagePage(request.ParentId) + || !this.securityService.CanManagePage(request.RelatedPageId) + || !this.securityService.CanManagePage(TabController.Instance.GetTab(request.RelatedPageId, this.PortalId)?.ParentId ?? -1)) + { + return this.GetForbiddenResponse(); + } + + try + { + var tab = this.pagesController.MovePage(request); + var tabs = TabController.GetPortalTabs( + this.PortalSettings.PortalId, + Null.NullInteger, + false, + true, + false, + true); + var pageItem = Converters.ConvertToPageItem(tab, tabs); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0, Page = pageItem }); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound); + } + catch (PageException ex) + { + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Message }); + } + } + /// /// Deletes a page. /// /// The page to delete, DTO. /// Should the page be hard-deleted or not. - /// The status of the page deletion. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage DeletePage(PageItem page, [FromUri] bool hardDelete = false) - { - if (!this.securityService.CanDeletePage(page.Id)) - { - return this.GetForbiddenResponse(); - } - - try - { - this.pagesController.DeletePage(page, hardDelete, this.PortalSettings); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound); - } - } - + /// The status of the page deletion. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage DeletePage(PageItem page, [FromUri] bool hardDelete = false) + { + if (!this.securityService.CanDeletePage(page.Id)) + { + return this.GetForbiddenResponse(); + } + + try + { + this.pagesController.DeletePage(page, hardDelete, this.PortalSettings); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound); + } + } + /// /// Deletes a module from a page. /// /// The module to delete, DTO. - /// A status code or an error. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage DeletePageModule(PageModuleItem module) - { - if (!this.securityService.CanManagePage(module.PageId)) - { - return this.GetForbiddenResponse(); - } - - try - { - this.pagesController.DeleteTabModule(module.PageId, module.ModuleId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); - } - catch (PageModuleNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound); - } - } - + /// A status code or an error. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage DeletePageModule(PageModuleItem module) + { + if (!this.securityService.CanManagePage(module.PageId)) + { + return this.GetForbiddenResponse(); + } + + try + { + this.pagesController.DeleteTabModule(module.PageId, module.ModuleId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); + } + catch (PageModuleNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound); + } + } + /// /// Copies the theme from a page to descendend pages. /// /// . - /// The status of the request. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage CopyThemeToDescendantPages(CopyThemeRequest copyTheme) - { - if (!this.securityService.CanManagePage(copyTheme.PageId)) - { - return this.GetForbiddenResponse(); - } - - this.pagesController.CopyThemeToDescendantPages(copyTheme.PageId, copyTheme.Theme); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); - } - + /// The status of the request. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage CopyThemeToDescendantPages(CopyThemeRequest copyTheme) + { + if (!this.securityService.CanManagePage(copyTheme.PageId)) + { + return this.GetForbiddenResponse(); + } + + this.pagesController.CopyThemeToDescendantPages(copyTheme.PageId, copyTheme.Theme); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); + } + /// /// Copies permissions from a page to the descendent pages. /// /// DTO. - /// The status of the operation. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage CopyPermissionsToDescendantPages(CopyPermissionsRequest copyPermissions) - { - if (!this.securityService.CanAdminPage(copyPermissions.PageId)) - { - return this.GetForbiddenResponse(); - } - - try - { - this.pagesController.CopyPermissionsToDescendantPages(copyPermissions.PageId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound); - } - catch (PermissionsNotMetException) - { - return this.Request.CreateResponse(HttpStatusCode.Forbidden); - } - } - + /// The status of the operation. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage CopyPermissionsToDescendantPages(CopyPermissionsRequest copyPermissions) + { + if (!this.securityService.CanAdminPage(copyPermissions.PageId)) + { + return this.GetForbiddenResponse(); + } + + try + { + this.pagesController.CopyPermissionsToDescendantPages(copyPermissions.PageId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 0 }); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound); + } + catch (PermissionsNotMetException) + { + return this.Request.CreateResponse(HttpStatusCode.Forbidden); + } + } + /// /// Sets a page in edit mode. /// /// the page (tab) id. - /// Sets a cookie for edit mode on the specified page then returns a success message. - [HttpPost] - public HttpResponseMessage EditModeForPage([FromUri] int id) - { - if (!TabPermissionController.CanAddContentToPage(TabController.Instance.GetTab(id, this.PortalId))) - { - return this.GetForbiddenResponse(); - } - - this.pagesController.EditModeForPage(id, this.UserInfo.UserID); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - + /// Sets a cookie for edit mode on the specified page then returns a success message. + [HttpPost] + public HttpResponseMessage EditModeForPage([FromUri] int id) + { + if (!TabPermissionController.CanAddContentToPage(TabController.Instance.GetTab(id, this.PortalId))) + { + return this.GetForbiddenResponse(); + } + + this.pagesController.EditModeForPage(id, this.UserInfo.UserID); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + /// /// Saves the page details. /// /// The new page settings, DTO. - /// The new page details. - [HttpPost] - [ValidateAntiForgeryToken] - public HttpResponseMessage SavePageDetails(PageSettings pageSettings) - { - if (!this.securityService.CanSavePageDetails(pageSettings)) - { - return this.GetForbiddenResponse(); - } - - try - { - pageSettings.Clean(); - var tab = this.pagesController.SavePageDetails(this.PortalSettings, pageSettings); - var tabs = TabController.GetPortalTabs( - this.PortalSettings.PortalId, - Null.NullInteger, - false, - true, - false, - true); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - Status = 0, - Page = Converters.ConvertToPageItem(tab, tabs), - }); - } - catch (PageNotFoundException) - { - return this.Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Page doesn't exists." }); - } - catch (PageValidationException ex) - { - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); - } - } - + /// The new page details. + [HttpPost] + [ValidateAntiForgeryToken] + public HttpResponseMessage SavePageDetails(PageSettings pageSettings) + { + if (!this.securityService.CanSavePageDetails(pageSettings)) + { + return this.GetForbiddenResponse(); + } + + try + { + pageSettings.Clean(); + var tab = this.pagesController.SavePageDetails(this.PortalSettings, pageSettings); + var tabs = TabController.GetPortalTabs( + this.PortalSettings.PortalId, + Null.NullInteger, + false, + true, + false, + true); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + Status = 0, + Page = Converters.ConvertToPageItem(tab, tabs), + }); + } + catch (PageNotFoundException) + { + return this.Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Page doesn't exists." }); + } + catch (PageValidationException ex) + { + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); + } + } + /// /// Gets the default page settings. /// /// The page (tab) id. - /// The page default settings. - [HttpGet] - public HttpResponseMessage GetDefaultSettings(int pageId = 0) - { - var settings = this.pagesController.GetDefaultSettings(pageId); - return this.Request.CreateResponse(HttpStatusCode.OK, settings); - } - + /// The page default settings. + [HttpGet] + public HttpResponseMessage GetDefaultSettings(int pageId = 0) + { + var settings = this.pagesController.GetDefaultSettings(pageId); + return this.Request.CreateResponse(HttpStatusCode.OK, settings); + } + /// /// Gets the list of cache providers. /// - /// List of cache providers. - [HttpGet] - public HttpResponseMessage GetCacheProviderList() - { - var providers = from p in OutputCachingProvider.GetProviderList() select p.Key; - return this.Request.CreateResponse(HttpStatusCode.OK, providers); - } - + /// List of cache providers. + [HttpGet] + public HttpResponseMessage GetCacheProviderList() + { + var providers = from p in OutputCachingProvider.GetProviderList() select p.Key; + return this.Request.CreateResponse(HttpStatusCode.OK, providers); + } + /// /// Gets the available themes. /// - /// Available themes. - [HttpGet] - public HttpResponseMessage GetThemes() - { - var themes = this.themesController.GetLayouts(this.PortalSettings, ThemeLevel.All); - - var defaultTheme = this.GetDefaultPortalTheme(); - var defaultPortalThemeName = defaultTheme?.ThemeName; - var defaultPortalThemeLevel = defaultTheme?.Level; - var defaultPortalLayout = this.defaultPortalThemeController.GetDefaultPortalLayout(); - var defaultPortalContainer = this.defaultPortalThemeController.GetDefaultPortalContainer(); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - themes, - defaultPortalThemeName, - defaultPortalThemeLevel, - defaultPortalLayout, - defaultPortalContainer, - }); - } - + /// Available themes. + [HttpGet] + public HttpResponseMessage GetThemes() + { + var themes = this.themesController.GetLayouts(this.PortalSettings, ThemeLevel.All); + + var defaultTheme = this.GetDefaultPortalTheme(); + var defaultPortalThemeName = defaultTheme?.ThemeName; + var defaultPortalThemeLevel = defaultTheme?.Level; + var defaultPortalLayout = this.defaultPortalThemeController.GetDefaultPortalLayout(); + var defaultPortalContainer = this.defaultPortalThemeController.GetDefaultPortalContainer(); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + themes, + defaultPortalThemeName, + defaultPortalThemeLevel, + defaultPortalLayout, + defaultPortalContainer, + }); + } + /// /// Gets the theme files for a given theme. /// /// The name of the theme. /// The level of the theme, . - /// Returns a list of available layouts and containers for each theme. - [HttpGet] - public HttpResponseMessage GetThemeFiles(string themeName, ThemeLevel level) - { - var themeLayout = this.themesController.GetLayouts(this.PortalSettings, level) - .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); - var themeContainer = this.themesController.GetContainers(this.PortalSettings, level) - .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - layouts = themeLayout == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeLayout), - containers = themeContainer == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeContainer), - }); - } - + /// Returns a list of available layouts and containers for each theme. + [HttpGet] + public HttpResponseMessage GetThemeFiles(string themeName, ThemeLevel level) + { + var themeLayout = this.themesController.GetLayouts(this.PortalSettings, level) + .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); + var themeContainer = this.themesController.GetContainers(this.PortalSettings, level) + .FirstOrDefault(t => t.PackageName.Equals(themeName, StringComparison.OrdinalIgnoreCase) && t.Level == level); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + layouts = themeLayout == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeLayout), + containers = themeContainer == null ? new List() : this.themesController.GetThemeFiles(this.PortalSettings, themeContainer), + }); + } + /// /// Save bulk pages (Add multiple pages). /// /// DTO. - /// A status code and the result of adding the multiple pages. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) - { - if (!this.securityService.IsPageAdminUser()) - { - return this.GetForbiddenResponse(); - } - - try - { - bulkPage.Clean(); - var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: false); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - Status = 0, - Response = bulkPageResponse, - }); - } - catch (PageValidationException ex) - { - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); - } - } - + /// A status code and the result of adding the multiple pages. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage SaveBulkPages(BulkPage bulkPage) + { + if (!this.securityService.IsPageAdminUser()) + { + return this.GetForbiddenResponse(); + } + + try + { + bulkPage.Clean(); + var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: false); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + Status = 0, + Response = bulkPageResponse, + }); + } + catch (PageValidationException ex) + { + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); + } + } + /// /// Validates if bulk pages (Add multiple pages) information is valid. /// /// DTO. - /// A status code and the result of the bulk pages check. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage PreSaveBulkPagesValidate(BulkPage bulkPage) - { - if (!this.securityService.IsPageAdminUser()) - { - return this.GetForbiddenResponse(); - } - - try - { - bulkPage.Clean(); - var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: true); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - Status = 0, - Response = bulkPageResponse, - }); - } - catch (PageValidationException ex) - { - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); - } - } - + /// A status code and the result of the bulk pages check. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage PreSaveBulkPagesValidate(BulkPage bulkPage) + { + if (!this.securityService.IsPageAdminUser()) + { + return this.GetForbiddenResponse(); + } + + try + { + bulkPage.Clean(); + var bulkPageResponse = this.bulkPagesController.AddBulkPages(bulkPage, validateOnly: true); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + Status = 0, + Response = bulkPageResponse, + }); + } + catch (PageValidationException ex) + { + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Field, ex.Message }); + } + } + /// /// Saves a page as a template. /// /// DTO. - /// The status of the operation with a possible error message. - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) - { - if (!this.securityService.CanExportPage(pageTemplate.TabId)) - { - return this.GetForbiddenResponse(); - } - - try - { - pageTemplate.Clean(); - var templateFilename = this.templateController.SaveAsTemplate(pageTemplate); - var response = string.Format(Localization.GetString("ExportedMessage"), templateFilename); - - return this.Request.CreateResponse(HttpStatusCode.OK, new - { - Status = 0, - Response = response, - }); - } - catch (TemplateException ex) - { - return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Message }); - } + /// The status of the operation with a possible error message. + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) + { + if (!this.securityService.CanExportPage(pageTemplate.TabId)) + { + return this.GetForbiddenResponse(); + } + + try + { + pageTemplate.Clean(); + var templateFilename = this.templateController.SaveAsTemplate(pageTemplate); + var response = string.Format(Localization.GetString("ExportedMessage"), templateFilename); + + return this.Request.CreateResponse(HttpStatusCode.OK, new + { + Status = 0, + Response = response, + }); + } + catch (TemplateException ex) + { + return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Message }); + } } /// @@ -657,629 +657,629 @@ public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate) /// The page (tab) id. /// A success status or an exception. /// POST /api/personabar/pages/MakePageNeutral?tabId=123 . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage MakePageNeutral([FromUri] int pageId) - { - try - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - if (this.tabController.GetTabsByPortal(this.PortalId).WithParentId(pageId).Count > 0) - { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("MakeNeutral.ErrorMessage")); - } - - var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); - this.tabController.ConvertTabToNeutralLanguage(this.PortalId, pageId, defaultLocale.Code, true); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to make this page neureal, please consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage MakePageNeutral([FromUri] int pageId) + { + try + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + if (this.tabController.GetTabsByPortal(this.PortalId).WithParentId(pageId).Count > 0) + { + return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("MakeNeutral.ErrorMessage")); + } + + var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); + this.tabController.ConvertTabToNeutralLanguage(this.PortalId, pageId, defaultLocale.Code, true); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occurred while trying to make this page neutral, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Makes a neutral page localizable. /// /// the page (tab) id. - /// A status code or an error message. - /// POST /api/personabar/pages/MakePageTranslatable?tabId=123 . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage MakePageTranslatable([FromUri] int pageId) - { - try - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); - if (currentTab == null) - { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTab"); - } - - var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); - this.tabController.LocalizeTab(currentTab, defaultLocale, true); - this.tabController.AddMissingLanguages(this.PortalId, pageId); - this.tabController.ClearCache(this.PortalId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to make this page translatable."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A status code or an error message. + /// POST /api/personabar/pages/MakePageTranslatable?tabId=123 . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage MakePageTranslatable([FromUri] int pageId) + { + try + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); + if (currentTab == null) + { + return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTab"); + } + + var defaultLocale = this.localeController.GetDefaultLocale(this.PortalId); + this.tabController.LocalizeTab(currentTab, defaultLocale, true); + this.tabController.AddMissingLanguages(this.PortalId, pageId); + this.tabController.ClearCache(this.PortalId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to make this page translatable."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Adds all missing languages to a page. /// /// The page (tab) id. - /// A status code or an exception message. - /// POST /api/personabar/pages/AddMissingLanguages?tabId=123 . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage AddMissingLanguages([FromUri] int pageId) - { - try - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - this.tabController.AddMissingLanguages(this.PortalId, pageId); - this.tabController.ClearCache(this.PortalId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to add missing languages to this page, consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A status code or an exception message. + /// POST /api/personabar/pages/AddMissingLanguages?tabId=123 . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage AddMissingLanguages([FromUri] int pageId) + { + try + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + this.tabController.AddMissingLanguages(this.PortalId, pageId); + this.tabController.ClearCache(this.PortalId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to add missing languages to this page, consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Notifies the translators with a comment. /// /// DTO. - /// A status code and a message. - /// POST /api/personabar/pages/NotifyTranslators . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage NotifyTranslators(TranslatorsComment comment) - { - try - { - if (!this.securityService.CanManagePage(comment.TabId)) - { - return this.GetForbiddenResponse(); - } - - // loop through all localized version of this page - var currentTab = this.tabController.GetTab(comment.TabId, this.PortalId, false); - foreach (var localizedTab in currentTab.LocalizedTabs.Values) - { - var users = new Dictionary(); - - // Give default translators for this language and administrators permissions - this.tabController.GiveTranslatorRoleEditRights(localizedTab, users); - - // Send Messages to all the translators of new content - foreach (var translator in users.Values.Where(user => user.UserID != this.PortalSettings.AdministratorId)) - { - this.AddTranslationSubmittedNotification(localizedTab, translator, comment.Text); - } - } - - var msgToUser = LocalizeString("TranslationMessageConfirmMessage.Text"); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Message = msgToUser }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to notify the translators, please consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - - /// - /// Gets the view data that used to be in the old ControlBar's localization tab - /// under Page Settings ( /{page}/ctl/Tab/action/edit/activeTab/settingTab ). - /// - /// The ID of the tab to get localization for. - /// Information about localiz. - /// /api/personabar/pages/GetTabLocalization?pageId=123. - [HttpGet] - public HttpResponseMessage GetTabLocalization(int pageId) - { - try - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); - var locales = new List(); - var pages = new DnnPagesDto(locales); - if (!currentTab.IsNeutralCulture) - { - pages = this.GetNonLocalizedPages(pageId); - } - - return this.Request.CreateResponse(HttpStatusCode.OK, pages); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured trying to get this page localization, consolt the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A status code and a message. + /// POST /api/personabar/pages/NotifyTranslators . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage NotifyTranslators(TranslatorsComment comment) + { + try + { + if (!this.securityService.CanManagePage(comment.TabId)) + { + return this.GetForbiddenResponse(); + } + + // loop through all localized version of this page + var currentTab = this.tabController.GetTab(comment.TabId, this.PortalId, false); + foreach (var localizedTab in currentTab.LocalizedTabs.Values) + { + var users = new Dictionary(); + + // Give default translators for this language and administrators permissions + this.tabController.GiveTranslatorRoleEditRights(localizedTab, users); + + // Send Messages to all the translators of new content + foreach (var translator in users.Values.Where(user => user.UserID != this.PortalSettings.AdministratorId)) + { + this.AddTranslationSubmittedNotification(localizedTab, translator, comment.Text); + } + } + + var msgToUser = LocalizeString("TranslationMessageConfirmMessage.Text"); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Message = msgToUser }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to notify the translators, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + + /// + /// Gets the view data that used to be in the old ControlBar's localization tab + /// under Page Settings ( /{page}/ctl/Tab/action/edit/activeTab/settingTab ). + /// + /// The ID of the tab to get localization for. + /// Information about localiz. + /// /api/personabar/pages/GetTabLocalization?pageId=123. + [HttpGet] + public HttpResponseMessage GetTabLocalization(int pageId) + { + try + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + var currentTab = this.tabController.GetTab(pageId, this.PortalId, false); + var locales = new List(); + var pages = new DnnPagesDto(locales); + if (!currentTab.IsNeutralCulture) + { + pages = this.GetNonLocalizedPages(pageId); + } + + return this.Request.CreateResponse(HttpStatusCode.OK, pages); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured trying to get this page localization, consolt the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Updates the page (tab) localization. /// /// DTO. - /// A status code or an exception message. - /// POST /api/personabar/pages/UpdateTabLocalization . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage UpdateTabLocalization(DnnPagesRequest request) - { - try - { - if (request.Pages.Any(x => x.TabId > 0 && !this.securityService.CanManagePage(x.TabId))) - { - return this.GetForbiddenResponse(); - } - - this.SaveNonLocalizedPages(request); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured trying to update the page localization, please consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A status code or an exception message. + /// POST /api/personabar/pages/UpdateTabLocalization . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage UpdateTabLocalization(DnnPagesRequest request) + { + try + { + if (request.Pages.Any(x => x.TabId > 0 && !this.securityService.CanManagePage(x.TabId))) + { + return this.GetForbiddenResponse(); + } + + this.SaveNonLocalizedPages(request); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured trying to update the page localization, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Restores a deleted module on a page (tab). /// /// The TabModule id. - /// A success message or an exception message. - /// POST /api/personabar/pages/RestoreModule?tabModuleId=123 . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage RestoreModule(int tabModuleId) - { - try - { - var module = ModuleController.Instance.GetTabModule(tabModuleId); - if (!this.securityService.CanManagePage(module.TabID)) - { - return this.GetForbiddenResponse(); - } - - var moduleController = ModuleController.Instance; - var moduleInfo = moduleController.GetTabModule(tabModuleId); - if (moduleInfo == null) - { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTabModule"); - } - - moduleController.RestoreModule(moduleInfo); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to restore the module onto that page."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A success message or an exception message. + /// POST /api/personabar/pages/RestoreModule?tabModuleId=123 . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage RestoreModule(int tabModuleId) + { + try + { + var module = ModuleController.Instance.GetTabModule(tabModuleId); + if (!this.securityService.CanManagePage(module.TabID)) + { + return this.GetForbiddenResponse(); + } + + var moduleController = ModuleController.Instance; + var moduleInfo = moduleController.GetTabModule(tabModuleId); + if (moduleInfo == null) + { + return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTabModule"); + } + + moduleController.RestoreModule(moduleInfo); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to restore the module onto that page."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Deletes a module from a page (tab). /// /// The TabModuleId. - /// A status message or an error message. - /// POST /api/personabar/pages/DeleteModule?tabModuleId=123 . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage DeleteModule(int tabModuleId) - { - try - { - var module = ModuleController.Instance.GetTabModule(tabModuleId); - if (!this.securityService.CanManagePage(module.TabID)) - { - return this.GetForbiddenResponse(); - } - - var moduleController = ModuleController.Instance; - var moduleInfo = moduleController.GetTabModule(tabModuleId); - if (moduleInfo == null) - { - return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTabModule"); - } - - moduleController.DeleteTabModule(moduleInfo.TabID, moduleInfo.ModuleID, false); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to delete the module, consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - - /// - /// Gets ContentLocalizationEnabled. - /// - /// A value indicating if content localization is enabled. - /// GET /api/personabar/pages/GetContentLocalizationEnabled. - [HttpGet] - public HttpResponseMessage GetContentLocalizationEnabled() - { - try - { - if (!TabPermissionController.CanManagePage()) - { - return this.GetForbiddenResponse(); - } - - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, this.PortalSettings.ContentLocalizationEnabled }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured while trying to find if content localization is enabled"; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - - /// - /// Gets GetCachedItemCount. - /// - /// The cache profider. - /// The page (tab) id. - /// Caching information. - /// GET /api/personabar/pages/GetCachedItemCount. - [HttpGet] - public HttpResponseMessage GetCachedItemCount(string cacheProvider, int pageId) - { - try - { - if (!TabPermissionController.CanManagePage()) - { - return this.GetForbiddenResponse(); - } - - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Count = OutputCachingProvider.Instance(cacheProvider).GetItemCount(pageId) }); - } - catch (Exception ex) - { - var errorMessage = "An unexpected error occured trying to get the cached items count, please consult the logs for more details."; - Logger.Error(errorMessage, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); - } - } - + /// A status message or an error message. + /// POST /api/personabar/pages/DeleteModule?tabModuleId=123 . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage DeleteModule(int tabModuleId) + { + try + { + var module = ModuleController.Instance.GetTabModule(tabModuleId); + if (!this.securityService.CanManagePage(module.TabID)) + { + return this.GetForbiddenResponse(); + } + + var moduleController = ModuleController.Instance; + var moduleInfo = moduleController.GetTabModule(tabModuleId); + if (moduleInfo == null) + { + return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InvalidTabModule"); + } + + moduleController.DeleteTabModule(moduleInfo.TabID, moduleInfo.ModuleID, false); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to delete the module, consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + + /// + /// Gets ContentLocalizationEnabled. + /// + /// A value indicating if content localization is enabled. + /// GET /api/personabar/pages/GetContentLocalizationEnabled. + [HttpGet] + public HttpResponseMessage GetContentLocalizationEnabled() + { + try + { + if (!TabPermissionController.CanManagePage()) + { + return this.GetForbiddenResponse(); + } + + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, this.PortalSettings.ContentLocalizationEnabled }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured while trying to find if content localization is enabled"; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + + /// + /// Gets GetCachedItemCount. + /// + /// The cache profider. + /// The page (tab) id. + /// Caching information. + /// GET /api/personabar/pages/GetCachedItemCount. + [HttpGet] + public HttpResponseMessage GetCachedItemCount(string cacheProvider, int pageId) + { + try + { + if (!TabPermissionController.CanManagePage()) + { + return this.GetForbiddenResponse(); + } + + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Count = OutputCachingProvider.Instance(cacheProvider).GetItemCount(pageId) }); + } + catch (Exception ex) + { + var errorMessage = "An unexpected error occured trying to get the cached items count, please consult the logs for more details."; + Logger.Error(errorMessage, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); + } + } + /// /// Clears the page cache for a given page. /// /// The cache provider to clear the cache for. /// The page (tab) id. - /// A status code or an error message. - /// POST /api/personabar/pages/ClearCache . - [HttpPost] - [ValidateAntiForgeryToken] - [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] - public HttpResponseMessage ClearCache([FromUri] string cacheProvider, [FromUri] int pageId) - { - try - { - if (!this.securityService.CanManagePage(pageId)) - { - return this.GetForbiddenResponse(); - } - - OutputCachingProvider.Instance(cacheProvider).Remove(pageId); - return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); - } - catch (Exception ex) - { - var message = "An unexpected error occured while trying to clear the cache for this page, see logs for more details."; - Logger.Error(message, ex); - return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message); - } + /// A status code or an error message. + /// POST /api/personabar/pages/ClearCache . + [HttpPost] + [ValidateAntiForgeryToken] + [AdvancedPermission(MenuName = "Dnn.Pages", Permission = "Edit")] + public HttpResponseMessage ClearCache([FromUri] string cacheProvider, [FromUri] int pageId) + { + try + { + if (!this.securityService.CanManagePage(pageId)) + { + return this.GetForbiddenResponse(); + } + + OutputCachingProvider.Instance(cacheProvider).Remove(pageId); + return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); + } + catch (Exception ex) + { + var message = "An unexpected error occured while trying to clear the cache for this page, see logs for more details."; + Logger.Error(message, ex); + return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message); + } } - private static string LocalizeString(string key) - { - return DotNetNuke.Services.Localization.Localization.GetString(key, LocalResourceFile); - } - - private static void EnableTabVersioningAndWorkflow(TabInfo tab) - { - var tabVersionSettings = TabVersionSettings.Instance; - var tabWorkflowSettings = TabWorkflowSettings.Instance; - - if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) - { - tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, true); - } - - if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) - { - tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, true); - } + private static string LocalizeString(string key) + { + return DotNetNuke.Services.Localization.Localization.GetString(key, LocalResourceFile); } - private static void DisableTabVersioningAndWorkflow(TabInfo tab) - { - var tabVersionSettings = TabVersionSettings.Instance; - var tabWorkflowSettings = TabWorkflowSettings.Instance; - - if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) - { - tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, false); - } - - if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) - { - tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, false); - } - } - - private DnnPagesDto GetNonLocalizedPages(int tabId) - { - var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); - - // Unique id of default language page - var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid - ? currentTab.DefaultLanguageGuid - : currentTab.UniqueId; - - // get all non admin pages and not deleted - var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( - t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); - allPages = allPages.Where(t => t.IsDeleted == false); - - // get all localized pages of current page - var tabInfos = allPages as IList ?? allPages.ToList(); - var localizedPages = tabInfos.Where( - t => t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId).OrderBy(t => t.DefaultLanguageGuid).ToList(); - Dictionary localizedTabs = null; - - // we are going to build up a list of locales - // this is a bit more involved, since we want the default language to be first. - // also, we do not want to add any locales the user has no access to - var locales = new List(); - var localeController = new LocaleController(); - var localeDict = localeController.GetLocales(this.PortalId); - if (localeDict.Count == 0) - { - locales.Add(new LocaleInfoDto(string.Empty)); - } - else - { - if (localizedPages.Count == 1 && localizedPages.First().CultureCode == string.Empty) - { - // locale neutral page - locales.Add(new LocaleInfoDto(string.Empty)); - } - else if (localizedPages.Count == 1 && localizedPages.First().CultureCode != this.PortalSettings.DefaultLanguage) - { - var first = localizedPages.First(); - locales.Add(new LocaleInfoDto(first.CultureCode)); - } - else - { - // force sort order, so first add default language - locales.Add(new LocaleInfoDto(this.PortalSettings.DefaultLanguage)); - - // build up a list of localized tabs. - // depending on whether or not the selected page is in the default langauge - // we will add the localized tabs from the current page - // or from the defaultlanguage page - if (currentTab.CultureCode == this.PortalSettings.DefaultLanguage) - { - localizedTabs = currentTab.LocalizedTabs; - } - else - { - // selected page is not in default language - // add localizedtabs from defaultlanguage page - if (currentTab.DefaultLanguageTab != null) - { - localizedTabs = currentTab.DefaultLanguageTab.LocalizedTabs; - } - } - - if (localizedTabs != null) - { - // only add locales from tabs the user has at least view permissions to. - // we will handle the edit permissions at a later stage - locales.AddRange( - from localizedTab in localizedTabs - where TabPermissionController.CanViewPage(localizedTab.Value) - select new LocaleInfoDto(localizedTab.Value.CultureCode)); - } - } - } - - var dnnPages = new DnnPagesDto(locales) - { - HasMissingLanguages = this.tabController.HasMissingLanguages(this.PortalId, tabId), - }; - - // filter the list of localized pages to only those that have a culture we want to see - var viewableLocalizedPages = localizedPages.Where( - localizedPage => locales.Find(locale => locale.CultureCode == localizedPage.CultureCode) != null).ToList(); - - foreach (var tabInfo in viewableLocalizedPages) - { - var localTabInfo = tabInfo; - var dnnPage = dnnPages.Page(localTabInfo.CultureCode); - if (!TabPermissionController.CanViewPage(tabInfo)) - { - dnnPages.RemoveLocale(localTabInfo.CultureCode); - dnnPages.Pages.Remove(dnnPage); - break; - } - - dnnPage.TabId = localTabInfo.TabID; - dnnPage.TabName = localTabInfo.TabName; - dnnPage.Title = localTabInfo.Title; - dnnPage.Description = localTabInfo.Description; - dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", string.Empty); - dnnPage.HasChildren = this.tabController.GetTabsByPortal(this.PortalId).WithParentId(tabInfo.TabID).Count != 0; - dnnPage.CanAdminPage = TabPermissionController.CanAdminPage(tabInfo); - dnnPage.CanViewPage = TabPermissionController.CanViewPage(tabInfo); - dnnPage.LocalResourceFile = LocalResourceFile; - dnnPage.PageUrl = this.NavigationManager.NavigateURL(localTabInfo.TabID, false, this.PortalSettings, string.Empty, localTabInfo.CultureCode); - dnnPage.IsSpecial = TabController.IsSpecialTab(localTabInfo.TabID, localTabInfo.PortalID); - - // calculate position in the form of 1.3.2... - var siblingTabs = tabInfos.Where(t => (t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); - dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture); - var parentTabId = localTabInfo.ParentId; - while (parentTabId > 0) - { - var parentTab = tabInfos.Single(t => t.TabID == parentTabId); - var id = parentTabId; - siblingTabs = tabInfos.Where(t => (t.ParentId == id && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); - dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position; - parentTabId = parentTab.ParentId; - } - - dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid; - dnnPage.IsTranslated = localTabInfo.IsTranslated; - dnnPage.IsPublished = this.tabController.IsTabPublished(localTabInfo); - - // generate modules information - var moduleController = ModuleController.Instance; - foreach (var moduleInfo in moduleController.GetTabModules(localTabInfo.TabID).Values) - { - var guid = moduleInfo.DefaultLanguageGuid == Null.NullGuid ? moduleInfo.UniqueId : moduleInfo.DefaultLanguageGuid; - - var dnnModules = dnnPages.Module(guid); // modules of each language - var dnnModule = dnnModules.Module(localTabInfo.CultureCode); - - // detect error : 2 modules with same uniqueId on the same page - dnnModule.LocalResourceFile = LocalResourceFile; - if (dnnModule.TabModuleId > 0) - { - dnnModule.ErrorDuplicateModule = true; - dnnPages.ErrorExists = true; - continue; - } - - dnnModule.ModuleTitle = moduleInfo.ModuleTitle; - dnnModule.DefaultLanguageGuid = moduleInfo.DefaultLanguageGuid; - dnnModule.TabId = localTabInfo.TabID; - dnnModule.TabModuleId = moduleInfo.TabModuleID; - dnnModule.ModuleId = moduleInfo.ModuleID; - dnnModule.CanAdminModule = ModulePermissionController.CanAdminModule(moduleInfo); - dnnModule.CanViewModule = ModulePermissionController.CanViewModule(moduleInfo); - dnnModule.IsDeleted = moduleInfo.IsDeleted; - if (moduleInfo.DefaultLanguageGuid != Null.NullGuid) - { - var defaultLanguageModule = moduleController.GetModuleByUniqueID(moduleInfo.DefaultLanguageGuid); - if (defaultLanguageModule != null) - { - dnnModule.DefaultModuleId = defaultLanguageModule.ModuleID; + private static void EnableTabVersioningAndWorkflow(TabInfo tab) + { + var tabVersionSettings = TabVersionSettings.Instance; + var tabWorkflowSettings = TabWorkflowSettings.Instance; + + if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) + { + tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, true); + } + + if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) + { + tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, true); + } + } + + private static void DisableTabVersioningAndWorkflow(TabInfo tab) + { + var tabVersionSettings = TabVersionSettings.Instance; + var tabWorkflowSettings = TabWorkflowSettings.Instance; + + if (tabVersionSettings.IsVersioningEnabled(tab.PortalID)) + { + tabVersionSettings.SetEnabledVersioningForTab(tab.TabID, false); + } + + if (tabWorkflowSettings.IsWorkflowEnabled(tab.PortalID)) + { + tabWorkflowSettings.SetWorkflowEnabled(tab.PortalID, tab.TabID, false); + } + } + + private DnnPagesDto GetNonLocalizedPages(int tabId) + { + var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); + + // Unique id of default language page + var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid + ? currentTab.DefaultLanguageGuid + : currentTab.UniqueId; + + // get all non admin pages and not deleted + var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( + t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); + allPages = allPages.Where(t => t.IsDeleted == false); + + // get all localized pages of current page + var tabInfos = allPages as IList ?? allPages.ToList(); + var localizedPages = tabInfos.Where( + t => t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId).OrderBy(t => t.DefaultLanguageGuid).ToList(); + Dictionary localizedTabs = null; + + // we are going to build up a list of locales + // this is a bit more involved, since we want the default language to be first. + // also, we do not want to add any locales the user has no access to + var locales = new List(); + var localeController = new LocaleController(); + var localeDict = localeController.GetLocales(this.PortalId); + if (localeDict.Count == 0) + { + locales.Add(new LocaleInfoDto(string.Empty)); + } + else + { + if (localizedPages.Count == 1 && localizedPages.First().CultureCode == string.Empty) + { + // locale neutral page + locales.Add(new LocaleInfoDto(string.Empty)); + } + else if (localizedPages.Count == 1 && localizedPages.First().CultureCode != this.PortalSettings.DefaultLanguage) + { + var first = localizedPages.First(); + locales.Add(new LocaleInfoDto(first.CultureCode)); + } + else + { + // force sort order, so first add default language + locales.Add(new LocaleInfoDto(this.PortalSettings.DefaultLanguage)); + + // build up a list of localized tabs. + // depending on whether or not the selected page is in the default langauge + // we will add the localized tabs from the current page + // or from the defaultlanguage page + if (currentTab.CultureCode == this.PortalSettings.DefaultLanguage) + { + localizedTabs = currentTab.LocalizedTabs; + } + else + { + // selected page is not in default language + // add localizedtabs from defaultlanguage page + if (currentTab.DefaultLanguageTab != null) + { + localizedTabs = currentTab.DefaultLanguageTab.LocalizedTabs; + } + } + + if (localizedTabs != null) + { + // only add locales from tabs the user has at least view permissions to. + // we will handle the edit permissions at a later stage + locales.AddRange( + from localizedTab in localizedTabs + where TabPermissionController.CanViewPage(localizedTab.Value) + select new LocaleInfoDto(localizedTab.Value.CultureCode)); + } + } + } + + var dnnPages = new DnnPagesDto(locales) + { + HasMissingLanguages = this.tabController.HasMissingLanguages(this.PortalId, tabId), + }; + + // filter the list of localized pages to only those that have a culture we want to see + var viewableLocalizedPages = localizedPages.Where( + localizedPage => locales.Find(locale => locale.CultureCode == localizedPage.CultureCode) != null).ToList(); + + foreach (var tabInfo in viewableLocalizedPages) + { + var localTabInfo = tabInfo; + var dnnPage = dnnPages.Page(localTabInfo.CultureCode); + if (!TabPermissionController.CanViewPage(tabInfo)) + { + dnnPages.RemoveLocale(localTabInfo.CultureCode); + dnnPages.Pages.Remove(dnnPage); + break; + } + + dnnPage.TabId = localTabInfo.TabID; + dnnPage.TabName = localTabInfo.TabName; + dnnPage.Title = localTabInfo.Title; + dnnPage.Description = localTabInfo.Description; + dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", string.Empty); + dnnPage.HasChildren = this.tabController.GetTabsByPortal(this.PortalId).WithParentId(tabInfo.TabID).Count != 0; + dnnPage.CanAdminPage = TabPermissionController.CanAdminPage(tabInfo); + dnnPage.CanViewPage = TabPermissionController.CanViewPage(tabInfo); + dnnPage.LocalResourceFile = LocalResourceFile; + dnnPage.PageUrl = this.NavigationManager.NavigateURL(localTabInfo.TabID, false, this.PortalSettings, string.Empty, localTabInfo.CultureCode); + dnnPage.IsSpecial = TabController.IsSpecialTab(localTabInfo.TabID, localTabInfo.PortalID); + + // calculate position in the form of 1.3.2... + var siblingTabs = tabInfos.Where(t => (t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); + dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture); + var parentTabId = localTabInfo.ParentId; + while (parentTabId > 0) + { + var parentTab = tabInfos.Single(t => t.TabID == parentTabId); + var id = parentTabId; + siblingTabs = tabInfos.Where(t => (t.ParentId == id && t.CultureCode == localTabInfo.CultureCode) || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList(); + dnnPage.Position = (siblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position; + parentTabId = parentTab.ParentId; + } + + dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid; + dnnPage.IsTranslated = localTabInfo.IsTranslated; + dnnPage.IsPublished = this.tabController.IsTabPublished(localTabInfo); + + // generate modules information + var moduleController = ModuleController.Instance; + foreach (var moduleInfo in moduleController.GetTabModules(localTabInfo.TabID).Values) + { + var guid = moduleInfo.DefaultLanguageGuid == Null.NullGuid ? moduleInfo.UniqueId : moduleInfo.DefaultLanguageGuid; + + var dnnModules = dnnPages.Module(guid); // modules of each language + var dnnModule = dnnModules.Module(localTabInfo.CultureCode); + + // detect error : 2 modules with same uniqueId on the same page + dnnModule.LocalResourceFile = LocalResourceFile; + if (dnnModule.TabModuleId > 0) + { + dnnModule.ErrorDuplicateModule = true; + dnnPages.ErrorExists = true; + continue; + } + + dnnModule.ModuleTitle = moduleInfo.ModuleTitle; + dnnModule.DefaultLanguageGuid = moduleInfo.DefaultLanguageGuid; + dnnModule.TabId = localTabInfo.TabID; + dnnModule.TabModuleId = moduleInfo.TabModuleID; + dnnModule.ModuleId = moduleInfo.ModuleID; + dnnModule.CanAdminModule = ModulePermissionController.CanAdminModule(moduleInfo); + dnnModule.CanViewModule = ModulePermissionController.CanViewModule(moduleInfo); + dnnModule.IsDeleted = moduleInfo.IsDeleted; + if (moduleInfo.DefaultLanguageGuid != Null.NullGuid) + { + var defaultLanguageModule = moduleController.GetModuleByUniqueID(moduleInfo.DefaultLanguageGuid); + if (defaultLanguageModule != null) + { + dnnModule.DefaultModuleId = defaultLanguageModule.ModuleID; if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid) { dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName; } - } - } - - dnnModule.SetModuleInfoHelp(); - dnnModule.IsTranslated = moduleInfo.IsTranslated; - dnnModule.IsLocalized = moduleInfo.IsLocalized; - - dnnModule.IsShared = this.tabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1; - - // detect error : the default language module is on an other page - dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null; - - // detect error : different culture on tab and module - dnnModule.ErrorCultureOfModuleNotCultureOfTab = moduleInfo.CultureCode != localTabInfo.CultureCode; - - dnnPages.ErrorExists |= dnnModule.ErrorDefaultOnOtherTab || dnnModule.ErrorCultureOfModuleNotCultureOfTab; - } - } - - return dnnPages; - } - - private void SaveNonLocalizedPages(DnnPagesRequest pages) - { - // check all pages - foreach (var page in pages.Pages) - { - var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); - if (tabInfo != null && - (tabInfo.TabName != page.TabName || - tabInfo.Title != page.Title || - tabInfo.Description != page.Description)) - { - tabInfo.TabName = page.TabName; - tabInfo.Title = page.Title; - tabInfo.Description = page.Description; - this.tabController.UpdateTab(tabInfo); - } - } - - var tabsToPublish = new List(); - var moduleTranslateOverrides = new Dictionary(); - var moduleController = ModuleController.Instance; - - // manage all actions we need to take for all modules on all pages - foreach (var modulesCollection in pages.Modules) - { - foreach (var moduleDto in modulesCollection.Modules) - { - var tabModule = moduleController.GetTabModule(moduleDto.TabModuleId); - if (tabModule != null) - { - if (tabModule.ModuleTitle != moduleDto.ModuleTitle) - { - tabModule.ModuleTitle = moduleDto.ModuleTitle; - moduleController.UpdateModule(tabModule); - } - - if (tabModule.DefaultLanguageGuid != Null.NullGuid && - tabModule.IsLocalized != moduleDto.IsLocalized) - { - var locale = this.localeController.GetLocale(tabModule.CultureCode); + } + } + + dnnModule.SetModuleInfoHelp(); + dnnModule.IsTranslated = moduleInfo.IsTranslated; + dnnModule.IsLocalized = moduleInfo.IsLocalized; + + dnnModule.IsShared = this.tabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1; + + // detect error : the default language module is on an other page + dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null; + + // detect error : different culture on tab and module + dnnModule.ErrorCultureOfModuleNotCultureOfTab = moduleInfo.CultureCode != localTabInfo.CultureCode; + + dnnPages.ErrorExists |= dnnModule.ErrorDefaultOnOtherTab || dnnModule.ErrorCultureOfModuleNotCultureOfTab; + } + } + + return dnnPages; + } + + private void SaveNonLocalizedPages(DnnPagesRequest pages) + { + // check all pages + foreach (var page in pages.Pages) + { + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); + if (tabInfo != null && + (tabInfo.TabName != page.TabName || + tabInfo.Title != page.Title || + tabInfo.Description != page.Description)) + { + tabInfo.TabName = page.TabName; + tabInfo.Title = page.Title; + tabInfo.Description = page.Description; + this.tabController.UpdateTab(tabInfo); + } + } + + var tabsToPublish = new List(); + var moduleTranslateOverrides = new Dictionary(); + var moduleController = ModuleController.Instance; + + // manage all actions we need to take for all modules on all pages + foreach (var modulesCollection in pages.Modules) + { + foreach (var moduleDto in modulesCollection.Modules) + { + var tabModule = moduleController.GetTabModule(moduleDto.TabModuleId); + if (tabModule != null) + { + if (tabModule.ModuleTitle != moduleDto.ModuleTitle) + { + tabModule.ModuleTitle = moduleDto.ModuleTitle; + moduleController.UpdateModule(tabModule); + } + + if (tabModule.DefaultLanguageGuid != Null.NullGuid && + tabModule.IsLocalized != moduleDto.IsLocalized) + { + var locale = this.localeController.GetLocale(tabModule.CultureCode); if (moduleDto.IsLocalized) { moduleController.LocalizeModule(tabModule, locale); @@ -1288,197 +1288,197 @@ private void SaveNonLocalizedPages(DnnPagesRequest pages) { moduleController.DeLocalizeModule(tabModule); } - } - - bool moduleTranslateOverride; - moduleTranslateOverrides.TryGetValue(tabModule.TabID, out moduleTranslateOverride); - - if (!moduleTranslateOverride && tabModule.IsTranslated != moduleDto.IsTranslated) - { - moduleController.UpdateTranslationStatus(tabModule, moduleDto.IsTranslated); - } - } - else if (moduleDto.CopyModule) - { - // find the first existing module on the line - foreach (var moduleToCopyFrom in modulesCollection.Modules) - { - if (moduleToCopyFrom.ModuleId > 0) - { - var toTabInfo = this.GetLocalizedTab(moduleToCopyFrom.TabId, moduleDto.CultureCode); - var miCopy = moduleController.GetTabModule(moduleToCopyFrom.TabModuleId); - if (miCopy.DefaultLanguageGuid == Null.NullGuid) - { - // default - DisableTabVersioningAndWorkflow(toTabInfo); - moduleController.CopyModule(miCopy, toTabInfo, Null.NullString, true); - EnableTabVersioningAndWorkflow(toTabInfo); - var localizedModule = moduleController.GetModule(miCopy.ModuleID, toTabInfo.TabID, false); - moduleController.LocalizeModule(localizedModule, LocaleController.Instance.GetLocale(localizedModule.CultureCode)); - } - else - { - var miCopyDefault = moduleController.GetModuleByUniqueID(miCopy.DefaultLanguageGuid); - moduleController.CopyModule(miCopyDefault, toTabInfo, Null.NullString, true); - } - - if (moduleDto == modulesCollection.Modules.First()) - { - // default language - var miDefault = moduleController.GetModule(miCopy.ModuleID, pages.Pages.First().TabId, false); - foreach (var page in pages.Pages.Skip(1)) - { - var moduleInfo = moduleController.GetModule(miCopy.ModuleID, page.TabId, false); - if (moduleInfo != null) - { - if (miDefault != null) - { - moduleInfo.DefaultLanguageGuid = miDefault.UniqueId; - } - - moduleController.UpdateModule(moduleInfo); - } - } - } - - break; - } - } - } - } - } - - foreach (var page in pages.Pages) - { - var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); - if (tabInfo != null) - { - var moduleTranslateOverride = false; - if (!tabInfo.IsDefaultLanguage) - { - if (tabInfo.IsTranslated != page.IsTranslated) - { - this.tabController.UpdateTranslationStatus(tabInfo, page.IsTranslated); - if (page.IsTranslated) - { - moduleTranslateOverride = true; - var tabModules = moduleController.GetTabModules(tabInfo.TabID) - .Where(moduleKvp => - moduleKvp.Value.DefaultLanguageModule != null && - moduleKvp.Value.LocalizedVersionGuid != moduleKvp.Value.DefaultLanguageModule.LocalizedVersionGuid); - - foreach (var moduleKvp in tabModules) - { - moduleController.UpdateTranslationStatus(moduleKvp.Value, true); - } - } - } - - if (page.IsPublished) - { - tabsToPublish.Add(tabInfo); - } - } - - moduleTranslateOverrides.Add(page.TabId, moduleTranslateOverride); - } - } - - // if we have tabs to publish, do it. - // marks all modules as translated, marks page as translated - foreach (var tabInfo in tabsToPublish) - { - // First mark all modules as translated - foreach (var module in moduleController.GetTabModules(tabInfo.TabID).Values) - { - moduleController.UpdateTranslationStatus(module, true); - } - - // Second mark tab as translated - this.tabController.UpdateTranslationStatus(tabInfo, true); - - // Third publish Tab (update Permissions) - this.tabController.PublishTab(tabInfo); - } - - // manage translated status of tab. In order to do that, we need to check if all modules on the page are translated - var tabTranslatedStatus = true; - foreach (var page in pages.Pages) - { - var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); - if (tabInfo != null) - { - if (tabInfo.ChildModules.Any(moduleKvp => !moduleKvp.Value.IsTranslated)) - { - tabTranslatedStatus = false; - } - - if (tabTranslatedStatus && !tabInfo.IsTranslated) - { - this.tabController.UpdateTranslationStatus(tabInfo, true); - } - } - } - } - - private void AddTranslationSubmittedNotification(TabInfo tabInfo, UserInfo translator, string comment) - { - var notificationsController = NotificationsController.Instance; - var notificationType = notificationsController.GetNotificationType("TranslationSubmitted"); - var subject = LocalizeString("NewContentMessage.Subject"); + } + + bool moduleTranslateOverride; + moduleTranslateOverrides.TryGetValue(tabModule.TabID, out moduleTranslateOverride); + + if (!moduleTranslateOverride && tabModule.IsTranslated != moduleDto.IsTranslated) + { + moduleController.UpdateTranslationStatus(tabModule, moduleDto.IsTranslated); + } + } + else if (moduleDto.CopyModule) + { + // find the first existing module on the line + foreach (var moduleToCopyFrom in modulesCollection.Modules) + { + if (moduleToCopyFrom.ModuleId > 0) + { + var toTabInfo = this.GetLocalizedTab(moduleToCopyFrom.TabId, moduleDto.CultureCode); + var miCopy = moduleController.GetTabModule(moduleToCopyFrom.TabModuleId); + if (miCopy.DefaultLanguageGuid == Null.NullGuid) + { + // default + DisableTabVersioningAndWorkflow(toTabInfo); + moduleController.CopyModule(miCopy, toTabInfo, Null.NullString, true); + EnableTabVersioningAndWorkflow(toTabInfo); + var localizedModule = moduleController.GetModule(miCopy.ModuleID, toTabInfo.TabID, false); + moduleController.LocalizeModule(localizedModule, LocaleController.Instance.GetLocale(localizedModule.CultureCode)); + } + else + { + var miCopyDefault = moduleController.GetModuleByUniqueID(miCopy.DefaultLanguageGuid); + moduleController.CopyModule(miCopyDefault, toTabInfo, Null.NullString, true); + } + + if (moduleDto == modulesCollection.Modules.First()) + { + // default language + var miDefault = moduleController.GetModule(miCopy.ModuleID, pages.Pages.First().TabId, false); + foreach (var page in pages.Pages.Skip(1)) + { + var moduleInfo = moduleController.GetModule(miCopy.ModuleID, page.TabId, false); + if (moduleInfo != null) + { + if (miDefault != null) + { + moduleInfo.DefaultLanguageGuid = miDefault.UniqueId; + } + + moduleController.UpdateModule(moduleInfo); + } + } + } + + break; + } + } + } + } + } + + foreach (var page in pages.Pages) + { + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); + if (tabInfo != null) + { + var moduleTranslateOverride = false; + if (!tabInfo.IsDefaultLanguage) + { + if (tabInfo.IsTranslated != page.IsTranslated) + { + this.tabController.UpdateTranslationStatus(tabInfo, page.IsTranslated); + if (page.IsTranslated) + { + moduleTranslateOverride = true; + var tabModules = moduleController.GetTabModules(tabInfo.TabID) + .Where(moduleKvp => + moduleKvp.Value.DefaultLanguageModule != null && + moduleKvp.Value.LocalizedVersionGuid != moduleKvp.Value.DefaultLanguageModule.LocalizedVersionGuid); + + foreach (var moduleKvp in tabModules) + { + moduleController.UpdateTranslationStatus(moduleKvp.Value, true); + } + } + } + + if (page.IsPublished) + { + tabsToPublish.Add(tabInfo); + } + } + + moduleTranslateOverrides.Add(page.TabId, moduleTranslateOverride); + } + } + + // if we have tabs to publish, do it. + // marks all modules as translated, marks page as translated + foreach (var tabInfo in tabsToPublish) + { + // First mark all modules as translated + foreach (var module in moduleController.GetTabModules(tabInfo.TabID).Values) + { + moduleController.UpdateTranslationStatus(module, true); + } + + // Second mark tab as translated + this.tabController.UpdateTranslationStatus(tabInfo, true); + + // Third publish Tab (update Permissions) + this.tabController.PublishTab(tabInfo); + } + + // manage translated status of tab. In order to do that, we need to check if all modules on the page are translated + var tabTranslatedStatus = true; + foreach (var page in pages.Pages) + { + var tabInfo = this.tabController.GetTab(page.TabId, this.PortalId, true); + if (tabInfo != null) + { + if (tabInfo.ChildModules.Any(moduleKvp => !moduleKvp.Value.IsTranslated)) + { + tabTranslatedStatus = false; + } + + if (tabTranslatedStatus && !tabInfo.IsTranslated) + { + this.tabController.UpdateTranslationStatus(tabInfo, true); + } + } + } + } + + private void AddTranslationSubmittedNotification(TabInfo tabInfo, UserInfo translator, string comment) + { + var notificationsController = NotificationsController.Instance; + var notificationType = notificationsController.GetNotificationType("TranslationSubmitted"); + var subject = LocalizeString("NewContentMessage.Subject"); var body = string.Format( - LocalizeString("NewContentMessage.Body"), - tabInfo.TabName, - this.NavigationManager.NavigateURL(tabInfo.TabID, false, this.PortalSettings, Null.NullString, tabInfo.CultureCode), - comment); - - var sender = UserController.GetUserById(this.PortalSettings.PortalId, this.PortalSettings.AdministratorId); - var notification = new Notification - { - NotificationTypeID = notificationType.NotificationTypeId, - Subject = subject, - Body = body, - IncludeDismissAction = true, - SenderUserID = sender.UserID, - }; - - notificationsController.SendNotification(notification, this.PortalSettings.PortalId, null, new List { translator }); - } - - private HttpResponseMessage GetForbiddenResponse() - { - return this.Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "The user is not allowed to access this method." }); - } - - private ThemeFileInfo GetDefaultPortalTheme() - { - var layoutSrc = this.defaultPortalThemeController.GetDefaultPortalLayout(); - if (string.IsNullOrWhiteSpace(layoutSrc)) - { - return null; - } - - var layout = this.themesController.GetThemeFile(PortalSettings.Current, layoutSrc, ThemeType.Skin); - return layout; - } - - private TabInfo GetLocalizedTab(int tabId, string cultureCode) - { - var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); - - // Unique id of default language page - var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid - ? currentTab.DefaultLanguageGuid - : currentTab.UniqueId; - - // get all non admin pages and not deleted - var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( - t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); - allPages = allPages.Where(t => t.IsDeleted == false); - - // get all localized pages of current page - var tabInfos = allPages as IList ?? allPages.ToList(); - return tabInfos.SingleOrDefault(t => (t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId) && t.CultureCode == cultureCode); - } - } -} + LocalizeString("NewContentMessage.Body"), + tabInfo.TabName, + this.NavigationManager.NavigateURL(tabInfo.TabID, false, this.PortalSettings, Null.NullString, tabInfo.CultureCode), + comment); + + var sender = UserController.GetUserById(this.PortalSettings.PortalId, this.PortalSettings.AdministratorId); + var notification = new Notification + { + NotificationTypeID = notificationType.NotificationTypeId, + Subject = subject, + Body = body, + IncludeDismissAction = true, + SenderUserID = sender.UserID, + }; + + notificationsController.SendNotification(notification, this.PortalSettings.PortalId, null, new List { translator }); + } + + private HttpResponseMessage GetForbiddenResponse() + { + return this.Request.CreateResponse(HttpStatusCode.Forbidden, new { Message = "The user is not allowed to access this method." }); + } + + private ThemeFileInfo GetDefaultPortalTheme() + { + var layoutSrc = this.defaultPortalThemeController.GetDefaultPortalLayout(); + if (string.IsNullOrWhiteSpace(layoutSrc)) + { + return null; + } + + var layout = this.themesController.GetThemeFile(PortalSettings.Current, layoutSrc, ThemeType.Skin); + return layout; + } + + private TabInfo GetLocalizedTab(int tabId, string cultureCode) + { + var currentTab = this.tabController.GetTab(tabId, this.PortalId, false); + + // Unique id of default language page + var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid + ? currentTab.DefaultLanguageGuid + : currentTab.UniqueId; + + // get all non admin pages and not deleted + var allPages = this.tabController.GetTabsByPortal(this.PortalId).Values.Where( + t => t.TabID != this.PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != this.PortalSettings.AdminTabId)); + allPages = allPages.Where(t => t.IsDeleted == false); + + // get all localized pages of current page + var tabInfos = allPages as IList ?? allPages.ToList(); + return tabInfos.SingleOrDefault(t => (t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId) && t.CultureCode == cultureCode); + } + } +} From 821b034eb75def02923aa0d8a45d5078b13ae938 Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 20:29:37 -0400 Subject: [PATCH 09/10] Corrected typos --- .../Services/PagesController.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs index af0efd89d1d..c7e1d308e5f 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs @@ -718,7 +718,7 @@ public HttpResponseMessage MakePageTranslatable([FromUri] int pageId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to make this page translatable."; + var errorMessage = "An unexpected error occurred while trying to make this page translatable."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -748,7 +748,7 @@ public HttpResponseMessage AddMissingLanguages([FromUri] int pageId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to add missing languages to this page, consult the logs for more details."; + var errorMessage = "An unexpected error occurred while trying to add missing languages to this page, consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -793,7 +793,7 @@ public HttpResponseMessage NotifyTranslators(TranslatorsComment comment) } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to notify the translators, please consult the logs for more details."; + var errorMessage = "An unexpected error occurred while trying to notify the translators, please consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -828,7 +828,7 @@ public HttpResponseMessage GetTabLocalization(int pageId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured trying to get this page localization, consolt the logs for more details."; + var errorMessage = "An unexpected error occurrfed trying to get this page localization, consolt the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -857,7 +857,7 @@ public HttpResponseMessage UpdateTabLocalization(DnnPagesRequest request) } catch (Exception ex) { - var errorMessage = "An unexpected error occured trying to update the page localization, please consult the logs for more details."; + var errorMessage = "An unexpected error occurred trying to update the page localization, please consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -894,7 +894,7 @@ public HttpResponseMessage RestoreModule(int tabModuleId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to restore the module onto that page."; + var errorMessage = "An unexpected error occurred while trying to restore the module onto that page."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -931,7 +931,7 @@ public HttpResponseMessage DeleteModule(int tabModuleId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to delete the module, consult the logs for more details."; + var errorMessage = "An unexpected error occurred while trying to delete the module, consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -956,7 +956,7 @@ public HttpResponseMessage GetContentLocalizationEnabled() } catch (Exception ex) { - var errorMessage = "An unexpected error occured while trying to find if content localization is enabled"; + var errorMessage = "An unexpected error occurred while trying to find if content localization is enabled"; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -983,7 +983,7 @@ public HttpResponseMessage GetCachedItemCount(string cacheProvider, int pageId) } catch (Exception ex) { - var errorMessage = "An unexpected error occured trying to get the cached items count, please consult the logs for more details."; + var errorMessage = "An unexpected error occurred trying to get the cached items count, please consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); } @@ -1013,7 +1013,7 @@ public HttpResponseMessage ClearCache([FromUri] string cacheProvider, [FromUri] } catch (Exception ex) { - var message = "An unexpected error occured while trying to clear the cache for this page, see logs for more details."; + var message = "An unexpected error occurred while trying to clear the cache for this page, see logs for more details."; Logger.Error(message, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message); } From c6f6f7cf4f888605f284493db3c910437e5cae9a Mon Sep 17 00:00:00 2001 From: Daniel Valadas Date: Sat, 27 Jun 2020 20:33:11 -0400 Subject: [PATCH 10/10] One more typo --- .../Dnn.PersonaBar.Extensions/Services/PagesController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs index c7e1d308e5f..7e461542d4b 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/PagesController.cs @@ -828,7 +828,7 @@ public HttpResponseMessage GetTabLocalization(int pageId) } catch (Exception ex) { - var errorMessage = "An unexpected error occurrfed trying to get this page localization, consolt the logs for more details."; + var errorMessage = "An unexpected error occurrfed trying to get this page localization, consult the logs for more details."; Logger.Error(errorMessage, ex); return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage); }