From 7a23c5dab41d0bbbb07573a70f8a85704256fe42 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 31 Jan 2012 10:10:19 -0800 Subject: [PATCH 1/4] Removing autoroute from Orchard.Tags --HG-- branch : autoroute --- .../Modules/Orchard.Tags/Orchard.Tags.csproj | 6 -- .../Orchard.Tags/Providers/TagPatterns.cs | 73 ------------------- .../Orchard.Tags/Providers/TagTokens.cs | 33 --------- 3 files changed, 112 deletions(-) delete mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Providers/TagPatterns.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Providers/TagTokens.cs diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj index 8a233b992..d770b535c 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj +++ b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj @@ -61,8 +61,6 @@ Code - - @@ -106,10 +104,6 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core - - {6F759635-13D7-4E94-BCC9-80445D63F117} - Orchard.Tokens - diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagPatterns.cs b/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagPatterns.cs deleted file mode 100644 index f8e6b84b6..000000000 --- a/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagPatterns.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Orchard.Tags.Services; -using Orchard.Localization; -using Orchard.Tags.Models; -using System.Web.Routing; -using Orchard.Events; - -namespace Orchard.Tags.Providers { - - public interface IRoutePatternProvider : IEventHandler { - void Describe(dynamic describe); - void Suggest(dynamic suggest); - } - public class TagPatterns : IRoutePatternProvider { - - private readonly ITagService _tagService; - - public TagPatterns( - ITagService tagService - ) { - _tagService = tagService; - T = NullLocalizer.Instance; - } - - public Localizer T { get; set; } - - public void Describe(dynamic describe) { - describe.For("Tags", T("Tags"), T("Tags url patterns"), (Func)GetId, (Func)GetTag, (Func>)GetContext) - .Pattern("Tags", T("View all tags"), T("A list of all tags are displayed on this page"), (Func)GetTagsRouteValues) - .Pattern("View", T("View tagged content"), T("Tagged content will be listed on this Url for each tag"), (Func)GetRouteValues); - } - - public RouteValueDictionary GetRouteValues(TagRecord tag) { - return new RouteValueDictionary(new{ - area = "Orchard.Tags", - controller = "Home", - action = "Search", - tagName = tag.TagName - }); - } - - public RouteValueDictionary GetTagsRouteValues(TagRecord tag) { - return new RouteValueDictionary(new { - area = "Orchard.Tags", - controller = "Home", - action = "Index" - }); - } - - public IDictionary GetContext(TagRecord tag) { - return new Dictionary { { "Tag", tag } }; - } - - public string GetId(TagRecord tag) { - return tag.Id.ToString(); - } - - public TagRecord GetTag(string id) { - return _tagService.GetTag(Convert.ToInt32(id)); - } - - public void Suggest(dynamic suggest) { - suggest.For("Tags") - .Suggest("View", "tags/tag-name", "{Tag.Name.Slug}", T("Slugified tag name")) - .Suggest("Tags", "tags", "tags", T("Plain /tags url")); - } - - - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagTokens.cs b/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagTokens.cs deleted file mode 100644 index 74b6f71ef..000000000 --- a/src/Orchard.Web/Modules/Orchard.Tags/Providers/TagTokens.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Orchard.Tokens; -using Orchard.Localization; -using Orchard.Tags.Models; - -namespace Orchard.Tags.Providers { - public class TagTokens : ITokenProvider { - - public TagTokens() { - - T = NullLocalizer.Instance; - - } - public Localizer T { get; set; } - public void Describe(DescribeContext context) { - - context.For("Tag", T("Tags"), T("Tag records")) - .Token("Name", T("Tag name"), T("Tag name"), "Text"); - - } - - public void Evaluate(EvaluateContext context) { - context.For("Tag") - .Token("", t => t.TagName) - .Token("Name", t => t.TagName) - // By chaining the name to text it can be slugified in Autoroute - .Chain("Name", "Text", t => t.TagName); - } - } -} \ No newline at end of file From 49cdb191fd07a689c4b7f822462db9b2b01326a2 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 31 Jan 2012 14:24:46 -0800 Subject: [PATCH 2/4] Handling Rsd and Archives --HG-- branch : autoroute --- .hgsubstate | 12 +-- .../Controllers/BlogAdminController.cs | 3 +- .../Controllers/BlogController.cs | 16 ++-- .../Controllers/BlogPostController.cs | 4 +- .../RemoteBlogPublishingController.cs | 4 +- .../Drivers/BlogArchivesPartDriver.cs | 18 ++-- .../Drivers/RecentBlogPostsPartDriver.cs | 13 ++- .../Extensions/UrlHelperExtensions.cs | 10 +- .../Orchard.Blogs/Handlers/BlogPartHandler.cs | 15 +-- .../Handlers/BlogPostPartHandler.cs | 2 - .../Modules/Orchard.Blogs/Migrations.cs | 21 +--- .../Orchard.Blogs/Models/BlogArchivesPart.cs | 6 +- .../Models/BlogArchivesPartRecord.cs | 5 +- .../Models/RecentBlogPostsPart.cs | 6 +- .../Models/RecentBlogPostsPartRecord.cs | 5 +- .../Orchard.Blogs/Orchard.Blogs.csproj | 13 ++- .../Orchard.Blogs/Providers/BlogAutoroutes.cs | 96 ------------------- .../Modules/Orchard.Blogs/Routes.cs | 59 +++++++++++- .../Routing/BlogPathConstraint.cs | 66 +++++++++++++ .../Routing/BlogPathConstraintUpdator.cs | 35 +++++++ .../Routing/IBlogPathConstraint.cs | 11 +++ .../Routing/IsArchiveConstraint.cs | 23 +++++ .../Orchard.Blogs/Services/BlogService.cs | 14 ++- .../Orchard.Blogs/Services/IBlogService.cs | 2 +- .../ViewModels/BlogArchivesViewModel.cs | 2 +- .../ViewModels/RecentBlogPostsViewModel.cs | 2 +- .../ModuleAssemblyInfo.txt | 2 + .../Orchard.Tags/Properties/AssemblyInfo.cs | 1 + .../Themes/Properties/AssemblyInfo.cs | 2 + .../Exceptions/DefaultExceptionPolicy.cs | 5 +- 30 files changed, 284 insertions(+), 189 deletions(-) delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Providers/BlogAutoroutes.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/IBlogPathConstraint.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs diff --git a/.hgsubstate b/.hgsubstate index ec5950b62..92b912f9a 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1,9 +1,9 @@ -d91108343ff1259cd3e35b2c080eb166d024711b src/Orchard.Web/Modules/Orchard.Alias -0b87c2916b43a87addfa534470c3bd7a47be662a src/Orchard.Web/Modules/Orchard.Autoroute -67bf9897ee9dd9483369aece729ad7c6f042941c src/Orchard.Web/Modules/Orchard.Forms -6033664adc404a22f311029b69fbf1e34dc4ff2a src/Orchard.Web/Modules/Orchard.Projections +81cb672c85fd980dd3db0515544b79a918e5eb69 src/Orchard.Web/Modules/Orchard.Alias +a3329c82a2636eb166c46f3cfdadd18eca4e4d7f src/Orchard.Web/Modules/Orchard.Autoroute +c54cb640d6bc14c51b9fb9bd78231bb0facec067 src/Orchard.Web/Modules/Orchard.Forms +c27801666ed3e8f9b9c7979a837e7d770763352a src/Orchard.Web/Modules/Orchard.Projections a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable f2a3984789ebe5caf2822ccb9e1d2c953add9c35 src/Orchard.Web/Modules/Orchard.Rules ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease -42d34730d8bb22052585ca94e3e945111aea3b9d src/Orchard.Web/Modules/Orchard.Tokens -08eadecb5e5fae52e8b4c7d1c60f29e51c63b2ca src/orchard.web/modules/Orchard.Fields +2373765b3f1f4171b09b1458f7dce9e8b83db0a2 src/Orchard.Web/Modules/Orchard.Tokens +d8a83a676cb3b9d0266ec83ac6a1e8562821d82b src/orchard.web/modules/Orchard.Fields diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs index c143e6fd1..73d41861d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs @@ -1,11 +1,10 @@ using System.Linq; -using System.Reflection; using System.Web.Mvc; using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; +using Orchard.Blogs.Routing; using Orchard.Blogs.Services; using Orchard.ContentManagement; -using Orchard.ContentManagement.Aspects; using Orchard.Data; using Orchard.DisplayManagement; using Orchard.Localization; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs index 264855789..4e64cc540 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs @@ -1,13 +1,12 @@ -using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Orchard.Blogs.Extensions; +using Orchard.Blogs.Routing; using Orchard.Blogs.Services; using Orchard.Core.Feeds; using Orchard.DisplayManagement; using Orchard.Logging; using Orchard.Mvc; -using Orchard.Services; using Orchard.Themes; using Orchard.UI.Navigation; using Orchard.Settings; @@ -21,23 +20,23 @@ namespace Orchard.Blogs.Controllers { private readonly IOrchardServices _services; private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; + private readonly IBlogPathConstraint _blogPathConstraint; private readonly IFeedManager _feedManager; - private readonly IWorkContextAccessor _workContextAccessor; private readonly ISiteService _siteService; public BlogController( IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, + IBlogPathConstraint blogPathConstraint, IFeedManager feedManager, IShapeFactory shapeFactory, - IWorkContextAccessor workContextAccessor, ISiteService siteService) { _services = services; _blogService = blogService; _blogPostService = blogPostService; + _blogPathConstraint = blogPathConstraint; _feedManager = feedManager; - _workContextAccessor = workContextAccessor; _siteService = siteService; Logger = NullLogger.Instance; Shape = shapeFactory; @@ -59,11 +58,14 @@ namespace Orchard.Blogs.Controllers { return View((object)viewModel); } - public ActionResult Item(int blogId, PagerParameters pagerParameters) { + public ActionResult Item(string blogPath, PagerParameters pagerParameters) { // TODO: (PH:Autoroute) Should use Containers so we can lose this action and rely on ContainerPartDriver instead Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); + var correctedPath = _blogPathConstraint.FindPath(blogPath); + if (correctedPath == null) + return HttpNotFound(); - var blogPart = _blogService.Get(blogId, VersionOptions.Published).As(); + var blogPart = _blogService.Get(correctedPath); if (blogPart == null) return HttpNotFound(); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs index f2c769d91..886643be6 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs @@ -36,9 +36,9 @@ namespace Orchard.Blogs.Controllers { dynamic Shape { get; set; } public Localizer T { get; set; } - public ActionResult ListByArchive(int blogId, string archiveData) { + public ActionResult ListByArchive(string blogPath, string archiveData) { //TODO: (erikpo) Move looking up the current blog up into a modelbinder - BlogPart blogPart = _blogService.Get(blogId,VersionOptions.Published).As(); + BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) return HttpNotFound(); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs index f5da96177..3209438bc 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs @@ -21,10 +21,10 @@ namespace Orchard.Blogs.Controllers { protected ILogger Logger { get; set; } - public ActionResult Rsd(int blogId) { + public ActionResult Rsd(string blogPath) { Logger.Debug("RSD requested"); - BlogPart blogPart = _blogService.Get(blogId); + BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) return HttpNotFound(); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogArchivesPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogArchivesPartDriver.cs index a6a7ed12f..bd68b8744 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogArchivesPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogArchivesPartDriver.cs @@ -5,21 +5,17 @@ using Orchard.Blogs.ViewModels; using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Handlers; -using System; namespace Orchard.Blogs.Drivers { public class BlogArchivesPartDriver : ContentPartDriver { private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; - private readonly IContentManager _contentManager; public BlogArchivesPartDriver( IBlogService blogService, - IBlogPostService blogPostService, - IContentManager contentManager) { + IBlogPostService blogPostService) { _blogService = blogService; _blogPostService = blogPostService; - _contentManager = contentManager; } protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) { @@ -36,7 +32,7 @@ namespace Orchard.Blogs.Drivers { protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) { var viewModel = new BlogArchivesViewModel { - BlogId = part.ForBlog, + Slug = part.ForBlog, Blogs = _blogService.Get().ToList().OrderBy(b => b.Name) }; @@ -47,21 +43,21 @@ namespace Orchard.Blogs.Drivers { protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) { var viewModel = new BlogArchivesViewModel(); if (updater.TryUpdateModel(viewModel, Prefix, null, null)) { - part.ForBlog = viewModel.BlogId; + part.ForBlog = viewModel.Slug; } return Editor(part, shapeHelper); } protected override void Importing(BlogArchivesPart part, ImportContentContext context) { - var blogId = context.Attribute(part.PartDefinition.Name, "BlogId"); - if (blogId != null) { - part.ForBlog = Convert.ToInt32(blogId); + var blogSlug = context.Attribute(part.PartDefinition.Name, "BlogSlug"); + if (blogSlug != null) { + part.ForBlog = blogSlug; } } protected override void Exporting(BlogArchivesPart part, ExportContentContext context) { - context.Element(part.PartDefinition.Name).SetAttributeValue("BlogId", part.ForBlog); + context.Element(part.PartDefinition.Name).SetAttributeValue("BlogSlug", part.ForBlog); } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RecentBlogPostsPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RecentBlogPostsPartDriver.cs index edc28f565..e06c7e841 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RecentBlogPostsPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RecentBlogPostsPartDriver.cs @@ -46,7 +46,7 @@ namespace Orchard.Blogs.Drivers { protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) { var viewModel = new RecentBlogPostsViewModel { Count = part.Count, - BlogId = part.ForBlog, + Slug = part.ForBlog, Blogs = _blogService.Get().ToList().OrderBy(b => b.Name) }; @@ -57,7 +57,7 @@ namespace Orchard.Blogs.Drivers { protected override DriverResult Editor(RecentBlogPostsPart part, IUpdateModel updater, dynamic shapeHelper) { var viewModel = new RecentBlogPostsViewModel(); if (updater.TryUpdateModel(viewModel, Prefix, null, null)) { - part.ForBlog = viewModel.BlogId; + part.ForBlog = viewModel.Slug; part.Count = viewModel.Count; } @@ -65,9 +65,9 @@ namespace Orchard.Blogs.Drivers { } protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) { - var blogId = context.Attribute(part.PartDefinition.Name, "BlogId"); - if (blogId != null) { - part.ForBlog = Convert.ToInt32(blogId); + var blogSlug = context.Attribute(part.PartDefinition.Name, "BlogSlug"); + if (blogSlug != null) { + part.ForBlog = blogSlug; } var count = context.Attribute(part.PartDefinition.Name, "Count"); @@ -77,9 +77,8 @@ namespace Orchard.Blogs.Drivers { } protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) { - context.Element(part.PartDefinition.Name).SetAttributeValue("BlogId", part.ForBlog); + context.Element(part.PartDefinition.Name).SetAttributeValue("BlogSlug", part.ForBlog); context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count); } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs index 5a0c34fcc..35874e6f1 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs @@ -1,9 +1,9 @@ using System.Web.Mvc; +using Orchard.Autoroute.Models; using Orchard.Blogs.Models; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.Mvc.Extensions; -using Orchard.Mvc.Html; namespace Orchard.Blogs.Extensions { /// @@ -27,19 +27,19 @@ namespace Orchard.Blogs.Extensions { } public static string BlogRsd(this UrlHelper urlHelper, BlogPart blogPart) { - return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "RemoteBlogPublishing", new { blogId = blogPart.ContentItem.Id, area = "Orchard.Blogs" })); + return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "RemoteBlogPublishing", new { blogPath = blogPart.As().Path, area = "Orchard.Blogs" })); } public static string BlogArchiveYear(this UrlHelper urlHelper, BlogPart blogPart, int year) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogId = blogPart.ContentItem.Id, archiveData = year.ToString(), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = year.ToString(), area = "Orchard.Blogs" }); } public static string BlogArchiveMonth(this UrlHelper urlHelper, BlogPart blogPart, int year, int month) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogId = blogPart.ContentItem.Id, archiveData = string.Format("{0:0000}/{1:00}", year, month), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); } public static string BlogArchiveDay(this UrlHelper urlHelper, BlogPart blogPart, int year, int month, int day) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogId = blogPart.ContentItem.Id, archiveData = string.Format("{0:0000}/{1:00}/{2:00}", year, month, day), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs" }); } public static string BlogForAdmin(this UrlHelper urlHelper, BlogPart blogPart) { diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs index af9e1a19e..0a7583a50 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs @@ -1,27 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; using System.Web.Routing; using JetBrains.Annotations; +using Orchard.Autoroute.Models; using Orchard.Blogs.Models; +using Orchard.Blogs.Routing; using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; using Orchard.Data; -using Orchard.Services; namespace Orchard.Blogs.Handlers { [UsedImplicitly] public class BlogPartHandler : ContentHandler { - private readonly IWorkContextAccessor _workContextAccessor; + private readonly IBlogPathConstraint _blogPathConstraint; - public BlogPartHandler(IRepository repository, IWorkContextAccessor workContextAccessor) { - _workContextAccessor = workContextAccessor; + public BlogPartHandler(IRepository repository, IBlogPathConstraint blogPathConstraint) { + _blogPathConstraint = blogPathConstraint; Filters.Add(StorageFilter.For(repository)); OnGetDisplayShape((context, blog) => { context.Shape.Description = blog.Description; context.Shape.PostCount = blog.PostCount; }); + + OnPublished((context, blog) => _blogPathConstraint.AddPath(blog.As().DisplayAlias)); + OnUnpublished((context, blog) => _blogPathConstraint.RemovePath(blog.As().DisplayAlias)); } protected override void GetItemMetadata(GetContentItemMetadataContext context) { diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs index 0f6ecd5d0..f9e3c12bf 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs @@ -57,8 +57,6 @@ namespace Orchard.Blogs.Handlers { if (blogPost == null) return; - // Note: DisplayRouteValues are still inherited from CommonPart. We shouldn't even need these overrides for admin routes. -PH - context.Metadata.CreateRouteValues = new RouteValueDictionary { {"Area", "Orchard.Blogs"}, {"Controller", "BlogPostAdmin"}, diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index a3cb2b5b8..1a8cbff1b 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -106,27 +106,8 @@ namespace Orchard.Blogs { .WithPart("TitlePart") .WithPart("AutoroutePart") ); + return 5; } - public int UpdateFrom5() { - SchemaBuilder.AlterTable("RecentBlogPostsPartRecord", - table => table.AddColumn("BlogId") - ); - - SchemaBuilder.AlterTable("BlogArchivesPartRecord", - table => table.AddColumn("BlogId") - ); - - // TODO: (PH:Autoroute) Convert BlogSlug to BlogId - SchemaBuilder.AlterTable("RecentBlogPostsPartRecord", - table => table.DropColumn("BlogSlug") - ); - - SchemaBuilder.AlterTable("BlogArchivesPartRecord", - table => table.DropColumn("BlogSlug") - ); - - return 6; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPart.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPart.cs index 4bbcdf759..bfa2a2c93 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPart.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPart.cs @@ -7,9 +7,9 @@ namespace Orchard.Blogs.Models { /// public class BlogArchivesPart : ContentPart { [Required] - public int ForBlog { - get { return Record.BlogId; } - set { Record.BlogId = value; } + public string ForBlog { + get { return Record.BlogSlug; } + set { Record.BlogSlug = value; } } } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPartRecord.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPartRecord.cs index a1f089932..5f32a6aa5 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPartRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchivesPartRecord.cs @@ -1,11 +1,10 @@ -using System.ComponentModel.DataAnnotations; -using Orchard.ContentManagement.Records; +using Orchard.ContentManagement.Records; namespace Orchard.Blogs.Models { /// /// The content part used by the BlogArchives widget /// public class BlogArchivesPartRecord : ContentPartRecord { - public virtual int BlogId { get; set; } + public virtual string BlogSlug { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPart.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPart.cs index 98b49b323..a48d2ed3c 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPart.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPart.cs @@ -5,9 +5,9 @@ namespace Orchard.Blogs.Models { public class RecentBlogPostsPart : ContentPart { [Required] - public int ForBlog { - get { return Record.BlogId; } - set { Record.BlogId = value; } + public string ForBlog { + get { return Record.BlogSlug; } + set { Record.BlogSlug = value; } } [Required] diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPartRecord.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPartRecord.cs index f15a3b8d5..43881a8f0 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPartRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/RecentBlogPostsPartRecord.cs @@ -5,7 +5,8 @@ namespace Orchard.Blogs.Models { public RecentBlogPostsPartRecord() { Count = 5; } - public virtual int BlogId { get; set; } + + public virtual string BlogSlug { get; set; } public virtual int Count { get; set; } - } + } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index af9e111e6..9f37e0ee9 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -79,7 +79,10 @@ - + + + + @@ -134,6 +137,14 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core + + {475B6C45-B27C-438B-8966-908B9D6D1077} + Orchard.Alias + + + {66FCCD76-2761-47E3-8D11-B45D0001DDAA} + Orchard.Autoroute + diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Providers/BlogAutoroutes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Providers/BlogAutoroutes.cs deleted file mode 100644 index 7ceb2ad24..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Providers/BlogAutoroutes.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Orchard.Events; -using System.Web.Routing; -using Orchard.ContentManagement; -using Orchard.Blogs.Models; -using Orchard.Core.Common.Models; -using Orchard.Localization; - -namespace Orchard.Blogs.Providers { - - - public interface IRoutePatternProvider : IEventHandler { - void Describe(dynamic describe); - void Suggest(dynamic suggest); - } - - public class BlogAutoroutes : IRoutePatternProvider { - - public BlogAutoroutes() { - T = NullLocalizer.Instance; - } - - public Localizer T { get; set; } - - const string yearToken = "{Content.Date.Format:yyyy}"; - const string monthToken = "{Content.Date.Format:MM}"; - const string dayToken = "{Content.Date.Format:dd}"; - const string idParentToken = "{Content.Container.Id}"; - const string idToken = "{Content.Id}"; - const string blogToken = "{Content.Slug}"; - const string blogPostToken = "{Content.Container.Path}/{Content.Slug}"; - - public void Describe(dynamic describe) { - // TODO: (PH) Could implement RSD for non-blog content much more easily now the routing can be applied to any content item... (maybe need a RemotePublishingPart?) - // TODO: Must restrict these to appropriate parts/types... - describe.For("Content") - .Match((Func)(c => c.Is())) - .Pattern("Rsd", T("Remote Blog Publishing"), T("Remote Blog Publishing destination Url"), - (Func)(c => new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "RemoteBlogPublishing"}, - {"action", "Rsd"}, - {"blogId", idToken}})) - .Pattern("Archive", T("Blog Archives"), T("Displays a list of all blog archives"), - (Func)(c => new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "ListByArchive"}, - {"blogId", idToken}, - {"archiveData", ""} - })) - ; - describe.For("Content") - .Match((Func)(c => c.Is())) - .Pattern("Archive.Year", T("Blog Archives by Year"), T("Displays a list of all blog archives for a particular year"), - (Func)(c=> new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "ListByArchive"}, - {"blogId", idParentToken}, - {"archiveData", String.Format("{0}",yearToken)} - })) - .Pattern("Archive.Month", T("Blog Archives by Month"), T("Displays a list of all blog archives for a particular year and month"), - (Func)(c => new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "ListByArchive"}, - {"blogId", idParentToken}, - {"archiveData", String.Format("{0}/{1}",yearToken,monthToken)} - })) - .Pattern("Archive.Day", T("Blog Archives by Day"), T("Displays a list of all blog archives for a particular date"), - (Func)(c => new RouteValueDictionary { - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "ListByArchive"}, - {"blogId", idParentToken}, - {"archiveData", String.Format("{0}/{1}/{2}",yearToken,monthToken,dayToken)} - })); - } - - public void Suggest(dynamic suggest) { - suggest.For("Content") - .Suggest("Rsd", "blog-title/rsd", blogToken + "/rsd", T("Rsd is a sub-path of the blog post")) - .Suggest("Archives", "blog-title/archives", blogToken + "/archives", T("Archives is a sub-path of the blog post")) - .Suggest("View", "blog-title", blogToken, T("Blog title")) - .Suggest("View", "blog-title/post-title", blogPostToken, T("Nested blog/post path")) - .Suggest("Archive.Year", "blog-title/post-title/archives/yy", String.Format("{0}/archives/{1}",blogPostToken,yearToken), T("Archives year")) - .Suggest("Archive.Month", "blog-title/post-title/archives/yy/mm", String.Format("{0}/archives/{1}/{2}",blogPostToken,yearToken,monthToken), T("Archives year/month")) - .Suggest("Archive.Day", "blog-title/post-title/archives/yy/mm/dd", String.Format("{0}/archives/{1}/{2}/{3}", blogPostToken, yearToken,monthToken,dayToken), T("Archives year/month/day")); - } - - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs index e14d92f18..fae9aa1b3 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs @@ -1,11 +1,15 @@ using System.Collections.Generic; using System.Web.Mvc; using System.Web.Routing; +using Orchard.Blogs.Routing; using Orchard.Mvc.Routes; namespace Orchard.Blogs { public class Routes : IRouteProvider { - public Routes() { + private readonly IBlogPathConstraint _blogPathConstraint; + + public Routes(IBlogPathConstraint blogPathConstraint) { + _blogPathConstraint = blogPathConstraint; } public void GetRoutes(ICollection routes) { @@ -168,7 +172,58 @@ namespace Orchard.Blogs { {"area", "Orchard.Blogs"} }, new MvcRouteHandler()) - } + }, +new RouteDescriptor { + Route = new Route( + "Archive/{*archiveData}", + new RouteValueDictionary { + {"blogPath", ""}, + {"area", "Orchard.Blogs"}, + {"controller", "BlogPost"}, + {"action", "ListByArchive"} + }, + new RouteValueDictionary { + {"archiveData", new IsArchiveConstraint()} + }, + new RouteValueDictionary { + {"area", "Orchard.Blogs"} + }, + new MvcRouteHandler()) + }, + new RouteDescriptor { + Route = new Route( + "{blogPath}/Archive/{*archiveData}", + new RouteValueDictionary { + {"area", "Orchard.Blogs"}, + {"controller", "BlogPost"}, + {"action", "ListByArchive"} + }, + new RouteValueDictionary { + {"blogPath", _blogPathConstraint}, + {"archiveData", new IsArchiveConstraint()} + }, + new RouteValueDictionary { + {"area", "Orchard.Blogs"} + }, + new MvcRouteHandler()) + }, + new RouteDescriptor { + Priority = 11, + Route = new Route( + "{blogPath}/rsd", + new RouteValueDictionary { + {"area", "Orchard.Blogs"}, + {"controller", "RemoteBlogPublishing"}, + {"action", "Rsd"} + }, + new RouteValueDictionary { + {"blogPath", _blogPathConstraint} + }, + new RouteValueDictionary { + {"area", "Orchard.Blogs"} + }, + new MvcRouteHandler()) + }, }; } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs new file mode 100644 index 000000000..9a99df298 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Routing; +using JetBrains.Annotations; +using Orchard.Logging; + +namespace Orchard.Blogs.Routing { + [UsedImplicitly] + public class BlogPathConstraint : IBlogPathConstraint { + private ConcurrentDictionary _paths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + public BlogPathConstraint() { + Logger = NullLogger.Instance; + } + + public ILogger Logger { get; set; } + + public void SetPaths(IEnumerable paths) { + _paths.Clear(); + foreach(var path in paths) { + AddPath(path); + } + + Logger.Debug("Blog paths: {0}", string.Join(", ", paths.ToArray())); + } + + public string FindPath(string path) { + string actual; + // path can be null for homepage + path = path ?? String.Empty; + + return _paths.TryGetValue(path, out actual) ? actual : path; + } + + public void AddPath(string path) { + // path can be null for homepage + path = path ?? String.Empty; + + _paths[path] = path; + } + + public void RemovePath(string path) { + // path can be null for homepage + path = path ?? String.Empty; + + _paths.TryRemove(path, out path); + } + + public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { + if (routeDirection == RouteDirection.UrlGeneration) + return true; + + object value; + if (values.TryGetValue(parameterName, out value)) { + var parameterValue = Convert.ToString(value); + + return _paths.ContainsKey(parameterValue); + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs new file mode 100644 index 000000000..3f7f51bf1 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs @@ -0,0 +1,35 @@ +using System.Linq; +using JetBrains.Annotations; +using Orchard.Autoroute.Models; +using Orchard.Blogs.Services; +using Orchard.ContentManagement; +using Orchard.Environment; +using Orchard.Tasks; + +namespace Orchard.Blogs.Routing { + [UsedImplicitly] + public class BlogPathConstraintUpdator : IOrchardShellEvents, IBackgroundTask { + private readonly IBlogPathConstraint _blogPathConstraint; + private readonly IBlogService _blogService; + + public BlogPathConstraintUpdator(IBlogPathConstraint blogPathConstraint, IBlogService blogService) { + _blogPathConstraint = blogPathConstraint; + _blogService = blogService; + } + + void IOrchardShellEvents.Activated() { + Refresh(); + } + + void IOrchardShellEvents.Terminating() { + } + + void IBackgroundTask.Sweep() { + Refresh(); + } + + private void Refresh() { + _blogPathConstraint.SetPaths(_blogService.Get().Select(b => b.As().DisplayAlias).ToList()); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IBlogPathConstraint.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IBlogPathConstraint.cs new file mode 100644 index 000000000..a3742cb29 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IBlogPathConstraint.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Web.Routing; + +namespace Orchard.Blogs.Routing { + public interface IBlogPathConstraint : IRouteConstraint, ISingletonDependency { + void SetPaths(IEnumerable paths); + string FindPath(string path); + void AddPath(string path); + void RemovePath(string path); + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs new file mode 100644 index 000000000..c3d6b71df --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs @@ -0,0 +1,23 @@ +using System.Web; +using System.Web.Routing; +using Orchard.Blogs.Models; + +namespace Orchard.Blogs.Routing { + public class IsArchiveConstraint : IRouteConstraint { + public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, + RouteDirection routeDirection) { + if(values[parameterName] == null) { + return false; + } + + try { + var archiveData = new ArchiveData(values[parameterName].ToString()); + archiveData.ToDateTime(); + return true; + } + catch { + return false; + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs index 81ebad553..8e2254c7b 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; +using Orchard.Autoroute.Models; using Orchard.Blogs.Models; +using Orchard.Blogs.Routing; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.Core.Title.Models; @@ -10,12 +12,17 @@ namespace Orchard.Blogs.Services { [UsedImplicitly] public class BlogService : IBlogService { private readonly IContentManager _contentManager; + private readonly IBlogPathConstraint _blogPathConstraint; - public BlogService(IContentManager contentManager) { + public BlogService(IContentManager contentManager, IBlogPathConstraint blogPathConstraint) { _contentManager = contentManager; + _blogPathConstraint = blogPathConstraint; } - public BlogPart Get(int id) { - return _contentManager.Get(id); + + public BlogPart Get(string path) { + return _contentManager.Query() + .Join().Where(rr => rr.DisplayAlias == path) + .Slice(0, 1).FirstOrDefault(); } public ContentItem Get(int id, VersionOptions versionOptions) { @@ -35,6 +42,7 @@ namespace Orchard.Blogs.Services { public void Delete(ContentItem blog) { _contentManager.Remove(blog); + _blogPathConstraint.RemovePath(blog.As().DisplayAlias); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/IBlogService.cs index f8b5e966f..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(int id); + 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/ViewModels/BlogArchivesViewModel.cs b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/BlogArchivesViewModel.cs index 9936db5b2..274661006 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/BlogArchivesViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/BlogArchivesViewModel.cs @@ -3,7 +3,7 @@ using Orchard.Blogs.Models; namespace Orchard.Blogs.ViewModels { public class BlogArchivesViewModel { + public string Slug { get; set; } public IEnumerable Blogs { get; set; } - public int BlogId { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/RecentBlogPostsViewModel.cs b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/RecentBlogPostsViewModel.cs index 1836f6804..9e304efdd 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/RecentBlogPostsViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/ViewModels/RecentBlogPostsViewModel.cs @@ -4,7 +4,7 @@ using Orchard.Blogs.Models; namespace Orchard.Blogs.ViewModels { public class RecentBlogPostsViewModel { public int Count { get; set; } - public int BlogId { get; set; } + public string Slug { get; set; } public IEnumerable Blogs { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleAssemblyInfo.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleAssemblyInfo.txt index 22a4eceba..c57b962d6 100644 --- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleAssemblyInfo.txt +++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleAssemblyInfo.txt @@ -1,6 +1,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Security; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -32,3 +33,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: SecurityTransparent] diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Properties/AssemblyInfo.cs b/src/Orchard.Web/Modules/Orchard.Tags/Properties/AssemblyInfo.cs index 532861bc3..7027a134d 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Properties/AssemblyInfo.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Properties/AssemblyInfo.cs @@ -32,3 +32,4 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("1.3.0")] [assembly: AssemblyFileVersion("1.3.0")] +[assembly: SecurityTransparent] diff --git a/src/Orchard.Web/Themes/Properties/AssemblyInfo.cs b/src/Orchard.Web/Themes/Properties/AssemblyInfo.cs index 3c0261b6d..ce733282b 100644 --- a/src/Orchard.Web/Themes/Properties/AssemblyInfo.cs +++ b/src/Orchard.Web/Themes/Properties/AssemblyInfo.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Runtime.InteropServices; +using System.Security; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -35,3 +36,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyVersion("1.3.0")] [assembly: AssemblyFileVersion("1.3.0")] +[assembly: SecurityTransparent] diff --git a/src/Orchard/Exceptions/DefaultExceptionPolicy.cs b/src/Orchard/Exceptions/DefaultExceptionPolicy.cs index 85d40ebb0..4cf950f39 100644 --- a/src/Orchard/Exceptions/DefaultExceptionPolicy.cs +++ b/src/Orchard/Exceptions/DefaultExceptionPolicy.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using System.Security; using System.Threading; +using Orchard.Environment; using Orchard.Events; using Orchard.Localization; using Orchard.Logging; @@ -11,14 +12,14 @@ using Orchard.UI.Notify; namespace Orchard.Exceptions { public class DefaultExceptionPolicy : IExceptionPolicy { private readonly INotifier _notifier; - private readonly Lazy _authorizer; + private readonly Work _authorizer; public DefaultExceptionPolicy() { Logger = NullLogger.Instance; T = NullLocalizer.Instance; } - public DefaultExceptionPolicy(INotifier notifier, Lazy authorizer) { + public DefaultExceptionPolicy(INotifier notifier, Work authorizer) { _notifier = notifier; _authorizer = authorizer; Logger = NullLogger.Instance; From 367066e7416e17fb946e05652a08224553cefa6a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 31 Jan 2012 17:07:00 -0800 Subject: [PATCH 3/4] Handling slashed in blog routes (with archive and rsd) --HG-- branch : autoroute --- .hgsubstate | 2 +- .../Controllers/BlogController.cs | 10 +-- .../Controllers/BlogPostController.cs | 24 +++++--- .../RemoteBlogPublishingController.cs | 16 ++++- .../Orchard.Blogs/Orchard.Blogs.csproj | 5 +- .../Modules/Orchard.Blogs/Routes.cs | 38 ++++-------- .../Routing/ARCHIVECONSTRAINT.CS | 61 +++++++++++++++++++ .../Routing/IARCHIVECONSTRAINT.CS | 9 +++ .../Orchard.Blogs/Routing/IRSDCONSTRAINT.CS | 7 +++ .../Routing/IsArchiveConstraint.cs | 23 ------- .../Orchard.Blogs/Routing/RSDCONSTRAINT.CS | 40 ++++++++++++ 11 files changed, 167 insertions(+), 68 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/ARCHIVECONSTRAINT.CS create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/IARCHIVECONSTRAINT.CS create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/IRSDCONSTRAINT.CS delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Routing/RSDCONSTRAINT.CS diff --git a/.hgsubstate b/.hgsubstate index 92b912f9a..7de3b3557 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1,5 +1,5 @@ 81cb672c85fd980dd3db0515544b79a918e5eb69 src/Orchard.Web/Modules/Orchard.Alias -a3329c82a2636eb166c46f3cfdadd18eca4e4d7f src/Orchard.Web/Modules/Orchard.Autoroute +f142e9e8cebf92caf3ca091d6e54849e02a27a4c src/Orchard.Web/Modules/Orchard.Autoroute c54cb640d6bc14c51b9fb9bd78231bb0facec067 src/Orchard.Web/Modules/Orchard.Forms c27801666ed3e8f9b9c7979a837e7d770763352a src/Orchard.Web/Modules/Orchard.Projections a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs index 4e64cc540..5d383ed15 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs @@ -58,14 +58,10 @@ namespace Orchard.Blogs.Controllers { return View((object)viewModel); } - public ActionResult Item(string blogPath, PagerParameters pagerParameters) { - // TODO: (PH:Autoroute) Should use Containers so we can lose this action and rely on ContainerPartDriver instead + public ActionResult Item(int blogId, PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); - var correctedPath = _blogPathConstraint.FindPath(blogPath); - if (correctedPath == null) - return HttpNotFound(); - var blogPart = _blogService.Get(correctedPath); + var blogPart = _blogService.Get(blogId, VersionOptions.Published).As(); if (blogPart == null) return HttpNotFound(); @@ -84,4 +80,4 @@ namespace Orchard.Blogs.Controllers { return new ShapeResult(this, blog); } } -} \ No newline at end of file +} diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs index 886643be6..4082a114d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs @@ -2,13 +2,11 @@ using System.Linq; using System.Web.Mvc; using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; +using Orchard.Blogs.Routing; using Orchard.Blogs.Services; -using Orchard.ContentManagement; using Orchard.Core.Feeds; using Orchard.DisplayManagement; using Orchard.Localization; -using Orchard.Mvc; -using Orchard.Security; using Orchard.Themes; namespace Orchard.Blogs.Controllers { @@ -18,17 +16,20 @@ namespace Orchard.Blogs.Controllers { private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; private readonly IFeedManager _feedManager; + private readonly IArchiveConstraint _archiveConstraint; public BlogPostController( IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, IFeedManager feedManager, - IShapeFactory shapeFactory) { + IShapeFactory shapeFactory, + IArchiveConstraint archiveConstraint) { _services = services; _blogService = blogService; _blogPostService = blogPostService; _feedManager = feedManager; + _archiveConstraint = archiveConstraint; T = NullLocalizer.Instance; Shape = shapeFactory; } @@ -36,15 +37,22 @@ namespace Orchard.Blogs.Controllers { dynamic Shape { get; set; } public Localizer T { get; set; } - public ActionResult ListByArchive(string blogPath, string archiveData) { - //TODO: (erikpo) Move looking up the current blog up into a modelbinder + public ActionResult ListByArchive(string path) { + + var blogPath = _archiveConstraint.FindPath(path); + var archive = _archiveConstraint.FindArchiveData(path); + + if (blogPath == null) + return HttpNotFound(); + + if (archive == null) + return HttpNotFound(); + BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) return HttpNotFound(); - var archive = new ArchiveData(archiveData); - var list = Shape.List(); list.AddRange(_blogPostService.Get(blogPart, archive).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"))); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs index 3209438bc..f652984b0 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/RemoteBlogPublishingController.cs @@ -3,6 +3,7 @@ using System.Web.Mvc; using System.Web.Routing; using System.Xml.Linq; using Orchard.Blogs.Models; +using Orchard.Blogs.Routing; using Orchard.Blogs.Services; using Orchard.Environment.Extensions; using Orchard.Logging; @@ -11,19 +12,30 @@ namespace Orchard.Blogs.Controllers { [OrchardFeature("Orchard.Blogs.RemotePublishing")] public class RemoteBlogPublishingController : Controller { private readonly IBlogService _blogService; + private readonly IRsdConstraint _rsdConstraint; private readonly RouteCollection _routeCollection; - public RemoteBlogPublishingController(IOrchardServices services, IBlogService blogService, RouteCollection routeCollection) { + public RemoteBlogPublishingController( + IOrchardServices services, + IBlogService blogService, + IRsdConstraint rsdConstraint, + RouteCollection routeCollection) { _blogService = blogService; + _rsdConstraint = rsdConstraint; _routeCollection = routeCollection; Logger = NullLogger.Instance; } protected ILogger Logger { get; set; } - public ActionResult Rsd(string blogPath) { + public ActionResult Rsd(string path) { Logger.Debug("RSD requested"); + var blogPath = _rsdConstraint.FindPath(path); + + if (blogPath == null) + return HttpNotFound(); + BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index 9f37e0ee9..a17572f82 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -81,8 +81,11 @@ + + + + - diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs index fae9aa1b3..3883676a3 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs @@ -6,10 +6,14 @@ using Orchard.Mvc.Routes; namespace Orchard.Blogs { public class Routes : IRouteProvider { - private readonly IBlogPathConstraint _blogPathConstraint; + private readonly IArchiveConstraint _archiveConstraint; + private readonly IRsdConstraint _rsdConstraint; - public Routes(IBlogPathConstraint blogPathConstraint) { - _blogPathConstraint = blogPathConstraint; + public Routes( + IArchiveConstraint archiveConstraint, + IRsdConstraint rsdConstraint) { + _archiveConstraint = archiveConstraint; + _rsdConstraint = rsdConstraint; } public void GetRoutes(ICollection routes) { @@ -173,34 +177,16 @@ namespace Orchard.Blogs { }, new MvcRouteHandler()) }, -new RouteDescriptor { - Route = new Route( - "Archive/{*archiveData}", - new RouteValueDictionary { - {"blogPath", ""}, - {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, - {"action", "ListByArchive"} - }, - new RouteValueDictionary { - {"archiveData", new IsArchiveConstraint()} - }, - new RouteValueDictionary { - {"area", "Orchard.Blogs"} - }, - new MvcRouteHandler()) - }, new RouteDescriptor { Route = new Route( - "{blogPath}/Archive/{*archiveData}", + "{*path}", new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "BlogPost"}, {"action", "ListByArchive"} }, new RouteValueDictionary { - {"blogPath", _blogPathConstraint}, - {"archiveData", new IsArchiveConstraint()} + {"path", _archiveConstraint}, }, new RouteValueDictionary { {"area", "Orchard.Blogs"} @@ -210,20 +196,20 @@ new RouteDescriptor { new RouteDescriptor { Priority = 11, Route = new Route( - "{blogPath}/rsd", + "{*path}", new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "RemoteBlogPublishing"}, {"action", "Rsd"} }, new RouteValueDictionary { - {"blogPath", _blogPathConstraint} + {"path", _rsdConstraint} }, new RouteValueDictionary { {"area", "Orchard.Blogs"} }, new MvcRouteHandler()) - }, + } }; } } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ARCHIVECONSTRAINT.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ARCHIVECONSTRAINT.CS new file mode 100644 index 000000000..3f56cda24 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ARCHIVECONSTRAINT.CS @@ -0,0 +1,61 @@ +using System; +using System.Web; +using System.Web.Routing; +using Orchard.Blogs.Models; + +namespace Orchard.Blogs.Routing { + public class ArchiveConstraint : IArchiveConstraint { + private readonly IBlogPathConstraint _blogPathConstraint; + + public ArchiveConstraint(IBlogPathConstraint blogPathConstraint) { + _blogPathConstraint = blogPathConstraint; + } + + public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { + + object value; + if (values.TryGetValue(parameterName, out value)) { + var parameterValue = Convert.ToString(value); + + var path = FindPath(parameterValue); + if (path == null) { + return false; + } + + var archiveData = FindArchiveData(parameterValue); + if (archiveData == null) { + return false; + } + + return _blogPathConstraint.FindPath(path) != null; + } + + return false; + } + + public string FindPath(string path) { + var archiveIndex = path.IndexOf("/archive/", StringComparison.OrdinalIgnoreCase); + + if (archiveIndex == -1) { + return null; + } + + return path.Substring(0, archiveIndex); + } + + public ArchiveData FindArchiveData(string path) { + var archiveIndex = path.IndexOf("/archive/", StringComparison.OrdinalIgnoreCase); + + if (archiveIndex == -1) { + return null; + } + + try { + return new ArchiveData(path.Substring(archiveIndex + "/archive/".Length)); + } + catch { + return null; + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IARCHIVECONSTRAINT.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IARCHIVECONSTRAINT.CS new file mode 100644 index 000000000..d89c68b21 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IARCHIVECONSTRAINT.CS @@ -0,0 +1,9 @@ +using System.Web.Routing; +using Orchard.Blogs.Models; + +namespace Orchard.Blogs.Routing { + public interface IArchiveConstraint : IRouteConstraint, ISingletonDependency { + string FindPath(string path); + ArchiveData FindArchiveData(string path); + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IRSDCONSTRAINT.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IRSDCONSTRAINT.CS new file mode 100644 index 000000000..e09bfcc54 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IRSDCONSTRAINT.CS @@ -0,0 +1,7 @@ +using System.Web.Routing; + +namespace Orchard.Blogs.Routing { + public interface IRsdConstraint : IRouteConstraint, ISingletonDependency { + string FindPath(string path); + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs deleted file mode 100644 index c3d6b71df..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/IsArchiveConstraint.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Web; -using System.Web.Routing; -using Orchard.Blogs.Models; - -namespace Orchard.Blogs.Routing { - public class IsArchiveConstraint : IRouteConstraint { - public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, - RouteDirection routeDirection) { - if(values[parameterName] == null) { - return false; - } - - try { - var archiveData = new ArchiveData(values[parameterName].ToString()); - archiveData.ToDateTime(); - return true; - } - catch { - return false; - } - } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RSDCONSTRAINT.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RSDCONSTRAINT.CS new file mode 100644 index 000000000..fec2fd2ab --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RSDCONSTRAINT.CS @@ -0,0 +1,40 @@ +using System; +using System.Web; +using System.Web.Routing; + +namespace Orchard.Blogs.Routing { + public class RsdConstraint : IRsdConstraint { + private readonly IBlogPathConstraint _blogPathConstraint; + + public RsdConstraint(IBlogPathConstraint blogPathConstraint) { + _blogPathConstraint = blogPathConstraint; + } + + public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { + if (routeDirection == RouteDirection.UrlGeneration) + return true; + + object value; + if (values.TryGetValue(parameterName, out value)) { + var parameterValue = Convert.ToString(value); + + var path = FindPath(parameterValue); + if(path == null) { + return false; + } + + return _blogPathConstraint.FindPath(path) != null; + } + + return false; + } + + public string FindPath(string path) { + if (!path.EndsWith("/rsd", StringComparison.OrdinalIgnoreCase)) { + return null; + } + + return path.Substring(0, path.Length - "/rsd".Length); + } + } +} \ No newline at end of file From b5e69f827df5fffda7eb99f337fe419f35b96e01 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 31 Jan 2012 18:13:54 -0800 Subject: [PATCH 4/4] Implementing IAliasAspect --HG-- branch : autoroute --- .hgsubstate | 2 +- .../Orchard.Blogs/Extensions/UrlHelperExtensions.cs | 9 ++++----- .../Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs | 6 +++--- src/Orchard.Web/Modules/Orchard.Blogs/Module.txt | 2 +- .../Modules/Orchard.Blogs/Orchard.Blogs.csproj | 8 -------- .../Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs | 2 +- .../Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs | 4 ++-- .../Modules/Orchard.Blogs/Services/BlogService.cs | 7 ++----- src/Orchard/ContentManagement/Aspects/IAliasAspect.cs | 5 +++++ src/Orchard/ContentManagement/Aspects/IRoutableAspect.cs | 3 +-- src/Orchard/Orchard.Framework.csproj | 1 + 11 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 src/Orchard/ContentManagement/Aspects/IAliasAspect.cs diff --git a/.hgsubstate b/.hgsubstate index 7de3b3557..d89bfdaab 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1,5 +1,5 @@ 81cb672c85fd980dd3db0515544b79a918e5eb69 src/Orchard.Web/Modules/Orchard.Alias -f142e9e8cebf92caf3ca091d6e54849e02a27a4c src/Orchard.Web/Modules/Orchard.Autoroute +38ee40302540edd0f4671b8110788b295573c345 src/Orchard.Web/Modules/Orchard.Autoroute c54cb640d6bc14c51b9fb9bd78231bb0facec067 src/Orchard.Web/Modules/Orchard.Forms c27801666ed3e8f9b9c7979a837e7d770763352a src/Orchard.Web/Modules/Orchard.Projections a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs index 35874e6f1..420c4e1f5 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs @@ -1,5 +1,4 @@ using System.Web.Mvc; -using Orchard.Autoroute.Models; using Orchard.Blogs.Models; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; @@ -27,19 +26,19 @@ namespace Orchard.Blogs.Extensions { } public static string BlogRsd(this UrlHelper urlHelper, BlogPart blogPart) { - return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "RemoteBlogPublishing", new { blogPath = blogPart.As().Path, area = "Orchard.Blogs" })); + return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "RemoteBlogPublishing", new { path = blogPart.As().Path + "/rsd", area = "Orchard.Blogs" })); } public static string BlogArchiveYear(this UrlHelper urlHelper, BlogPart blogPart, int year) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = year.ToString(), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { path = blogPart.As().Path + "/archive/" + year.ToString(), area = "Orchard.Blogs" }); } public static string BlogArchiveMonth(this UrlHelper urlHelper, BlogPart blogPart, int year, int month) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { path = blogPart.As().Path + "/archive/" + string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); } public static string BlogArchiveDay(this UrlHelper urlHelper, BlogPart blogPart, int year, int month, int day) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogPath = blogPart.As().DisplayAlias, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs" }); + return urlHelper.Action("ListByArchive", "BlogPost", new { path = blogPart.As().Path + "/archive/" + string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs" }); } public static string BlogForAdmin(this UrlHelper urlHelper, BlogPart blogPart) { diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs index 0a7583a50..1f19d71cb 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs @@ -1,9 +1,9 @@ using System.Web.Routing; using JetBrains.Annotations; -using Orchard.Autoroute.Models; using Orchard.Blogs.Models; using Orchard.Blogs.Routing; using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Handlers; using Orchard.Data; @@ -21,8 +21,8 @@ namespace Orchard.Blogs.Handlers { context.Shape.PostCount = blog.PostCount; }); - OnPublished((context, blog) => _blogPathConstraint.AddPath(blog.As().DisplayAlias)); - OnUnpublished((context, blog) => _blogPathConstraint.RemovePath(blog.As().DisplayAlias)); + OnPublished((context, blog) => _blogPathConstraint.AddPath(blog.As().Path)); + OnUnpublished((context, blog) => _blogPathConstraint.RemovePath(blog.As().Path)); } protected override void GetItemMetadata(GetContentItemMetadataContext context) { diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Module.txt b/src/Orchard.Web/Modules/Orchard.Blogs/Module.txt index 065f6d3e3..d85273145 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Module.txt +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Module.txt @@ -12,5 +12,5 @@ Features: Orchard.Blogs.RemotePublishing: Name: Remote Blog Publishing Description: Blog easier using a dedicated MetaWeblogAPI-compatible publishing tool. - Dependencies: XmlRpc, Orchard.Blogs + Dependencies: XmlRpc, Orchard.Blogs, Orchard.Autoroute Category: Content Publishing diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index a17572f82..3a30b14fa 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -140,14 +140,6 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core - - {475B6C45-B27C-438B-8966-908B9D6D1077} - Orchard.Alias - - - {66FCCD76-2761-47E3-8D11-B45D0001DDAA} - Orchard.Autoroute - diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs index 9a99df298..6fb86ae45 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraint.cs @@ -10,7 +10,7 @@ using Orchard.Logging; namespace Orchard.Blogs.Routing { [UsedImplicitly] public class BlogPathConstraint : IBlogPathConstraint { - private ConcurrentDictionary _paths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _paths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); public BlogPathConstraint() { Logger = NullLogger.Instance; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs index 3f7f51bf1..5a35dac9c 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogPathConstraintUpdator.cs @@ -1,8 +1,8 @@ using System.Linq; using JetBrains.Annotations; -using Orchard.Autoroute.Models; using Orchard.Blogs.Services; using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Environment; using Orchard.Tasks; @@ -29,7 +29,7 @@ namespace Orchard.Blogs.Routing { } private void Refresh() { - _blogPathConstraint.SetPaths(_blogService.Get().Select(b => b.As().DisplayAlias).ToList()); + _blogPathConstraint.SetPaths(_blogService.Get().Select(b => b.As().Path).ToList()); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs index 8e2254c7b..c7f8f0e5a 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; -using Orchard.Autoroute.Models; using Orchard.Blogs.Models; using Orchard.Blogs.Routing; using Orchard.ContentManagement; @@ -20,9 +19,7 @@ namespace Orchard.Blogs.Services { } public BlogPart Get(string path) { - return _contentManager.Query() - .Join().Where(rr => rr.DisplayAlias == path) - .Slice(0, 1).FirstOrDefault(); + return _contentManager.Query().List().FirstOrDefault(rr => rr.As().Path == path); } public ContentItem Get(int id, VersionOptions versionOptions) { @@ -42,7 +39,7 @@ namespace Orchard.Blogs.Services { public void Delete(ContentItem blog) { _contentManager.Remove(blog); - _blogPathConstraint.RemovePath(blog.As().DisplayAlias); + _blogPathConstraint.RemovePath(blog.As().Path); } } } \ No newline at end of file diff --git a/src/Orchard/ContentManagement/Aspects/IAliasAspect.cs b/src/Orchard/ContentManagement/Aspects/IAliasAspect.cs new file mode 100644 index 000000000..3afd26833 --- /dev/null +++ b/src/Orchard/ContentManagement/Aspects/IAliasAspect.cs @@ -0,0 +1,5 @@ +namespace Orchard.ContentManagement.Aspects { + public interface IAliasAspect : IContent { + string Path { get; } + } +} diff --git a/src/Orchard/ContentManagement/Aspects/IRoutableAspect.cs b/src/Orchard/ContentManagement/Aspects/IRoutableAspect.cs index dad8b1633..396968243 100644 --- a/src/Orchard/ContentManagement/Aspects/IRoutableAspect.cs +++ b/src/Orchard/ContentManagement/Aspects/IRoutableAspect.cs @@ -1,6 +1,5 @@ namespace Orchard.ContentManagement.Aspects { - public interface IRoutableAspect : ITitleAspect { + public interface IRoutableAspect : ITitleAspect, IAliasAspect { string Slug { get; set; } - string Path { get; set; } } } diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index a65c59116..2a2fc4998 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -159,6 +159,7 @@ +