From 2fd235d81873adfe279fa784d8f74f1278d9f402 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 22 Nov 2010 18:03:49 -0800 Subject: [PATCH 1/6] Fixing folder renaming in AzureFileSystem New Combine in IStorageProvider --HG-- branch : dev --- .../Media/AzureBlobStorageProviderTests.cs | 11 +++++ src/Orchard.Azure/AzureFileSystem.cs | 41 +++++++++++++++++-- .../Orchard.Media/Services/MediaService.cs | 12 +++--- .../Media/FileSystemStorageProvider.cs | 4 ++ .../FileSystems/Media/IStorageProvider.cs | 1 + 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs index e6c948032..f4cbe9182 100644 --- a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs +++ b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs @@ -105,6 +105,17 @@ namespace Orchard.Azure.Tests.FileSystems.Media { Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders(null).First().GetPath()); } + [Test] + public void CreateFolderWithSubFolder() { + _azureBlobStorageProvider.CreateFolder("folder"); + Assert.AreEqual(0, _azureBlobStorageProvider.ListFolders("folder").Count()); + + _azureBlobStorageProvider.CreateFolder("folder/folder"); + Assert.AreEqual(1, _azureBlobStorageProvider.ListFolders("folder").Count()); + Assert.AreEqual(0, _azureBlobStorageProvider.ListFiles("folder/folder").Count()); + Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders("folder").First().GetName()); + } + [Test] public void DeleteFolderShouldDeleteFilesAlso() { _azureBlobStorageProvider.CreateFile("folder/foo1.txt"); diff --git a/src/Orchard.Azure/AzureFileSystem.cs b/src/Orchard.Azure/AzureFileSystem.cs index 598974b68..f258e2f8b 100644 --- a/src/Orchard.Azure/AzureFileSystem.cs +++ b/src/Orchard.Azure/AzureFileSystem.cs @@ -51,10 +51,42 @@ namespace Orchard.Azure { } private static void EnsurePathIsRelative(string path) { - if (path.StartsWith("/") || path.StartsWith("http://")) + if ( path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://") ) throw new ArgumentException("Path must be relative"); } + public string Combine(string path1, string path2) { + if ( path1 == null) { + throw new ArgumentNullException("path1"); + } + + if ( path2 == null ) { + throw new ArgumentNullException("path2"); + } + + if ( String.IsNullOrEmpty(path2) ) { + return path1; + } + + if ( String.IsNullOrEmpty(path1) ) { + return path2; + } + + if ( path2.StartsWith("http://") || path2.StartsWith("https://") ) + { + return path2; + } + + var ch = path1[path1.Length - 1]; + + if (ch != '/') + { + return (path1.TrimEnd('/') + '/' + path2.TrimStart('/')); + } + + return (path1 + path2); + } + public IStorageFile GetFile(string path) { EnsurePathIsRelative(path); @@ -75,7 +107,7 @@ namespace Orchard.Azure { EnsurePathIsRelative(path); - string prefix = String.Concat(Container.Name, "/", _root, path); + string prefix = String.Concat(Combine(Container.Name, _root), path); if ( !prefix.EndsWith("/") ) prefix += "/"; @@ -121,7 +153,7 @@ namespace Orchard.Azure { Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path)); // Creating a virtually hidden file to make the directory an existing concept - CreateFile(path + "/" + FolderEntry); + CreateFile(Combine(path, FolderEntry)); } } @@ -263,7 +295,8 @@ namespace Orchard.Azure { } public string GetName() { - return Path.GetDirectoryName(GetPath() + "/"); + var path = GetPath(); + return path.Substring(path.LastIndexOf('/') +1 ); } public string GetPath() { diff --git a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs index 3fe95d6d5..e990545bb 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs @@ -66,7 +66,7 @@ namespace Orchard.Media.Services { _storageProvider.CreateFolder(name); return; } - _storageProvider.CreateFolder(mediaPath + "\\" + name); + _storageProvider.CreateFolder(_storageProvider.Combine(mediaPath, name)); } public void DeleteFolder(string name) { @@ -79,12 +79,12 @@ namespace Orchard.Media.Services { } public void DeleteFile(string name, string folderName) { - _storageProvider.DeleteFile(folderName + "\\" + name); + _storageProvider.DeleteFile(_storageProvider.Combine(folderName, name)); } public void RenameFile(string name, string newName, string folderName) { if (FileAllowed(newName, false)) { - _storageProvider.RenameFile(folderName + "\\" + name, folderName + "\\" + newName); + _storageProvider.RenameFile(_storageProvider.Combine(folderName, name), _storageProvider.Combine(folderName, newName)); } } @@ -193,14 +193,14 @@ namespace Orchard.Media.Services { } } - private static string RenameFolderPath(string path, string newName) { - var lastIndex = path.LastIndexOf("\\"); + private string RenameFolderPath(string path, string newName) { + var lastIndex = Math.Max(path.LastIndexOf(Path.DirectorySeparatorChar), path.LastIndexOf(Path.AltDirectorySeparatorChar)); if (lastIndex == -1) { return newName; } - return path.Substring(0, lastIndex) + "\\" + newName; + return _storageProvider.Combine(path.Substring(0, lastIndex), newName); } } } diff --git a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs index 94109df69..5d7a16f48 100644 --- a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs +++ b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs @@ -148,6 +148,10 @@ namespace Orchard.FileSystems.Media { File.Move(Map(path), Map(newPath)); } + public string Combine(string path1, string path2) { + return Path.Combine(path1, path2); + } + #endregion private class FileSystemStorageFile : IStorageFile { diff --git a/src/Orchard/FileSystems/Media/IStorageProvider.cs b/src/Orchard/FileSystems/Media/IStorageProvider.cs index b2e47c034..d6ae596a9 100644 --- a/src/Orchard/FileSystems/Media/IStorageProvider.cs +++ b/src/Orchard/FileSystems/Media/IStorageProvider.cs @@ -12,5 +12,6 @@ namespace Orchard.FileSystems.Media { void DeleteFile(string path); void RenameFile(string path, string newPath); IStorageFile CreateFile(string path); + string Combine(string path1, string path2); } } \ No newline at end of file From 2ccde50d1e21292ef8b5c66420ee1a85834f749e Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 23 Nov 2010 12:41:21 -0800 Subject: [PATCH 2/6] Fixing folder splitting display in media --HG-- branch : dev --- .../Media/AzureBlobStorageProviderTests.cs | 12 ++++++++++++ .../Modules/Orchard.Media/Helpers/MediaHelpers.cs | 5 +++-- .../Orchard.Media/Views/Admin/EditProperties.cshtml | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs index f4cbe9182..f6e4fda80 100644 --- a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs +++ b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs @@ -44,6 +44,18 @@ namespace Orchard.Azure.Tests.FileSystems.Media { _azureBlobStorageProvider.DeleteFile("notexisting"); } + [Test] + public void RootFolderAreNotCropped() { + _azureBlobStorageProvider.CreateFolder("default"); + _azureBlobStorageProvider.CreateFolder("foo"); + + var folders = _azureBlobStorageProvider.ListFolders(""); + + Assert.That(folders.Count(), Is.EqualTo(2)); + Assert.That(folders.Any(f => f.GetName() == "default"), Is.True); + Assert.That(folders.Any(f => f.GetName() == "foo"), Is.True); + } + [Test] public void CreateFileShouldReturnCorrectStorageFile() { var storageFile = _azureBlobStorageProvider.CreateFile("foo.txt"); diff --git a/src/Orchard.Web/Modules/Orchard.Media/Helpers/MediaHelpers.cs b/src/Orchard.Web/Modules/Orchard.Media/Helpers/MediaHelpers.cs index 3f0cbf032..f9cadb0b7 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Helpers/MediaHelpers.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Helpers/MediaHelpers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using Orchard.Media.Models; namespace Orchard.Media.Helpers { @@ -9,12 +10,12 @@ namespace Orchard.Media.Helpers { if (String.IsNullOrEmpty(mediaPath)) { return navigations; } - if (!mediaPath.Contains("\\")) { + if ( !mediaPath.Contains(Path.DirectorySeparatorChar.ToString()) && !mediaPath.Contains(Path.AltDirectorySeparatorChar.ToString()) ) { navigations.Add(new FolderNavigation { FolderName = mediaPath, FolderPath = mediaPath }); return navigations; } - string[] navigationParts = mediaPath.Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries); + string[] navigationParts = mediaPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries); string currentPath = String.Empty; foreach (string navigationPart in navigationParts) { currentPath = (string.IsNullOrEmpty(currentPath) ? navigationPart : currentPath + "\\" + navigationPart); diff --git a/src/Orchard.Web/Modules/Orchard.Media/Views/Admin/EditProperties.cshtml b/src/Orchard.Web/Modules/Orchard.Media/Views/Admin/EditProperties.cshtml index ffb1697a1..47fcf198a 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Views/Admin/EditProperties.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Media/Views/Admin/EditProperties.cshtml @@ -8,7 +8,7 @@

@Html.ActionLink(T("Media Folders").ToString(), "Index") > @foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) { @Html.ActionLink(navigation.FolderName, "Edit", - new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) + new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) > } @T("Folder Properties")

From 3c2b6c6111a8910e42412daa1f89402834f0aa86 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 23 Nov 2010 12:43:09 -0800 Subject: [PATCH 3/6] Fixing new content type validation Work Item: 16471 --HG-- branch : dev --- .../Orchard.ContentTypes/Controllers/AdminController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 218f6faf0..f4d408d2e 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -52,13 +52,13 @@ namespace Orchard.ContentTypes.Controllers { ModelState.AddModelError("DisplayName", T("A type with the same name already exists.").ToString()); } - var typeViewModel = _contentDefinitionService.AddType(viewModel); - if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return View(viewModel); } + var typeViewModel = _contentDefinitionService.AddType(viewModel); + Services.Notifier.Information(T("The \"{0}\" content type has been created.", typeViewModel.DisplayName)); return RedirectToAction("Edit", new { id = typeViewModel.Name }); From 1621a10cc861f4ad7540214d142525b315855094 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 23 Nov 2010 13:03:30 -0800 Subject: [PATCH 4/6] Fixing unit tests --HG-- branch : dev --- .../Commands/CodeGenerationCommandsTests.cs | 3 +++ .../Migrations/SchemaCommandGeneratorTests.cs | 3 +++ src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs | 3 +++ src/Orchard.Tests/Environment/StubHostEnvironment.cs | 9 +++++++++ src/Orchard.Tests/Logging/LoggingModuleTests.cs | 4 ++++ src/Orchard.Tests/Orchard.Framework.Tests.csproj | 1 + 6 files changed, 23 insertions(+) create mode 100644 src/Orchard.Tests/Environment/StubHostEnvironment.cs diff --git a/src/Orchard.Tests.Modules/CodeGeneration/Commands/CodeGenerationCommandsTests.cs b/src/Orchard.Tests.Modules/CodeGeneration/Commands/CodeGenerationCommandsTests.cs index d66df6694..7d9a43948 100644 --- a/src/Orchard.Tests.Modules/CodeGeneration/Commands/CodeGenerationCommandsTests.cs +++ b/src/Orchard.Tests.Modules/CodeGeneration/Commands/CodeGenerationCommandsTests.cs @@ -9,12 +9,14 @@ using Orchard.Commands; using Orchard.Data; using Orchard.Data.Migration.Generator; using Orchard.Data.Providers; +using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.Extensions; using Orchard.Environment.ShellBuilders; using Orchard.Environment.ShellBuilders.Models; using Orchard.FileSystems.AppData; using Orchard.Localization; +using Orchard.Tests.Environment; using Orchard.Tests.FileSystems.AppData; using Orchard.Tests.Stubs; @@ -49,6 +51,7 @@ namespace Orchard.Tests.Modules.CodeGeneration.Commands { builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); _container = builder.Build(); _extensionManager = _container.Resolve(); diff --git a/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs b/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs index 0bc220b34..0477f9cd1 100644 --- a/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs +++ b/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs @@ -32,6 +32,8 @@ using Orchard.Tests.FileSystems.AppData; using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records; using Path = Bleroy.FluentPath.Path; using Orchard.Tests.Stubs; +using Orchard.Tests.Environment; +using Orchard.Environment; namespace Orchard.Tests.Modules.Migrations { [TestFixture] @@ -85,6 +87,7 @@ namespace Orchard.Tests.Modules.Migrations { builder.RegisterType().As(); builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)); builder.RegisterType().As(); + builder.RegisterType().As(); _session = _sessionFactory.OpenSession(); builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As(); diff --git a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs index bc9e28ff7..cde43e1f3 100644 --- a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs +++ b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs @@ -8,12 +8,14 @@ using Orchard.Data; using Orchard.Data.Migration.Interpreters; using Orchard.Data.Migration.Schema; using Orchard.Data.Providers; +using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.ShellBuilders.Models; using Orchard.FileSystems.AppData; using Orchard.Reports.Services; using Orchard.Tests.ContentManagement; using System.IO; +using Orchard.Tests.Environment; using Orchard.Tests.FileSystems.AppData; using Orchard.Tests.Stubs; @@ -47,6 +49,7 @@ namespace Orchard.Tests.DataMigration { builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As(); builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty() }).As(); builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST" }).As(); diff --git a/src/Orchard.Tests/Environment/StubHostEnvironment.cs b/src/Orchard.Tests/Environment/StubHostEnvironment.cs new file mode 100644 index 000000000..bfac75427 --- /dev/null +++ b/src/Orchard.Tests/Environment/StubHostEnvironment.cs @@ -0,0 +1,9 @@ +using Orchard.Environment; + +namespace Orchard.Tests.Environment { + public class StubHostEnvironment : HostEnvironment { + public override void ResetSiteCompilation() { + + } + } +} diff --git a/src/Orchard.Tests/Logging/LoggingModuleTests.cs b/src/Orchard.Tests/Logging/LoggingModuleTests.cs index 733df6f09..810a27cdc 100644 --- a/src/Orchard.Tests/Logging/LoggingModuleTests.cs +++ b/src/Orchard.Tests/Logging/LoggingModuleTests.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Diagnostics; using Autofac; using NUnit.Framework; +using Orchard.Environment; using Orchard.Logging; +using Orchard.Tests.Environment; namespace Orchard.Tests.Logging { [TestFixture] @@ -13,6 +15,7 @@ namespace Orchard.Tests.Logging { var builder = new ContainerBuilder(); builder.RegisterModule(new LoggingModule()); builder.RegisterType(); + builder.RegisterType().As(); var container = builder.Build(); var thing = container.Resolve(); Assert.That(thing.Logger, Is.Not.Null); @@ -46,6 +49,7 @@ namespace Orchard.Tests.Logging { var builder = new ContainerBuilder(); builder.RegisterModule(new LoggingModule()); builder.RegisterType(); + builder.RegisterType().As(); var container = builder.Build(); var thing = container.Resolve(); Assert.That(thing.Logger, Is.Not.Null); diff --git a/src/Orchard.Tests/Orchard.Framework.Tests.csproj b/src/Orchard.Tests/Orchard.Framework.Tests.csproj index 934b2c6e9..208366c7d 100644 --- a/src/Orchard.Tests/Orchard.Framework.Tests.csproj +++ b/src/Orchard.Tests/Orchard.Framework.Tests.csproj @@ -226,6 +226,7 @@ + From 01e792e82ed9fc6864465085501859a0689634d8 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 23 Nov 2010 13:23:01 -0800 Subject: [PATCH 5/6] Fixing search qurey validation Work Item: 16556 --HG-- branch : dev --- .../Controllers/SearchController.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs index 163970768..46a524376 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs @@ -1,9 +1,11 @@ -using System.Linq; +using System; +using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.DisplayManagement; using Orchard.Indexing; using Orchard.Localization; +using Orchard.Logging; using Orchard.Search.Services; using Orchard.Search.ViewModels; using Orchard.Search.Models; @@ -29,26 +31,29 @@ namespace Orchard.Search.Controllers { _contentManager = contentManager; T = NullLocalizer.Instance; + Logger = NullLogger.Instance; Shape = shapeFactory; } private IOrchardServices Services { get; set; } public Localizer T { get; set; } + public ILogger Logger { get; set; } dynamic Shape { get; set; } public ActionResult Index(Pager pager, string q = "") { var searchFields = Services.WorkContext.CurrentSite.As().SearchedFields; - IPageOfItems searchHits; - if (q.Trim().StartsWith("?") || q.Trim().StartsWith("*")) { - searchHits = new PageOfItems(new ISearchHit[] { }); - Services.Notifier.Error(T("'*' or '?' not allowed as first character in WildcardQuery")); - } - else { + IPageOfItems searchHits = new PageOfItems(new ISearchHit[] { }); + try { + searchHits = _searchService.Query(q, pager.Page, pager.PageSize, - Services.WorkContext.CurrentSite.As().Record.FilterCulture, - searchFields, - searchHit => searchHit); + Services.WorkContext.CurrentSite.As().Record.FilterCulture, + searchFields, + searchHit => searchHit); + } + catch(Exception e) { + Services.Notifier.Error(T("Invalid search query: {0}", q)); + Logger.Error(e, "Invalid search query: " + q); } var list = Shape.List(); From 2f35839887f30fa094c4853c16500a76f827e71d Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 23 Nov 2010 13:28:40 -0800 Subject: [PATCH 6/6] Fixing trailing slash issue on Azure media folders --HG-- branch : dev extra : transplant_source : %D2%A0%A7%8DG%09%B6f%F5%AE%A2w%7D%AD%5E%02%DEa%9D%AB --- src/Orchard.Azure/AzureFileSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Azure/AzureFileSystem.cs b/src/Orchard.Azure/AzureFileSystem.cs index f258e2f8b..5c690c521 100644 --- a/src/Orchard.Azure/AzureFileSystem.cs +++ b/src/Orchard.Azure/AzureFileSystem.cs @@ -256,7 +256,7 @@ namespace Orchard.Azure { } public string GetPath() { - return _blob.Uri.ToString().Substring(_rootPath.Length+1); + return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/'); } public string GetName() { @@ -300,7 +300,7 @@ namespace Orchard.Azure { } public string GetPath() { - return _blob.Uri.ToString().Substring(_rootPath.Length + 1).TrimEnd('/'); + return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/'); } public long GetSize() {