mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Starting to untether blog routes
--HG-- branch : autoroute
This commit is contained in:
@@ -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<BlogPart>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<BlogPartRecord> repository, IWorkContextAccessor workContextAccessor, IEnumerable<IHomePageProvider> homePageProviders, IBlogPathConstraint blogPathConstraint) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
||||
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) => {
|
||||
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<RoutePart>().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"},
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,5 +22,6 @@ namespace Orchard.Blogs.Services {
|
||||
void Publish(BlogPostPart blogPostPart, DateTime scheduledPublishUtc);
|
||||
void Unpublish(BlogPostPart blogPostPart);
|
||||
DateTime? GetScheduledPublishUtc(BlogPostPart blogPostPart);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user