--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-10-14 17:18:40 -07:00
9 changed files with 26 additions and 20 deletions

View File

@@ -84,6 +84,13 @@ namespace Orchard.Core.Tests.Routable.Services {
Assert.That(_routableService.IsSlugValid("some/page"), Is.True); Assert.That(_routableService.IsSlugValid("some/page"), Is.True);
} }
[Test]
public void DotsAroundSlugAreAllowed() {
Assert.That(_routableService.IsSlugValid(".slug"), Is.False);
Assert.That(_routableService.IsSlugValid("slug."), Is.False);
Assert.That(_routableService.IsSlugValid("slug.slug"), Is.True);
}
[Test] [Test]
public void EmptySlugsShouldBeConsideredValid() { public void EmptySlugsShouldBeConsideredValid() {
// so that automatic generation on Publish occurs // so that automatic generation on Publish occurs

View File

@@ -82,8 +82,14 @@ namespace Orchard.Core.Routable.Drivers {
part.Title = model.Title; part.Title = model.Title;
part.Slug = model.Slug; part.Slug = model.Slug;
if (!_routableService.IsSlugValid(part.Slug)) { if ( !_routableService.IsSlugValid(part.Slug) ) {
updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your slugs: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\". No spaces are allowed (please use dashes or underscores instead).")); var slug = (part.Slug ?? String.Empty);
if ( slug.StartsWith(".") || slug.EndsWith(".") ) {
updater.AddModelError("Routable.Slug", T("The \".\" can't be used around routes."));
}
else {
updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your slugs: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\". No spaces are allowed (please use dashes or underscores instead)."));
}
} }
string originalSlug = part.Slug; string originalSlug = part.Slug;

View File

