mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
@@ -1,14 +1,19 @@
|
||||
using System.Linq;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Blogs {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public AdminMenu(IBlogService blogService) {
|
||||
public AdminMenu(IBlogService blogService, IAuthorizationService authorizationService, IWorkContextAccessor workContextAccessor) {
|
||||
_blogService = blogService;
|
||||
_authorizationService = authorizationService;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
@@ -21,13 +26,13 @@ namespace Orchard.Blogs {
|
||||
}
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
var blogs = _blogService.Get();
|
||||
var blogs = _blogService.Get().Where(x => _authorizationService.TryCheckAccess(Permissions.MetaListBlogs, _workContextAccessor.GetContext().CurrentUser, x)).ToArray();
|
||||
var blogCount = blogs.Count();
|
||||
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
||||
|
||||
if (blogCount > 0 && singleBlog == null) {
|
||||
menu.Add(T("Manage Blogs"), "3",
|
||||
item => item.Action("List", "BlogAdmin", new { area = "Orchard.Blogs" }).Permission(Permissions.MetaListBlogs));
|
||||
item => item.Action("List", "BlogAdmin", new { area = "Orchard.Blogs" }).Permission(Permissions.MetaListOwnBlogs));
|
||||
}
|
||||
else if (singleBlog != null)
|
||||
menu.Add(T("Manage Blog"), "1.0",
|
||||
@@ -36,7 +41,7 @@ namespace Orchard.Blogs {
|
||||
if (singleBlog != null)
|
||||
menu.Add(T("New Post"), "1.1",
|
||||
item =>
|
||||
item.Action("Create", "BlogPostAdmin", new { area = "Orchard.Blogs", blogId = singleBlog.Id }).Permission(Permissions.MetaListOwnBlogs));
|
||||
item.Action("Create", "BlogPostAdmin", new {area = "Orchard.Blogs", blogId = singleBlog.Id}).Permission(Permissions.MetaListOwnBlogs));
|
||||
|
||||
menu.Add(T("New Blog"), "1.2",
|
||||
item =>
|
||||
|
||||
@@ -153,11 +153,12 @@ namespace Orchard.Blogs.Controllers {
|
||||
public ActionResult List() {
|
||||
var list = Services.New.List();
|
||||
list.AddRange(_blogService.Get(VersionOptions.Latest)
|
||||
.Select(b => {
|
||||
var blog = Services.ContentManager.BuildDisplay(b, "SummaryAdmin");
|
||||
blog.TotalPostCount = _blogPostService.PostCount(b, VersionOptions.Latest);
|
||||
return blog;
|
||||
}));
|
||||
.Where(x => Services.Authorizer.Authorize(Permissions.MetaListOwnBlogs, x))
|
||||
.Select(b => {
|
||||
var blog = Services.ContentManager.BuildDisplay(b, "SummaryAdmin");
|
||||
blog.TotalPostCount = _blogPostService.PostCount(b, VersionOptions.Latest);
|
||||
return blog;
|
||||
}));
|
||||
|
||||
dynamic viewModel = Services.New.ViewModel()
|
||||
.ContentItems(list);
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Orchard.Blogs {
|
||||
public static readonly Permission DeleteBlogPost = new Permission { Description = "Delete blog post for others", Name = "DeleteBlogPost", ImpliedBy = new[] { ManageBlogs } };
|
||||
public static readonly Permission DeleteOwnBlogPost = new Permission { Description = "Delete own blog post", Name = "DeleteOwnBlogPost", ImpliedBy = new[] { DeleteBlogPost, ManageOwnBlogs } };
|
||||
|
||||
public static readonly Permission MetaListBlogs = new Permission { ImpliedBy = new[] { EditBlogPost, PublishBlogPost, DeleteBlogPost } };
|
||||
public static readonly Permission MetaListOwnBlogs = new Permission { ImpliedBy = new[] { EditOwnBlogPost, PublishOwnBlogPost, DeleteOwnBlogPost } };
|
||||
public static readonly Permission MetaListBlogs = new Permission { ImpliedBy = new[] { EditBlogPost, PublishBlogPost, DeleteBlogPost }, Name = "MetaListBlogs"};
|
||||
public static readonly Permission MetaListOwnBlogs = new Permission { ImpliedBy = new[] { EditOwnBlogPost, PublishOwnBlogPost, DeleteOwnBlogPost }, Name = "MetaListOwnBlogs" };
|
||||
|
||||
public virtual Feature Feature { get; set; }
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using System.Web.UI.WebControls;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Security;
|
||||
@@ -13,7 +14,12 @@ namespace Orchard.Blogs.Security {
|
||||
public void Adjust(CheckAccessContext context) {
|
||||
if (!context.Granted &&
|
||||
context.Content.Is<ICommonPart>()) {
|
||||
if (OwnerVariationExists(context.Permission) &&
|
||||
|
||||
if (context.Permission.Name == Orchard.Core.Contents.Permissions.PublishContent.Name && context.Content.ContentItem.ContentType == "BlogPost") {
|
||||
context.Adjusted = true;
|
||||
context.Permission = Permissions.PublishBlogPost;
|
||||
}
|
||||
else if (OwnerVariationExists(context.Permission) &&
|
||||
HasOwnership(context.User, context.Content)) {
|
||||
context.Adjusted = true;
|
||||
context.Permission = GetOwnerVariation(context.Permission);
|
||||
@@ -64,6 +70,9 @@ namespace Orchard.Blogs.Security {
|
||||
return Permissions.DeleteOwnBlogPost;
|
||||
if (permission.Name == Core.Contents.Permissions.ViewContent.Name)
|
||||
return Core.Contents.Permissions.ViewOwnContent;
|
||||
if (permission.Name == Permissions.MetaListBlogs.Name)
|
||||
return Permissions.MetaListOwnBlogs;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user