mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
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:
@@ -142,10 +142,17 @@ namespace Orchard.Core.Common.Handlers {
|
|||||||
part.VersionPublishedUtc = utcNow;
|
part.VersionPublishedUtc = utcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void LazyLoadHandlers(CommonPart part) {
|
protected void LazyLoadHandlers(CommonPart part) {
|
||||||
// add handlers that will load content for id's just-in-time
|
// add handlers that will load content for id's just-in-time
|
||||||
part.OwnerField.Loader(() => _contentManager.Get<IUser>(part.Record.OwnerId));
|
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) {
|
protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
@@ -41,6 +42,17 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
if (contentItem == null)
|
if (contentItem == null)
|
||||||
return HttpNotFound();
|
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"))) {
|
if (!Services.Authorizer.Authorize(Permissions.ViewContent, contentItem, T("Cannot view content"))) {
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Blogs.Services;
|
using Orchard.Blogs.Services;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.UI.Navigation;
|
using Orchard.UI.Navigation;
|
||||||
@@ -26,7 +27,7 @@ namespace Orchard.Blogs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void BuildMenu(NavigationItemBuilder menu) {
|
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 blogCount = blogs.Count();
|
||||||
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.Core.Feeds;
|
using Orchard.Core.Feeds;
|
||||||
@@ -15,11 +15,13 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Display(BlogPostPart part, string displayType, dynamic shapeHelper) {
|
protected override DriverResult Display(BlogPostPart part, string displayType, dynamic shapeHelper) {
|
||||||
if (displayType.StartsWith("Detail")) {
|
if (part.BlogPart != null && part.BlogPart.HasPublished()) {
|
||||||
var blogTitle = _contentManager.GetItemMetadata(part.BlogPart).DisplayText;
|
if (displayType.StartsWith("Detail")) {
|
||||||
_feedManager.Register(part.BlogPart, blogTitle);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@Html.ItemDisplayText(termEntry.ContentItem)
|
@Html.ItemDisplayText(termEntry.ContentItem)
|
||||||
@if (termEntry.HasDraft) {
|
if (termEntry.HasDraft) {
|
||||||
<text>@T(" (Draft)")</text>
|
<text>@T(" (Draft)")</text>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user