@@ -26,6 +26,9 @@ namespace Orchard.Core.Routable.Services {
if (slug.Length > 1000) if (slug.Length > 1000)
slug = slug.Substring(0, 1000); slug = slug.Substring(0, 1000);
// dots are not allowed at the begin and the end of routes
slug = slug.Trim('.');
model.Slug = slug.ToLowerInvariant(); model.Slug = slug.ToLowerInvariant();
} }
@@ -63,8 +66,7 @@ namespace Orchard.Core.Routable.Services {
} }
public bool IsSlugValid(string slug) { public bool IsSlugValid(string slug) {
// see http://tools.ietf.org/html/rfc3987 for prohibited chars return String.IsNullOrWhiteSpace(slug) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s]+$") && !(slug.StartsWith(".") || slug.EndsWith("."));
return slug == null || String.IsNullOrEmpty(slug.Trim()) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s]+$");
} }
public bool ProcessSlug(RoutePart part) { public bool ProcessSlug(RoutePart part) {
@@ -80,7 +82,6 @@ namespace Orchard.Core.Routable.Services {
// of slugs to consider for conflict detection // of slugs to consider for conflict detection
pathsLikeThis = pathsLikeThis.Where(p => p.ContentItem.Id != part.ContentItem.Id); pathsLikeThis = pathsLikeThis.Where(p => p.ContentItem.Id != part.ContentItem.Id);
//todo: (heskew) need better messages
if (pathsLikeThis.Count() > 0) { if (pathsLikeThis.Count() > 0) {
var originalSlug = part.Slug; var originalSlug = part.Slug;
//todo: (heskew) make auto-uniqueness optional //todo: (heskew) make auto-uniqueness optional

View File

@@ -43,7 +43,6 @@ namespace Orchard.Blogs.Controllers {
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
public ActionResult Create() { public ActionResult Create() {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -57,7 +56,6 @@ namespace Orchard.Blogs.Controllers {
[HttpPost, ActionName("Create")] [HttpPost, ActionName("Create")]
public ActionResult CreatePOST() { public ActionResult CreatePOST() {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -79,7 +77,6 @@ namespace Orchard.Blogs.Controllers {
} }
public ActionResult Edit(string blogSlug) { public ActionResult Edit(string blogSlug) {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to edit blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to edit blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -93,7 +90,6 @@ namespace Orchard.Blogs.Controllers {
[HttpPost, ActionName("Edit")] [HttpPost, ActionName("Edit")]
public ActionResult EditPOST(string blogSlug) { public ActionResult EditPOST(string blogSlug) {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -112,7 +108,6 @@ namespace Orchard.Blogs.Controllers {
[HttpPost] [HttpPost]
public ActionResult Remove(string blogSlug) { public ActionResult Remove(string blogSlug) {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't delete blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't delete blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();

View File

@@ -18,21 +18,21 @@ namespace Orchard.Blogs.Handlers {
private static void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IRepository<CommonPartRecord> commonRepository, BlogPostPart blogPostPart) { private static void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IRepository<CommonPartRecord> commonRepository, BlogPostPart blogPostPart) {
blogArchiveRepository.Flush(); blogArchiveRepository.Flush();
//INFO: (erikpo) Remove all current blog archive records // remove all current blog archive records
var blogArchiveRecords = var blogArchiveRecords =
from bar in blogArchiveRepository.Table from bar in blogArchiveRepository.Table
where bar.BlogPart == blogPostPart.BlogPart.Record where bar.BlogPart == blogPostPart.BlogPart.Record
select bar; select bar;
blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete); blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete);
//INFO: (erikpo) Get all blog posts for the current blog // get all blog posts for the current blog
var postsQuery = var postsQuery =
from bpr in commonRepository.Table from bpr in commonRepository.Table
where bpr.ContentItemRecord.ContentType.Name == "BlogPost" && bpr.Container.Id == blogPostPart.BlogPart.Record.Id where bpr.ContentItemRecord.ContentType.Name == "BlogPost" && bpr.Container.Id == blogPostPart.BlogPart.Record.Id
orderby bpr.PublishedUtc orderby bpr.PublishedUtc
select bpr; select bpr;
//INFO: (erikpo) Create a dictionary of all the year/month combinations and their count of posts that are published in this blog // create a dictionary of all the year/month combinations and their count of posts that are published in this blog
var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count()); var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count());
foreach (var post in postsQuery) { foreach (var post in postsQuery) {
if (!post.PublishedUtc.HasValue) if (!post.PublishedUtc.HasValue)
@@ -46,7 +46,7 @@ namespace Orchard.Blogs.Handlers {
inMemoryBlogArchives[key] = 1; inMemoryBlogArchives[key] = 1;
} }
//INFO: (erikpo) Create the new blog archive records based on the in memory values // create the new blog archive records based on the in memory values
foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) { foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) {
blogArchiveRepository.Create(new BlogPartArchiveRecord {BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value}); blogArchiveRepository.Create(new BlogPartArchiveRecord {BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value});
} }

View File

@@ -9,7 +9,6 @@ namespace Orchard.Blogs.Models {
set { this.As<RoutePart>().Title = value; } set { this.As<RoutePart>().Title = value; }
} }
//TODO: (erikpo) Need a data type for slug
public string Slug { public string Slug {
get { return this.As<RoutePart>().Slug; } get { return this.As<RoutePart>().Slug; }
set { this.As<RoutePart>().Slug = value; } set { this.As<RoutePart>().Slug = value; }

View File

@@ -27,7 +27,7 @@ namespace Orchard.ContentTypes.Controllers {
#region Types #region Types
public ActionResult List() { public ActionResult List() {
return View(new ListContentTypesViewModel { return View("List", new ListContentTypesViewModel {
Types = _contentDefinitionService.GetTypes() Types = _contentDefinitionService.GetTypes()
}); });
} }

View File

@@ -243,9 +243,8 @@
<IISUrl> <IISUrl>
</IISUrl> </IISUrl>
<NTLMAuthentication>False</NTLMAuthentication> <NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer> <UseCustomServer>True</UseCustomServer>
<CustomServerUrl> <CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties> </WebProjectProperties>
</FlavorProperties> </FlavorProperties>

View File

@@ -195,7 +195,6 @@ namespace Orchard.Mvc.Html {
return value.HasValue ? htmlHelper.DateTimeRelative(value.Value, T) : defaultIfNull; return value.HasValue ? htmlHelper.DateTimeRelative(value.Value, T) : defaultIfNull;
} }
//TODO: (erikpo) This method needs localized
public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime value, Localizer T) { public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime value, Localizer T) {
var time = htmlHelper.Resolve<IClock>().UtcNow - value; var time = htmlHelper.Resolve<IClock>().UtcNow - value;