Starting to untether blog routes

--HG--
branch : autoroute
This commit is contained in:
randompete
2011-12-07 01:29:41 +00:00
parent ad3c8ee80d
commit 898bed466a
4 changed files with 4 additions and 78 deletions
@@ -36,25 +36,9 @@ namespace Orchard.Blogs.Controllers {
dynamic Shape { get; set; } dynamic Shape { get; set; }
public Localizer T { 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 ListByArchive(int blogId, string archiveData) {
public ActionResult Item(string blogPath, string postSlug) {
//TODO: (erikpo) Move looking up the current blog up into a modelbinder //TODO: (erikpo) Move looking up the current blog up into a modelbinder
var blogPart = _blogService.Get(blogPath); BlogPart blogPart = _blogService.Get(blogId,VersionOptions.Published).As<BlogPart>();
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);
if (blogPart == null) if (blogPart == null)
return HttpNotFound(); return HttpNotFound();
@@ -71,9 +55,6 @@ namespace Orchard.Blogs.Controllers {
.Blog(blogPart) .Blog(blogPart)
.ArchiveData(archive); .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. // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
return View((object)viewModel); return View((object)viewModel);
} }
@@ -16,28 +16,11 @@ namespace Orchard.Blogs.Handlers {
[UsedImplicitly] [UsedImplicitly]
public class BlogPartHandler : ContentHandler { public class BlogPartHandler : ContentHandler {
private readonly IWorkContextAccessor _workContextAccessor; private readonly IWorkContextAccessor _workContextAccessor;
private readonly IBlogPathConstraint _blogPathConstraint;
private readonly IHomePageProvider _routableHomePageProvider;
public BlogPartHandler(IRepository<BlogPartRecord> repository, IWorkContextAccessor workContextAccessor, IEnumerable<IHomePageProvider> homePageProviders, IBlogPathConstraint blogPathConstraint) { public BlogPartHandler(IRepository<BlogPartRecord> repository, IWorkContextAccessor workContextAccessor, IEnumerable<IHomePageProvider> homePageProviders, IBlogPathConstraint blogPathConstraint) {
_workContextAccessor = workContextAccessor; _workContextAccessor = workContextAccessor;
_blogPathConstraint = blogPathConstraint;
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
Filters.Add(StorageFilter.For(repository)); Filters.Add(StorageFilter.For(repository));
Action<PublishContentContext, RoutePart> publishedHandler = (context, route) => {
if (route.Is<BlogPart>()) {
if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
_blogPathConstraint.AddPath("");
}
else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) {
_blogPathConstraint.RemovePath("");
}
};
OnPublished<RoutePart>(publishedHandler);
OnUnpublished<RoutePart>(publishedHandler);
OnGetDisplayShape<BlogPart>((context, blog) => { OnGetDisplayShape<BlogPart>((context, blog) => {
context.Shape.Description = blog.Description; context.Shape.Description = blog.Description;
context.Shape.PostCount = blog.PostCount; context.Shape.PostCount = blog.PostCount;
@@ -50,15 +33,11 @@ namespace Orchard.Blogs.Handlers {
if (blog == null) if (blog == null)
return; return;
var blogPath = blog.Id == _routableHomePageProvider.GetHomePageId(_workContextAccessor.GetContext().CurrentSite.HomePage)
? ""
: blog.As<RoutePart>().Path;
context.Metadata.DisplayRouteValues = new RouteValueDictionary { context.Metadata.DisplayRouteValues = new RouteValueDictionary {
{"Area", "Orchard.Blogs"}, {"Area", "Orchard.Blogs"},
{"Controller", "Blog"}, {"Controller", "Blog"},
{"Action", "Item"}, {"Action", "Item"},
{"blogPath", blogPath} {"blogId", context.ContentItem.Id}
}; };
context.Metadata.CreateRouteValues = new RouteValueDictionary { context.Metadata.CreateRouteValues = new RouteValueDictionary {
{"Area", "Orchard.Blogs"}, {"Area", "Orchard.Blogs"},
@@ -223,41 +223,6 @@ namespace Orchard.Blogs {
{"area", "Orchard.Blogs"} {"area", "Orchard.Blogs"}
}, },
new MvcRouteHandler()) 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())
} }
}; };
} }
@@ -22,5 +22,6 @@ namespace Orchard.Blogs.Services {
void Publish(BlogPostPart blogPostPart, DateTime scheduledPublishUtc); void Publish(BlogPostPart blogPostPart, DateTime scheduledPublishUtc);
void Unpublish(BlogPostPart blogPostPart); void Unpublish(BlogPostPart blogPostPart);
DateTime? GetScheduledPublishUtc(BlogPostPart blogPostPart); DateTime? GetScheduledPublishUtc(BlogPostPart blogPostPart);
} }
} }