From 898bed466a5350fdf9032e720f5bc11c2528278c Mon Sep 17 00:00:00 2001 From: randompete Date: Wed, 7 Dec 2011 01:29:41 +0000 Subject: [PATCH] Starting to untether blog routes --HG-- branch : autoroute --- .../Controllers/BlogPostController.cs | 23 ++---------- .../Orchard.Blogs/Handlers/BlogPartHandler.cs | 23 +----------- .../Modules/Orchard.Blogs/Routes.cs | 35 ------------------- .../Services/IBlogPostService.cs | 1 + 4 files changed, 4 insertions(+), 78 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs index 7a6b7e571..f2c769d91 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs @@ -36,25 +36,9 @@ namespace Orchard.Blogs.Controllers { dynamic Shape { get; set; } public Localizer T { get; set; } - //TODO: (erikpo) Should think about moving the slug parameters and get calls and null checks up into a model binder or action filter - public ActionResult Item(string blogPath, string postSlug) { + public ActionResult ListByArchive(int blogId, string archiveData) { //TODO: (erikpo) Move looking up the current blog up into a modelbinder - var blogPart = _blogService.Get(blogPath); - if (blogPart == null) - return HttpNotFound(); - - //TODO: (erikpo) Look up the current user and their permissions to this blog post and determine if they should be able to view it or not. - var postPart = _blogPostService.Get(blogPart, postSlug, VersionOptions.Published); - if (postPart == null) - return HttpNotFound(); - - dynamic model = _services.ContentManager.BuildDisplay(postPart); - return new ShapeResult(this, model); - } - - public ActionResult ListByArchive(string blogPath, string archiveData) { - //TODO: (erikpo) Move looking up the current blog up into a modelbinder - BlogPart blogPart = _blogService.Get(blogPath); + BlogPart blogPart = _blogService.Get(blogId,VersionOptions.Published).As(); if (blogPart == null) return HttpNotFound(); @@ -71,9 +55,6 @@ namespace Orchard.Blogs.Controllers { .Blog(blogPart) .ArchiveData(archive); - //todo: (heskew) add back - //.ArchiveData(archive) <-- ?? - // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return View((object)viewModel); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs index 133f46880..46f06c473 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs @@ -16,28 +16,11 @@ namespace Orchard.Blogs.Handlers { [UsedImplicitly] public class BlogPartHandler : ContentHandler { private readonly IWorkContextAccessor _workContextAccessor; - private readonly IBlogPathConstraint _blogPathConstraint; - private readonly IHomePageProvider _routableHomePageProvider; public BlogPartHandler(IRepository repository, IWorkContextAccessor workContextAccessor, IEnumerable homePageProviders, IBlogPathConstraint blogPathConstraint) { _workContextAccessor = workContextAccessor; - _blogPathConstraint = blogPathConstraint; - _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name); Filters.Add(StorageFilter.For(repository)); - Action publishedHandler = (context, route) => { - if (route.Is()) { - if (route.ContentItem.Id != 0 && route.PromoteToHomePage) - _blogPathConstraint.AddPath(""); - } - else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) { - _blogPathConstraint.RemovePath(""); - } - }; - - OnPublished(publishedHandler); - OnUnpublished(publishedHandler); - OnGetDisplayShape((context, blog) => { context.Shape.Description = blog.Description; context.Shape.PostCount = blog.PostCount; @@ -50,15 +33,11 @@ namespace Orchard.Blogs.Handlers { if (blog == null) return; - var blogPath = blog.Id == _routableHomePageProvider.GetHomePageId(_workContextAccessor.GetContext().CurrentSite.HomePage) - ? "" - : blog.As().Path; - context.Metadata.DisplayRouteValues = new RouteValueDictionary { {"Area", "Orchard.Blogs"}, {"Controller", "Blog"}, {"Action", "Item"}, - {"blogPath", blogPath} + {"blogId", context.ContentItem.Id} }; context.Metadata.CreateRouteValues = new RouteValueDictionary { {"Area", "Orchard.Blogs"}, diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs index aa8db7621..9d8548959 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs @@ -223,41 +223,6 @@ namespace Orchard.Blogs { {"area", "Orchard.Blogs"} }, new MvcRouteHandler()) - }, - new RouteDescriptor { - Priority = 11, - Route = new Route( - "{blogPath}/{postSlug}", - new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "Item"} - }, - new RouteValueDictionary { - {"blogPath", _blogPathConstraint} - }, - new RouteValueDictionary { - {"area", "Orchard.Blogs"} - }, - new MvcRouteHandler()) - }, - new RouteDescriptor { - Priority = 11, - Route = new Route( - "{blogPath}", - new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "Blog"}, - {"action", "Item"}, - {"blogPath", ""} - }, - new RouteValueDictionary { - {"blogPath", _blogPathConstraint} - }, - new RouteValueDictionary { - {"area", "Orchard.Blogs"} - }, - new MvcRouteHandler()) } }; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogPostService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogPostService.cs index 6bce07c57..468d59d6a 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogPostService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogPostService.cs @@ -22,5 +22,6 @@ namespace Orchard.Blogs.Services { void Publish(BlogPostPart blogPostPart, DateTime scheduledPublishUtc); void Unpublish(BlogPostPart blogPostPart); DateTime? GetScheduledPublishUtc(BlogPostPart blogPostPart); + } } \ No newline at end of file