From d216132a4b0f946a35b4908c4d6fcd8092943401 Mon Sep 17 00:00:00 2001 From: Bertrand Le Roy Date: Wed, 22 Aug 2012 18:46:15 -0700 Subject: [PATCH] Minor refactoring to enable a localized string to be picked up by loc tool. --HG-- branch : 1.x --- .../Controllers/AdminController.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs index bb9c014c3..6912d26d9 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs @@ -14,7 +14,6 @@ using Orchard.Mvc.Extensions; using Orchard.Themes.Services; using Orchard.UI.Admin; using Orchard.UI.Notify; -using Orchard.Utility.Extensions; using Orchard.Widgets.Models; using Orchard.Widgets.Services; @@ -23,8 +22,6 @@ namespace Orchard.Widgets.Controllers { [ValidateInput(false), Admin] public class AdminController : Controller, IUpdateModel { - private const string NotAuthorizedManageWidgetsLabel = "Not authorized to manage widgets"; - private readonly IWidgetsService _widgetsService; private readonly ISiteThemeService _siteThemeService; private readonly IVirtualPathProvider _virtualPathProvider; @@ -94,7 +91,7 @@ namespace Orchard.Widgets.Controllers { if (!string.IsNullOrWhiteSpace(moveOut)) return DeleteWidget(widgetId, returnUrl); - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); if (!string.IsNullOrWhiteSpace(moveUp)) @@ -107,9 +104,13 @@ namespace Orchard.Widgets.Controllers { return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); } + private bool IsAuthorizedToManageWidgets() { + return Services.Authorizer.Authorize(Permissions.ManageWidgets, T("Not authorized to manage widgets")); + } + public ActionResult ChooseWidget(int layerId, string zone, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); if (string.IsNullOrWhiteSpace(zone)) { @@ -141,7 +142,7 @@ namespace Orchard.Widgets.Controllers { } public ActionResult AddWidget(int layerId, string widgetType, string zone, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); WidgetPart widgetPart = Services.ContentManager.New(widgetType); @@ -165,7 +166,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("AddWidget")] public ActionResult AddWidgetPOST(int layerId, string widgetType, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", ""); @@ -194,7 +195,7 @@ namespace Orchard.Widgets.Controllers { } public ActionResult AddLayer(string name, string description, string layerRule) { // <- hints for a new layer - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); LayerPart layerPart = Services.ContentManager.New("Layer"); @@ -217,7 +218,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("AddLayer")] public ActionResult AddLayerPOST() { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); LayerPart layerPart = _widgetsService.CreateLayer("", "", ""); @@ -237,7 +238,7 @@ namespace Orchard.Widgets.Controllers { } public ActionResult EditLayer(int id) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); LayerPart layerPart = _widgetsService.GetLayer(id); @@ -252,7 +253,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("EditLayer")] [FormValueRequired("submit.Save")] public ActionResult EditLayerSavePOST(int id, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); LayerPart layerPart = _widgetsService.GetLayer(id); @@ -275,7 +276,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("EditLayer")] [FormValueRequired("submit.Delete")] public ActionResult EditLayerDeletePOST(int id) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); try { @@ -290,7 +291,7 @@ namespace Orchard.Widgets.Controllers { } public ActionResult EditWidget(int id) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); WidgetPart widgetPart = null; @@ -318,7 +319,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("EditWidget")] [FormValueRequired("submit.Save")] public ActionResult EditWidgetSavePOST(int id, int layerId, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); WidgetPart widgetPart = null; @@ -350,7 +351,7 @@ namespace Orchard.Widgets.Controllers { return DeleteWidget(id, returnUrl); } private ActionResult DeleteWidget(int id, string returnUrl) { - if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) + if (!IsAuthorizedToManageWidgets()) return new HttpUnauthorizedResult(); WidgetPart widgetPart = null;