From 9cc8b30b6dd959f35646c5783421cc361cf93a59 Mon Sep 17 00:00:00 2001 From: StanleyGoldman Date: Tue, 23 Apr 2013 19:41:52 -0400 Subject: [PATCH] #17795 Adding a ViewContentTypes Permission --HG-- branch : 1.x extra : source : 5d7754f28609ac7ae688b44abbd666608b03225b --- src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs | 4 ++-- .../Orchard.ContentTypes/Controllers/AdminController.cs | 3 +++ src/Orchard.Web/Modules/Orchard.ContentTypes/Permissions.cs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs index 3c3982781..08fd5c613 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs @@ -12,8 +12,8 @@ namespace Orchard.ContentTypes { builder.Add(T("Content Definition"), "1.4.1", menu => { menu.LinkToFirstChild(true); - menu.Add(T("Content Types"), "1", item => item.Action("Index", "Admin", new { area = "Orchard.ContentTypes" }).LocalNav()); - menu.Add(T("Content Parts"), "2", item => item.Action("ListParts", "Admin", new { area = "Orchard.ContentTypes" }).LocalNav()); + menu.Add(T("Content Types"), "1", item => item.Action("Index", "Admin", new { area = "Orchard.ContentTypes" }).Permission(Permissions.ViewContentTypes).LocalNav()); + menu.Add(T("Content Parts"), "2", item => item.Action("ListParts", "Admin", new { area = "Orchard.ContentTypes" }).Permission(Permissions.ViewContentTypes).LocalNav()); }); } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index b867e82b2..930a93d62 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -51,6 +51,9 @@ namespace Orchard.ContentTypes.Controllers { #region Types public ActionResult List() { + if (!Services.Authorizer.Authorize(Permissions.ViewContentTypes, T("Not allowed to view content types."))) + return new HttpUnauthorizedResult(); + return View("List", new ListContentTypesViewModel { Types = _contentDefinitionService.GetTypes() }); diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Permissions.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Permissions.cs index af64cccc7..f6c465a95 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Permissions.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Permissions.cs @@ -4,13 +4,15 @@ using Orchard.Security.Permissions; namespace Orchard.ContentTypes { public class Permissions : IPermissionProvider { + public static readonly Permission ViewContentTypes = new Permission { Name = "ViewContentTypes", Description = "View content types." }; public static readonly Permission EditContentTypes = new Permission { Name = "EditContentTypes", Description = "Edit content types." }; public virtual Feature Feature { get; set; } public IEnumerable GetPermissions() { return new [] { - EditContentTypes, + ViewContentTypes, + EditContentTypes }; }