mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Wrapping up the current state of slug generation for Pages
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045559
This commit is contained in:
@@ -23,7 +23,7 @@ namespace Orchard.Core.Settings.Controllers {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public ActionResult Index(string tabName) {
|
public ActionResult Index(string tabName) {
|
||||||
var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel {
|
var model = new SettingsIndexViewModel {
|
||||||
Site = _siteService.GetSiteSettings().As<SiteSettings>()
|
Site = _siteService.GetSiteSettings().As<SiteSettings>()
|
||||||
};
|
};
|
||||||
model.ViewModel = _modelManager.BuildEditorModel(model.Site);
|
model.ViewModel = _modelManager.BuildEditorModel(model.Site);
|
||||||
|
@@ -13,7 +13,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
private readonly IOrchardServices _services;
|
private readonly IOrchardServices _services;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
|
|
||||||
public BlogController(IOrchardServices services, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier, IBlogService blogService) {
|
public BlogController(IOrchardServices services, IBlogService blogService) {
|
||||||
_services = services;
|
_services = services;
|
||||||
_blogService = blogService;
|
_blogService = blogService;
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,6 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: (erikpo) Evaluate if publish options should be moved into create or out of create to keep it clean
|
|
||||||
model.BlogPost = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New<BlogPost>("blogpost"), this);
|
model.BlogPost = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New<BlogPost>("blogpost"), this);
|
||||||
model.BlogPost.Item.Blog = blog;
|
model.BlogPost.Item.Blog = blog;
|
||||||
if (!publishNow && publishDate != null)
|
if (!publishNow && publishDate != null)
|
||||||
@@ -86,6 +85,7 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: (erikpo) Evaluate if publish options should be moved into create or out of create to keep it clean
|
||||||
_services.ContentManager.Create(model.BlogPost.Item.ContentItem, publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
_services.ContentManager.Create(model.BlogPost.Item.ContentItem, publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
||||||
|
|
||||||
//TEMP: (erikpo) ensure information has committed for this record
|
//TEMP: (erikpo) ensure information has committed for this record
|
||||||
|
@@ -24,7 +24,7 @@ namespace Orchard.Blogs.Models {
|
|||||||
|
|
||||||
blog.Slug = routableService.GenerateUniqueSlug(slug,
|
blog.Slug = routableService.GenerateUniqueSlug(slug,
|
||||||
blogService.Get().Where(
|
blogService.Get().Where(
|
||||||
b => b.Slug.StartsWith(slug)).Select(
|
b => b.Slug.StartsWith(slug) && b.Id != blog.Id).Select(
|
||||||
b => b.Slug));
|
b => b.Slug));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -26,9 +26,10 @@ namespace Orchard.Blogs.Models {
|
|||||||
|
|
||||||
blogPost.Slug = routableService.GenerateUniqueSlug(slug,
|
blogPost.Slug = routableService.GenerateUniqueSlug(slug,
|
||||||
blogPostService.Get(blogPost.Blog, VersionOptions.Published).Where(
|
blogPostService.Get(blogPost.Blog, VersionOptions.Published).Where(
|
||||||
bp => bp.Slug.StartsWith(slug)).Select(
|
bp => bp.Slug.StartsWith(slug) && bp.Id != blogPost.Id).Select(
|
||||||
bp => bp.Slug));
|
bp => bp.Slug));
|
||||||
});
|
});
|
||||||
|
|
||||||
OnCreated<BlogPost>((context, bp) => bp.Blog.PostCount++);
|
OnCreated<BlogPost>((context, bp) => bp.Blog.PostCount++);
|
||||||
OnRemoved<BlogPost>((context, bp) => bp.Blog.PostCount--);
|
OnRemoved<BlogPost>((context, bp) => bp.Blog.PostCount--);
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
@@ -15,23 +14,15 @@ using Orchard.UI.Notify;
|
|||||||
namespace Orchard.Pages.Controllers {
|
namespace Orchard.Pages.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class AdminController : Controller, IUpdateModel {
|
public class AdminController : Controller, IUpdateModel {
|
||||||
private readonly ISessionLocator _sessionLocator;
|
private readonly IOrchardServices _services;
|
||||||
private readonly IPageService _pageService;
|
private readonly IPageService _pageService;
|
||||||
private readonly ISlugConstraint _slugConstraint;
|
|
||||||
|
|
||||||
public AdminController(
|
public AdminController(IOrchardServices services, IPageService pageService) {
|
||||||
IOrchardServices services,
|
_services = services;
|
||||||
ISessionLocator sessionLocator,
|
|
||||||
IPageService pageService,
|
|
||||||
ISlugConstraint slugConstraint) {
|
|
||||||
Services = services;
|
|
||||||
_sessionLocator = sessionLocator;
|
|
||||||
_pageService = pageService;
|
_pageService = pageService;
|
||||||
_slugConstraint = slugConstraint;
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrchardServices Services { get; set; }
|
|
||||||
private Localizer T { get; set; }
|
private Localizer T { get; set; }
|
||||||
|
|
||||||
public ActionResult List(PagesOptions options) {
|
public ActionResult List(PagesOptions options) {
|
||||||
@@ -67,7 +58,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
case PagesBulkAction.None:
|
case PagesBulkAction.None:
|
||||||
break;
|
break;
|
||||||
case PagesBulkAction.PublishNow:
|
case PagesBulkAction.PublishNow:
|
||||||
if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't publish page")))
|
if (!_services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't publish page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
foreach (PageEntry entry in checkedEntries) {
|
foreach (PageEntry entry in checkedEntries) {
|
||||||
@@ -76,7 +67,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PagesBulkAction.Unpublish:
|
case PagesBulkAction.Unpublish:
|
||||||
if (!Services.Authorizer.Authorize(Permissions.UnpublishPages, T("Couldn't unpublish page")))
|
if (!_services.Authorizer.Authorize(Permissions.UnpublishPages, T("Couldn't unpublish page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
foreach (PageEntry entry in checkedEntries) {
|
foreach (PageEntry entry in checkedEntries) {
|
||||||
var page = _pageService.GetLatest(entry.PageId);
|
var page = _pageService.GetLatest(entry.PageId);
|
||||||
@@ -84,7 +75,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PagesBulkAction.Delete:
|
case PagesBulkAction.Delete:
|
||||||
if (!Services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
|
if (!_services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
foreach (PageEntry entry in checkedEntries) {
|
foreach (PageEntry entry in checkedEntries) {
|
||||||
@@ -108,10 +99,10 @@ namespace Orchard.Pages.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Create() {
|
public ActionResult Create() {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
|
if (!_services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var page = Services.ContentManager.BuildEditorModel(Services.ContentManager.New<Page>("page"));
|
var page = _services.ContentManager.BuildEditorModel(_services.ContentManager.New<Page>("page"));
|
||||||
|
|
||||||
var model = new PageCreateViewModel {
|
var model = new PageCreateViewModel {
|
||||||
Page = page
|
Page = page
|
||||||
@@ -122,7 +113,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
|
|
||||||
[HttpPost, ActionName("Create")]
|
[HttpPost, ActionName("Create")]
|
||||||
public ActionResult CreatePOST(PageCreateViewModel model) {
|
public ActionResult CreatePOST(PageCreateViewModel model) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
|
if (!_services.Authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||||
@@ -137,22 +128,22 @@ namespace Orchard.Pages.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Page = Services.ContentManager.UpdateEditorModel(Services.ContentManager.New<Page>("page"), this);
|
model.Page = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New<Page>("page"), this);
|
||||||
if (!publishNow && publishDate != null)
|
if (!publishNow && publishDate != null)
|
||||||
model.Page.Item.Published = publishDate.Value;
|
model.Page.Item.Published = publishDate.Value;
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
_services.TransactionManager.Cancel();
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.ContentManager.Create(model.Page.Item.ContentItem, publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
_services.ContentManager.Create(model.Page.Item.ContentItem, publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
||||||
|
|
||||||
return RedirectToAction("List");
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Edit(string pageSlug) {
|
public ActionResult Edit(string pageSlug) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
if (!_services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
Page page = _pageService.GetLatest(pageSlug);
|
Page page = _pageService.GetLatest(pageSlug);
|
||||||
@@ -161,7 +152,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var model = new PageEditViewModel {
|
var model = new PageEditViewModel {
|
||||||
Page = Services.ContentManager.BuildEditorModel(page)
|
Page = _services.ContentManager.BuildEditorModel(page)
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -169,7 +160,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
|
|
||||||
[HttpPost, ActionName("Edit")]
|
[HttpPost, ActionName("Edit")]
|
||||||
public ActionResult EditPOST(string pageSlug) {
|
public ActionResult EditPOST(string pageSlug) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
if (!_services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
Page page = _pageService.GetPageOrDraft(pageSlug);
|
Page page = _pageService.GetPageOrDraft(pageSlug);
|
||||||
@@ -198,25 +189,25 @@ namespace Orchard.Pages.Controllers {
|
|||||||
_pageService.Unpublish(page);
|
_pageService.Unpublish(page);
|
||||||
|
|
||||||
var model = new PageEditViewModel {
|
var model = new PageEditViewModel {
|
||||||
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
Page = _services.ContentManager.UpdateEditorModel(page, this)
|
||||||
};
|
};
|
||||||
|
|
||||||
TryUpdateModel(model);
|
TryUpdateModel(model);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
_services.TransactionManager.Cancel();
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.Notifier.Information(T("Page information updated."));
|
_services.Notifier.Information(T("Page information updated."));
|
||||||
|
|
||||||
return RedirectToAction("List");
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Delete(string pageSlug) {
|
public ActionResult Delete(string pageSlug) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
|
if (!_services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
Page page = _pageService.Get(pageSlug);
|
Page page = _pageService.Get(pageSlug);
|
||||||
@@ -226,7 +217,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
|
|
||||||
_pageService.Delete(page);
|
_pageService.Delete(page);
|
||||||
|
|
||||||
Services.Notifier.Information(T("Page was successfully deleted"));
|
_services.Notifier.Information(T("Page was successfully deleted"));
|
||||||
|
|
||||||
return RedirectToAction("List");
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
@@ -20,15 +20,15 @@ namespace Orchard.Pages.Models {
|
|||||||
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new StorageFilter<CommonVersionRecord>(commonRepository));
|
Filters.Add(new StorageFilter<CommonVersionRecord>(commonRepository));
|
||||||
|
|
||||||
OnCreating<Page>((context, blog) =>
|
OnCreating<Page>((context, page) =>
|
||||||
{
|
{
|
||||||
string slug = !string.IsNullOrEmpty(blog.Slug)
|
string slug = !string.IsNullOrEmpty(page.Slug)
|
||||||
? blog.Slug
|
? page.Slug
|
||||||
: routableService.Slugify(blog.Title);
|
: routableService.Slugify(page.Title);
|
||||||
|
|
||||||
blog.Slug = routableService.GenerateUniqueSlug(slug,
|
page.Slug = routableService.GenerateUniqueSlug(slug,
|
||||||
pageService.Get(PageStatus.Published).Where(
|
pageService.Get(PageStatus.Published).Where(
|
||||||
p => p.Slug.StartsWith(slug)).Select(
|
p => p.Slug.StartsWith(slug) && p.Id != page.Id).Select(
|
||||||
p => p.Slug));
|
p => p.Slug));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -231,7 +231,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
tagBuilder.MergeAttribute("action", formAction);
|
tagBuilder.MergeAttribute("action", formAction);
|
||||||
tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(formMethod), true);
|
tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(formMethod), true);
|
||||||
|
|
||||||
htmlHelper.ViewContext.HttpContext.Response.Output.Write(tagBuilder.ToString(TagRenderMode.StartTag));
|
htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
|
||||||
|
|
||||||
return new MvcFormAntiForgeryPost(htmlHelper);
|
return new MvcFormAntiForgeryPost(htmlHelper);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
public static class LayoutExtensions {
|
public static class LayoutExtensions {
|
||||||
public static void RenderBody(this HtmlHelper html) {
|
public static void RenderBody(this HtmlHelper html) {
|
||||||
LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);
|
LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);
|
||||||
html.ViewContext.HttpContext.Response.Output.Write(layoutViewContext.BodyContent);
|
html.ViewContext.Writer.Write(layoutViewContext.BodyContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MvcHtmlString Body(this HtmlHelper html) {
|
public static MvcHtmlString Body(this HtmlHelper html) {
|
||||||
|
@@ -10,7 +10,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing) {
|
protected override void Dispose(bool disposing) {
|
||||||
_htmlHelper.ViewContext.HttpContext.Response.Output.Write(_htmlHelper.AntiForgeryTokenOrchard());
|
_htmlHelper.ViewContext.Writer.Write(_htmlHelper.AntiForgeryTokenOrchard());
|
||||||
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user