Fix List.cshtml with new permission (#8053)

This commit is contained in:
Matteo Piovanelli
2018-05-17 21:21:59 +02:00
committed by Sébastien Ros
parent 4c78799be3
commit 92ca4128e3

View File

@@ -6,16 +6,19 @@
var typeDisplayName = Model.TypeDisplayName; var typeDisplayName = Model.TypeDisplayName;
var pageTitle = T("Manage Content"); var pageTitle = T("Manage Content");
var createLinkText = T("Create New Content"); var createLinkText = T("Create New Content");
var userCanCreateContent = false; // if no specific type is selected, we assume we should show the "Create" button
var showCreateContentButton = string.IsNullOrWhiteSpace(typeDisplayName);
IAuthorizationService _authorizationService; IAuthorizationService _authorizationService;
WorkContext.TryResolve<IAuthorizationService>(out _authorizationService); WorkContext.TryResolve<IAuthorizationService>(out _authorizationService);
if (!string.IsNullOrWhiteSpace(typeDisplayName)) { if (!showCreateContentButton) {
// being here it means there is a specific type we are considering
pageTitle = T("Manage {0} Content", Html.Raw(typeDisplayName)); pageTitle = T("Manage {0} Content", Html.Raw(typeDisplayName));
createLinkText = T("Create New {0}", Html.Raw(typeDisplayName)); createLinkText = T("Create New {0}", Html.Raw(typeDisplayName));
var permission = DynamicPermissions.CreateDynamicPermission(DynamicPermissions.PermissionTemplates[Permissions.CreateContent.Name], Model.ContentType); var permission = DynamicPermissions
.CreateDynamicPermission(DynamicPermissions.PermissionTemplates[Permissions.CreateContent.Name], Model.ContentType);
if (_authorizationService.TryCheckAccess(permission, WorkContext.CurrentUser, null)) { if (_authorizationService.TryCheckAccess(permission, WorkContext.CurrentUser, null)) {
userCanCreateContent = true; showCreateContentButton = true;
} }
} }
@@ -23,7 +26,7 @@
Layout.Title = pageTitle.Text; Layout.Title = pageTitle.Text;
} }
@if (userCanCreateContent) { @if (showCreateContentButton) {
<div class="manage"> <div class="manage">
@Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" }) @Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" })
</div> </div>