Fix wrong behaviours and exceptions when blog is unpublished. (#8389)

* Fix wrong behaviours and exceptions when blog is unpublished. More details there #8388.
This commit is contained in:
Hermes Sbicego
2020-07-10 08:31:11 +02:00
committed by GitHub
parent b82e232e38
commit 87477518fa
5 changed files with 31 additions and 9 deletions

View File

@@ -142,10 +142,17 @@ namespace Orchard.Core.Common.Handlers {
part.VersionPublishedUtc = utcNow;
}
protected void LazyLoadHandlers(CommonPart part) {
// add handlers that will load content for id's just-in-time
part.OwnerField.Loader(() => _contentManager.Get<IUser>(part.Record.OwnerId));
part.ContainerField.Loader(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id));
part.ContainerField.Loader(() => part.Record.Container == null ?
null :
/* Published, or latest if published version is missing:
** So the relation with the container is still present even if the container is unpublished
*/
_contentManager.Get(part.Record.Container.Id) ??
_contentManager.Get(part.Record.Container.Id, VersionOptions.Latest));
}
protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) {

View File

@@ -1,5 +1,6 @@
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Localization;
using Orchard.Mvc;
using Orchard.Themes;
@@ -41,6 +42,17 @@ namespace Orchard.Core.Contents.Controllers {
if (contentItem == null)
return HttpNotFound();
var container = contentItem.As<CommonPart>()?.Container;
if (container != null && !container.HasPublished()) {
// if the content has a container that has not a published version we check preview permissions
// in order to check if user can view the content or not.
// Open point: should we handle hierarchies?
if (!Services.Authorizer.Authorize(Permissions.PreviewContent, contentItem)) {
return HttpNotFound();
}
}
if (!Services.Authorizer.Authorize(Permissions.ViewContent, contentItem, T("Cannot view content"))) {
return new HttpUnauthorizedResult();
}

View File

@@ -1,5 +1,6 @@
using System.Linq;
using Orchard.Blogs.Services;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Security;
using Orchard.UI.Navigation;
@@ -26,7 +27,7 @@ namespace Orchard.Blogs {
}
private void BuildMenu(NavigationItemBuilder menu) {
var blogs = _blogService.Get().Where(x => _authorizationService.TryCheckAccess(Permissions.MetaListBlogs, _workContextAccessor.GetContext().CurrentUser, x)).ToArray();
var blogs = _blogService.Get(VersionOptions.Latest).Where(x => _authorizationService.TryCheckAccess(Permissions.MetaListBlogs, _workContextAccessor.GetContext().CurrentUser, x)).ToArray();
var blogCount = blogs.Count();
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;

View File

@@ -1,5 +1,5 @@
using Orchard.Blogs.Models;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Feeds;
@@ -15,11 +15,13 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Display(BlogPostPart part, string displayType, dynamic shapeHelper) {
if (displayType.StartsWith("Detail")) {
var blogTitle = _contentManager.GetItemMetadata(part.BlogPart).DisplayText;
_feedManager.Register(part.BlogPart, blogTitle);
if (part.BlogPart != null && part.BlogPart.HasPublished()) {
if (displayType.StartsWith("Detail")) {
var publishedBlog = part.BlogPart.IsPublished() ? part.BlogPart : _contentManager.Get(part.BlogPart.Id).As<BlogPart>();
var blogTitle = _contentManager.GetItemMetadata(publishedBlog).DisplayText;
_feedManager.Register(publishedBlog, blogTitle);
}
}
return null;
}
}

View File

@@ -48,7 +48,7 @@
}
else {
@Html.ItemDisplayText(termEntry.ContentItem)
@if (termEntry.HasDraft) {
if (termEntry.HasDraft) {
<text>@T(" (Draft)")</text>
}
}