From 9838c674243bb137f62b1fe56412adb646e29e48 Mon Sep 17 00:00:00 2001 From: andrerod Date: Fri, 17 Dec 2010 17:40:30 -0800 Subject: [PATCH] #17051: Correcting a few wrong handlers Loaded -> Loading. Adding handlers to hook loaders on Versioning. Fixing small permissions issue on live writter so that the user only gets the blogs that he can edit. --HG-- branch : 1.x --- .../Core/Common/Handlers/CommonPartHandler.cs | 29 +++++----- .../Handlers/ArchiveLaterPartHandler.cs | 8 ++- .../Controllers/BlogPostAdminController.cs | 28 ++++++---- .../Drivers/BlogPostPartDriver.cs | 2 +- .../Handlers/BlogPostPartHandler.cs | 56 ++++++++----------- .../Orchard.Blogs/Services/IBlogService.cs | 2 +- .../Orchard.Blogs/Services/XmlRpcHandler.cs | 43 ++++++++------ .../Modules/Orchard.Comments/Placement.info | 4 +- .../Handlers/LocalizationPartHandler.cs | 19 +++++-- .../Handlers/PublishLaterPartHandler.cs | 10 +++- .../Handlers/UserRolesPartHandler.cs | 1 - src/Orchard/Caching/CacheModule.cs | 2 +- .../ContentManagement/IContentManager.cs | 27 +++++++++ 13 files changed, 139 insertions(+), 92 deletions(-) diff --git a/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs b/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs index c58bbe8f2..c18471aba 100644 --- a/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs +++ b/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs @@ -34,12 +34,13 @@ namespace Orchard.Core.Common.Handlers { Filters.Add(StorageFilter.For(commonRepository)); Filters.Add(StorageFilter.For(commonVersionRepository)); - OnInitializing(PropertySetHandlers); + OnActivated(PropertySetHandlers); OnInitializing(AssignCreatingOwner); OnInitializing(AssignCreatingDates); OnInitializing>(AssignCreatingDates); - OnLoaded(LazyLoadHandlers); + OnLoading((context, part) => LazyLoadHandlers(part)); + OnVersioning((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart)); OnVersioned(AssignVersioningDates); OnVersioned>(AssignVersioningDates); @@ -65,7 +66,7 @@ namespace Orchard.Core.Common.Handlers { context.Builder.Weld>(); } - bool ContentTypeWithACommonPart(string typeName) { + protected bool ContentTypeWithACommonPart(string typeName) { //Note: What about content type handlers which activate "CommonPart" in code? var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName); @@ -75,26 +76,26 @@ namespace Orchard.Core.Common.Handlers { return false; } - void AssignCreatingOwner(InitializingContentContext context, CommonPart part) { + protected void AssignCreatingOwner(InitializingContentContext context, CommonPart part) { // and use the current user as Owner if (part.Record.OwnerId == 0) { part.Owner = _authenticationService.GetAuthenticatedUser(); } } - void AssignCreatingDates(InitializingContentContext context, CommonPart part) { + protected void AssignCreatingDates(InitializingContentContext context, CommonPart part) { // assign default create/modified dates part.CreatedUtc = _clock.UtcNow; part.ModifiedUtc = _clock.UtcNow; } - void AssignCreatingDates(InitializingContentContext context, ContentPart part) { + protected void AssignCreatingDates(InitializingContentContext context, ContentPart part) { // assign default create/modified dates part.Record.CreatedUtc = _clock.UtcNow; part.Record.ModifiedUtc = _clock.UtcNow; } - void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) { + protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) { // assign the created building.CreatedUtc = existing.CreatedUtc ?? _clock.UtcNow; // persist and published dates @@ -103,7 +104,7 @@ namespace Orchard.Core.Common.Handlers { building.ModifiedUtc = _clock.UtcNow; } - void AssignVersioningDates(VersionContentContext context, ContentPart existing, ContentPart building) { + protected void AssignVersioningDates(VersionContentContext context, ContentPart existing, ContentPart building) { // assign the created date building.Record.CreatedUtc = _clock.UtcNow; // assign modified date for the new version @@ -112,7 +113,7 @@ namespace Orchard.Core.Common.Handlers { building.Record.PublishedUtc = null; } - void AssignPublishingDates(PublishContentContext context, CommonPart part) { + protected void AssignPublishingDates(PublishContentContext context, CommonPart part) { // don't assign dates when unpublishing if (context.PublishingItemVersionRecord == null) return; @@ -121,7 +122,7 @@ namespace Orchard.Core.Common.Handlers { part.PublishedUtc = part.PublishedUtc ?? _clock.UtcNow; } - void AssignPublishingDates(PublishContentContext context, ContentPart part) { + protected void AssignPublishingDates(PublishContentContext context, ContentPart part) { // don't assign dates when unpublishing if (context.PublishingItemVersionRecord == null) return; @@ -130,13 +131,13 @@ namespace Orchard.Core.Common.Handlers { part.Record.PublishedUtc = part.Record.PublishedUtc ?? _clock.UtcNow; } - void LazyLoadHandlers(LoadContentContext context, CommonPart part) { + protected void LazyLoadHandlers(CommonPart part) { // add handlers that will load content for id's just-in-time part.OwnerField.Loader(() => _contentManager.Get(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 : _contentManager.Get(part.Record.Container.Id)); } - static void PropertySetHandlers(InitializingContentContext context, CommonPart part) { + protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) { // add handlers that will update records when part properties are set part.OwnerField.Setter(user => { @@ -162,4 +163,4 @@ namespace Orchard.Core.Common.Handlers { part.ContainerField.Value = part.ContainerField.Value; } } -} \ No newline at end of file +} diff --git a/src/Orchard.Web/Modules/Orchard.ArchiveLater/Handlers/ArchiveLaterPartHandler.cs b/src/Orchard.Web/Modules/Orchard.ArchiveLater/Handlers/ArchiveLaterPartHandler.cs index 45cf29cca..6156530e7 100644 --- a/src/Orchard.Web/Modules/Orchard.ArchiveLater/Handlers/ArchiveLaterPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.ArchiveLater/Handlers/ArchiveLaterPartHandler.cs @@ -1,6 +1,5 @@ using Orchard.ArchiveLater.Models; using Orchard.ArchiveLater.Services; -using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; namespace Orchard.ArchiveLater.Handlers { @@ -10,7 +9,12 @@ namespace Orchard.ArchiveLater.Handlers { public ArchiveLaterPartHandler(IArchiveLaterService archiveLaterService) { _archiveLaterService = archiveLaterService; - OnLoaded((context, archiveLater) => archiveLater.ScheduledArchiveUtc.Loader(delegate { return _archiveLaterService.GetScheduledArchiveUtc(archiveLater.As()); })); + OnLoading((context, part) => LazyLoadHandlers(part)); + OnVersioning((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart)); + } + + protected void LazyLoadHandlers(ArchiveLaterPart part) { + part.ScheduledArchiveUtc.Loader((value) => _archiveLaterService.GetScheduledArchiveUtc(part)); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs index 2022dd933..5e61ea706 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs @@ -10,8 +10,6 @@ using Orchard.Core.Contents.Settings; using Orchard.Localization; using Orchard.Mvc.AntiForgery; using Orchard.Mvc.Extensions; -using Orchard.Security; -using Orchard.Security.Permissions; using Orchard.UI.Admin; using Orchard.UI.Notify; @@ -31,14 +29,17 @@ namespace Orchard.Blogs.Controllers { public IOrchardServices Services { get; set; } public Localizer T { get; set; } - public ActionResult Create() { + public ActionResult Create(int blogId) { if (!Services.Authorizer.Authorize(Permissions.EditOwnBlogPost, T("Not allowed to create blog post"))) return new HttpUnauthorizedResult(); - var blogPost = Services.ContentManager.New("BlogPost"); - if (blogPost.BlogPart == null) + var blog = _blogService.Get(blogId, VersionOptions.Latest).As(); + if (blog == null) return HttpNotFound(); + var blogPost = Services.ContentManager.New("BlogPost"); + blogPost.BlogPart = blog; + dynamic model = Services.ContentManager.BuildEditor(blogPost); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return View((object)model); @@ -46,8 +47,8 @@ namespace Orchard.Blogs.Controllers { [HttpPost, ActionName("Create")] [FormValueRequired("submit.Save")] - public ActionResult CreatePOST() { - return CreatePOST(contentItem => { + public ActionResult CreatePOST(int blogId) { + return CreatePOST(blogId, contentItem => { if (!contentItem.Has() && !contentItem.TypeDefinition.Settings.GetModel().Draftable) Services.ContentManager.Publish(contentItem); }); @@ -55,21 +56,24 @@ namespace Orchard.Blogs.Controllers { [HttpPost, ActionName("Create")] [FormValueRequired("submit.Publish")] - public ActionResult CreateAndPublishPOST() { + public ActionResult CreateAndPublishPOST(int blogId) { if (!Services.Authorizer.Authorize(Permissions.PublishOwnBlogPost, T("Couldn't create blog post"))) return new HttpUnauthorizedResult(); - return CreatePOST(contentItem => Services.ContentManager.Publish(contentItem)); + return CreatePOST(blogId, contentItem => Services.ContentManager.Publish(contentItem)); } - public ActionResult CreatePOST(Action conditionallyPublish) { + private ActionResult CreatePOST(int blogId, Action conditionallyPublish) { if (!Services.Authorizer.Authorize(Permissions.EditOwnBlogPost, T("Couldn't create blog post"))) return new HttpUnauthorizedResult(); - var blogPost = Services.ContentManager.New("BlogPost"); - if (blogPost.BlogPart == null) + var blog = _blogService.Get(blogId, VersionOptions.Latest).As(); + if (blog == null) return HttpNotFound(); + var blogPost = Services.ContentManager.New("BlogPost"); + blogPost.BlogPart = blog; + Services.ContentManager.Create(blogPost, VersionOptions.Draft); var model = Services.ContentManager.UpdateEditor(blogPost, this); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPostPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPostPartDriver.cs index 6b46a06ff..61f1f6976 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPostPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPostPartDriver.cs @@ -6,7 +6,7 @@ using Orchard.Core.Feeds; using Orchard.Localization; namespace Orchard.Blogs.Drivers { - [UsedImplicitly] + [UsedImplicitly] public class BlogPostPartDriver : ContentPartDriver { private readonly IFeedManager _feedManager; public IOrchardServices Services { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs index 281cc498f..c4456d86c 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Web.Routing; using JetBrains.Annotations; @@ -6,53 +5,28 @@ using Orchard.Blogs.Models; using Orchard.Blogs.Services; using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; +using Orchard.Core.Common.Models; using Orchard.Core.Routable.Models; namespace Orchard.Blogs.Handlers { [UsedImplicitly] public class BlogPostPartHandler : ContentHandler { + private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; public BlogPostPartHandler(IBlogService blogService, IBlogPostService blogPostService, RequestContext requestContext) { + _blogService = blogService; _blogPostService = blogPostService; - Action updateBlogPostCount = - (blog => { - // Ensure we get the "right" set of published posts for the blog - blog.ContentItem.ContentManager.Flush(); - - var postsCount = _blogPostService.Get(blog, VersionOptions.Published).Count(); - blog.PostCount = postsCount; - }); - OnGetDisplayShape(SetModelProperties); OnGetEditorShape(SetModelProperties); OnUpdateEditorShape(SetModelProperties); - OnInitializing((context, bp) => { - var blogId = requestContext.RouteData.Values.ContainsKey("blogId") ? requestContext.RouteData.Values["blogId"] as string : null; - if (!string.IsNullOrEmpty(blogId)) { - var blog = blogService.Get(int.Parse(blogId), VersionOptions.Latest); - bp.BlogPart = blog.As(); - return; - } - - //todo: don't get at the container form data directly. right now the container is set in the common driver editor (updater) - //todo: which is too late for what's needed (currently) in this handler - var containerId = requestContext.HttpContext.Request.Form["CommonPart.containerId"]; - if (!string.IsNullOrEmpty(containerId)) { - int cId; - if (int.TryParse(containerId, out cId)) { - bp.BlogPart = context.ContentItem.ContentManager.Get(cId).As(); - return; - } - } - }); - OnCreated((context, bp) => updateBlogPostCount(bp.BlogPart)); - OnPublished((context, bp) => updateBlogPostCount(bp.BlogPart)); - OnUnpublished((context, bp) => updateBlogPostCount(bp.BlogPart)); - OnVersioned((context, bp1, bp2) => updateBlogPostCount(bp1.BlogPart)); - OnRemoved((context, bp) => updateBlogPostCount(bp.BlogPart)); + OnCreated((context, part) => UpdateBlogPostCount(part)); + OnPublished((context, part) => UpdateBlogPostCount(part)); + OnUnpublished((context, part) => UpdateBlogPostCount(part)); + OnVersioned((context, part, newVersionPart) => UpdateBlogPostCount(newVersionPart)); + OnRemoved((context, part) => UpdateBlogPostCount(part)); OnRemoved( (context, b) => @@ -60,6 +34,20 @@ namespace Orchard.Blogs.Handlers { blogPost => context.ContentManager.Remove(blogPost.ContentItem))); } + private void UpdateBlogPostCount(BlogPostPart blogPostPart) { + CommonPart commonPart = blogPostPart.As(); + if (commonPart != null && + commonPart.Record.Container != null) { + + BlogPart blogPart = blogPostPart.BlogPart ?? + _blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As(); + + // Ensure the "right" set of published posts for the blog is obtained + blogPart.ContentItem.ContentManager.Flush(); + blogPart.PostCount = _blogPostService.Get(blogPart, VersionOptions.Published).Count(); + } + } + private static void SetModelProperties(BuildShapeContext context, BlogPostPart blogPost) { context.Shape.Blog = blogPost.BlogPart; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs index 21730ac3c..3215e4417 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs @@ -4,7 +4,7 @@ using Orchard.ContentManagement; namespace Orchard.Blogs.Services { public interface IBlogService : IDependency { - BlogPart Get(string slug); + BlogPart Get(string path); ContentItem Get(int id, VersionOptions versionOptions); IEnumerable Get(); IEnumerable Get(VersionOptions versionOptions); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs index bf06b98ac..fd1d5afcb 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs @@ -58,7 +58,6 @@ namespace Orchard.Blogs.Services { if (context.Request.MethodName == "blogger.getUsersBlogs") { var result = MetaWeblogGetUserBlogs(urlHelper, - Convert.ToString(context.Request.Params[0].Value), Convert.ToString(context.Request.Params[1].Value), Convert.ToString(context.Request.Params[2].Value)); @@ -111,33 +110,30 @@ namespace Orchard.Blogs.Services { if (context.Request.MethodName == "blogger.deletePost") { var result = MetaWeblogDeletePost( - Convert.ToString(context.Request.Params[0].Value), Convert.ToString(context.Request.Params[1].Value), Convert.ToString(context.Request.Params[2].Value), Convert.ToString(context.Request.Params[3].Value), - Convert.ToBoolean(context.Request.Params[4].Value), context._drivers); context.Response = new XRpcMethodResponse().Add(result); } } private XRpcArray MetaWeblogGetUserBlogs(UrlHelper urlHelper, - string appkey, string userName, string password) { IUser user = ValidateUser(userName, password); - // User needs to at least have permission to edit its own blog posts to access the service - _authorizationService.CheckAccess(Permissions.EditOwnBlogPost, user, null); - XRpcArray array = new XRpcArray(); foreach (BlogPart blog in _blogService.Get()) { - BlogPart blogPart = blog; - array.Add(new XRpcStruct() - .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blogPart))) - .Set("blogid", blog.Id) - .Set("blogName", blog.Name)); + // Check if user has permissions for each specific blog + if (_authorizationService.TryCheckAccess(Permissions.EditOthersBlogPost, user, blog)) { + BlogPart blogPart = blog; + array.Add(new XRpcStruct() + .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blogPart))) + .Set("blogid", blog.Id) + .Set("blogName", blog.Name)); + } } return array; @@ -215,7 +211,7 @@ namespace Orchard.Blogs.Services { blogPost.As().Path = blogPost.As().GetPathWithSlug(blogPost.As().Slug); } - _contentManager.Create(blogPost.ContentItem, VersionOptions.Draft); + _contentManager.Create(blogPost, VersionOptions.Draft); var publishedUtc = content.Optional("dateCreated"); if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow)) @@ -249,7 +245,14 @@ namespace Orchard.Blogs.Services { return postStruct; } - private bool MetaWeblogEditPost(int postId, string userName, string password, XRpcStruct content, bool publish, IEnumerable drivers) { + private bool MetaWeblogEditPost( + int postId, + string userName, + string password, + XRpcStruct content, + bool publish, + IEnumerable drivers) { + IUser user = ValidateUser(userName, password); var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired); if (blogPost == null) @@ -284,7 +287,12 @@ namespace Orchard.Blogs.Services { return true; } - private bool MetaWeblogDeletePost(string appkey, string postId, string userName, string password, bool publish, IEnumerable drivers) { + private bool MetaWeblogDeletePost( + string postId, + string userName, + string password, + IEnumerable drivers) { + IUser user = ValidateUser(userName, password); var blogPost = _blogPostService.Get(Convert.ToInt32(postId), VersionOptions.Latest); if (blogPost == null) @@ -308,7 +316,10 @@ namespace Orchard.Blogs.Services { return user; } - private static XRpcStruct CreateBlogStruct(BlogPostPart blogPostPart, UrlHelper urlHelper) { + private static XRpcStruct CreateBlogStruct( + BlogPostPart blogPostPart, + UrlHelper urlHelper) { + var url = urlHelper.AbsoluteAction(() => urlHelper.BlogPost(blogPostPart)); var blogStruct = new XRpcStruct() .Set("postid", blogPostPart.Id) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Placement.info b/src/Orchard.Web/Modules/Orchard.Comments/Placement.info index e0fc46077..f6682d551 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Placement.info +++ b/src/Orchard.Web/Modules/Orchard.Comments/Placement.info @@ -13,9 +13,9 @@ - + - + diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Handlers/LocalizationPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Localization/Handlers/LocalizationPartHandler.cs index fd629a987..c6077e34f 100644 --- a/src/Orchard.Web/Modules/Orchard.Localization/Handlers/LocalizationPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Localization/Handlers/LocalizationPartHandler.cs @@ -19,7 +19,10 @@ namespace Orchard.Localization.Handlers { Filters.Add(StorageFilter.For(localizedRepository)); - OnInitializing(InitializePart); + OnActivated(PropertySetHandlers); + + OnLoading((context, part) => LazyLoadHandlers(part)); + OnVersioning((context, part, versionedPart) => LazyLoadHandlers(versionedPart)); OnIndexed((context, localized) => context.DocumentIndex .Add("culture", CultureInfo.GetCultureInfo(localized.Culture != null ? localized.Culture.Culture : _cultureManager.GetSiteCulture()).LCID) @@ -29,18 +32,24 @@ namespace Orchard.Localization.Handlers { public Localizer T { get; set; } - void InitializePart(InitializingContentContext context, LocalizationPart localizationPart) { + protected static void PropertySetHandlers(ActivatedContentContext context, LocalizationPart localizationPart) { localizationPart.CultureField.Setter(cultureRecord => { localizationPart.Record.CultureId = cultureRecord.Id; return cultureRecord; }); + localizationPart.MasterContentItemField.Setter(masterContentItem => { localizationPart.Record.MasterContentItemId = masterContentItem.ContentItem.Id; return masterContentItem; - }); - localizationPart.CultureField.Loader(ctx => _cultureManager.GetCultureById(localizationPart.Record.CultureId)); + }); + } + + protected void LazyLoadHandlers(LocalizationPart localizationPart) { + localizationPart.CultureField.Loader(ctx => + _cultureManager.GetCultureById(localizationPart.Record.CultureId)); + localizationPart.MasterContentItemField.Loader(ctx => _contentManager.Get(localizationPart.Record.MasterContentItemId, localizationPart.IsPublished() ? VersionOptions.Published : VersionOptions.Latest)); } } -} \ No newline at end of file +} diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/Handlers/PublishLaterPartHandler.cs b/src/Orchard.Web/Modules/Orchard.PublishLater/Handlers/PublishLaterPartHandler.cs index 19bcb38fb..8f8183cc5 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/Handlers/PublishLaterPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/Handlers/PublishLaterPartHandler.cs @@ -1,5 +1,4 @@ -using Orchard.ContentManagement; -using Orchard.ContentManagement.Handlers; +using Orchard.ContentManagement.Handlers; using Orchard.PublishLater.Models; using Orchard.PublishLater.Services; @@ -10,7 +9,12 @@ namespace Orchard.PublishLater.Handlers { public PublishLaterPartHandler(IPublishLaterService publishLaterService) { _publishLaterService = publishLaterService; - OnLoaded((context, publishLater) => publishLater.ScheduledPublishUtc.Loader(delegate { return _publishLaterService.GetScheduledPublishUtc(publishLater.As()); })); + OnLoading((context, part) => LazyLoadHandlers(part)); + OnVersioning((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart)); + } + + protected void LazyLoadHandlers(PublishLaterPart part) { + part.ScheduledPublishUtc.Loader((value) => _publishLaterService.GetScheduledPublishUtc(part)); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs index 9ec4b0bcb..af7fad3e8 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Handlers/UserRolesPartHandler.cs @@ -19,6 +19,5 @@ namespace Orchard.Roles.Handlers { .Select(x => x.Role.Name).ToList(); }); } - } } \ No newline at end of file diff --git a/src/Orchard/Caching/CacheModule.cs b/src/Orchard/Caching/CacheModule.cs index bba898374..8360eed28 100644 --- a/src/Orchard/Caching/CacheModule.cs +++ b/src/Orchard/Caching/CacheModule.cs @@ -17,7 +17,7 @@ namespace Orchard.Caching { .Any(xx => xx.ParameterType == typeof(ICacheManager))); if (needsCacheManager) { - registration.Preparing += (sender, e) => { + registration.Preparing += (sender, e) => { var parameter = new TypedParameter( typeof(ICacheManager), e.Context.Resolve(new TypedParameter(typeof(Type), registration.Activator.LimitType))); diff --git a/src/Orchard/ContentManagement/IContentManager.cs b/src/Orchard/ContentManagement/IContentManager.cs index 127b07de3..84223c9aa 100644 --- a/src/Orchard/ContentManagement/IContentManager.cs +++ b/src/Orchard/ContentManagement/IContentManager.cs @@ -38,12 +38,39 @@ namespace Orchard.ContentManagement { } public class VersionOptions { + /// + /// Gets the latest version. + /// public static VersionOptions Latest { get { return new VersionOptions { IsLatest = true }; } } + + /// + /// Gets the latest published version. + /// public static VersionOptions Published { get { return new VersionOptions { IsPublished = true }; } } + + /// + /// Gets the latest draft version. + /// public static VersionOptions Draft { get { return new VersionOptions { IsDraft = true }; } } + + /// + /// Gets the latest version and creates a new version draft based on it. + /// public static VersionOptions DraftRequired { get { return new VersionOptions { IsDraft = true, IsDraftRequired = true }; } } + + /// + /// Gets all versions. + /// public static VersionOptions AllVersions { get { return new VersionOptions { IsAllVersions = true }; } } + + /// + /// Gets a specific version based on its number. + /// public static VersionOptions Number(int version) { return new VersionOptions { VersionNumber = version }; } + + /// + /// Gets a specific version based on the version record identifier. + /// public static VersionOptions VersionRecord(int id) { return new VersionOptions { VersionRecordId = id }; } public bool IsLatest { get; private set; }