U4-9926 - fix partial view macro udis

This commit is contained in:
Stephan
2017-05-17 12:09:28 +02:00
parent 70507501bd
commit 147a1daf6d
9 changed files with 33 additions and 23 deletions

View File

@@ -2,6 +2,6 @@
{
public interface IPartialView : IFile
{
PartialViewType ViewType { get; }
}
}

View File

@@ -1,10 +1,8 @@
using System;
using System.Runtime.Serialization;
using Umbraco.Core.Services;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Partial View file
/// </summary>
@@ -12,14 +10,21 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public class PartialView : File, IPartialView
{
[Obsolete("Use the ctor that explicitely sets the view type.")]
public PartialView(string path)
: this(path, null)
: this(PartialViewType.PartialView, path, null)
{ }
internal PartialView(string path, Func<File, string> getFileContent)
public PartialView(PartialViewType viewType, string path)
: this(viewType, path, null)
{ }
internal PartialView(PartialViewType viewType, string path, Func<File, string> getFileContent)
: base(path, getFileContent)
{ }
{
ViewType = viewType;
}
internal PartialViewType ViewType { get; set; }
public PartialViewType ViewType { get; set; }
}
}

View File

@@ -1,6 +1,6 @@
namespace Umbraco.Core.Models
{
internal enum PartialViewType : byte
public enum PartialViewType : byte
{
Unknown = 0, // default
PartialView = 1,

View File

@@ -30,7 +30,7 @@ namespace Umbraco.Core.Persistence.Repositories
var updated = FileSystem.GetLastModified(path).UtcDateTime;
//var content = GetFileContent(path);
var view = new PartialView(path, file => GetFileContent(file.OriginalPath))
var view = new PartialView(ViewType, path, file => GetFileContent(file.OriginalPath))
{
//id can be the hash
Id = path.GetHashCode(),
@@ -38,8 +38,7 @@ namespace Umbraco.Core.Persistence.Repositories
//Content = content,
CreateDate = created,
UpdateDate = updated,
VirtualPath = FileSystem.GetUrl(id),
ViewType = ViewType
VirtualPath = FileSystem.GetUrl(id)
};
//on initial construction we don't want to have dirty properties tracked

View File

@@ -198,7 +198,13 @@ namespace Umbraco.Core
public static StringUdi GetUdi(this IPartialView entity)
{
if (entity == null) throw new ArgumentNullException("entity");
return new StringUdi(Constants.UdiEntityType.PartialView, entity.Path.TrimStart('/')).EnsureClosed();
// we should throw on Unknown but for the time being, assume it means PartialView
var entityType = entity.ViewType == PartialViewType.PartialViewMacro
? Constants.UdiEntityType.PartialViewMacro
: Constants.UdiEntityType.PartialView;
return new StringUdi(entityType, entity.Path.TrimStart('/')).EnsureClosed();
}
/// <summary>

View File

@@ -37,14 +37,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
var repository = new PartialViewRepository(unitOfWork, _fileSystem);
var partialView = new PartialView("test-path-1.cshtml") { Content = "// partialView" };
var partialView = new PartialView(PartialViewType.PartialView, "test-path-1.cshtml") { Content = "// partialView" };
repository.AddOrUpdate(partialView);
unitOfWork.Commit();
Assert.IsTrue(_fileSystem.FileExists("test-path-1.cshtml"));
Assert.AreEqual("test-path-1.cshtml", partialView.Path);
Assert.AreEqual("/Views/Partials/test-path-1.cshtml", partialView.VirtualPath);
partialView = new PartialView("path-2/test-path-2.cshtml") { Content = "// partialView" };
partialView = new PartialView(PartialViewType.PartialView, "path-2/test-path-2.cshtml") { Content = "// partialView" };
repository.AddOrUpdate(partialView);
unitOfWork.Commit();
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.cshtml"));
@@ -56,7 +56,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreEqual("path-2\\test-path-2.cshtml", partialView.Path);
Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);
partialView = new PartialView("path-2\\test-path-3.cshtml") { Content = "// partialView" };
partialView = new PartialView(PartialViewType.PartialView, "path-2\\test-path-3.cshtml") { Content = "// partialView" };
repository.AddOrUpdate(partialView);
unitOfWork.Commit();
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.cshtml"));
@@ -73,7 +73,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreEqual("path-2\\test-path-3.cshtml", partialView.Path);
Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);
partialView = new PartialView("\\test-path-4.cshtml") { Content = "// partialView" };
partialView = new PartialView(PartialViewType.PartialView, "\\test-path-4.cshtml") { Content = "// partialView" };
Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
{
repository.AddOrUpdate(partialView);

View File

@@ -42,13 +42,13 @@ namespace Umbraco.Web.Editors
switch (type)
{
case Core.Constants.Trees.PartialViews:
var view = new PartialView(display.VirtualPath);
var view = new PartialView(PartialViewType.PartialView, display.VirtualPath);
view.Content = display.Content;
var result = Services.FileService.CreatePartialView(view, display.Snippet, Security.CurrentUser.Id);
return result.Success == true ? Request.CreateResponse(HttpStatusCode.OK) : Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
case Core.Constants.Trees.PartialViewMacros:
var viewMacro = new PartialView(display.VirtualPath);
var viewMacro = new PartialView(PartialViewType.PartialViewMacro, display.VirtualPath);
viewMacro.Content = display.Content;
var resultMacro = Services.FileService.CreatePartialViewMacro(viewMacro, display.Snippet, Security.CurrentUser.Id);
return resultMacro.Success == true ? Request.CreateResponse(HttpStatusCode.OK) : Request.CreateNotificationValidationErrorResponse(resultMacro.Exception.Message);
@@ -219,13 +219,13 @@ namespace Umbraco.Web.Editors
switch (type)
{
case Core.Constants.Trees.PartialViews:
codeFileDisplay = Mapper.Map<IPartialView, CodeFileDisplay>(new PartialView(string.Empty));
codeFileDisplay = Mapper.Map<IPartialView, CodeFileDisplay>(new PartialView(PartialViewType.PartialView, string.Empty));
codeFileDisplay.VirtualPath = SystemDirectories.PartialViews;
if (snippetName.IsNullOrWhiteSpace() == false)
codeFileDisplay.Content = Services.FileService.GetPartialViewSnippetContent(snippetName);
break;
case Core.Constants.Trees.PartialViewMacros:
codeFileDisplay = Mapper.Map<IPartialView, CodeFileDisplay>(new PartialView(string.Empty));
codeFileDisplay = Mapper.Map<IPartialView, CodeFileDisplay>(new PartialView(PartialViewType.PartialViewMacro, string.Empty));
codeFileDisplay.VirtualPath = SystemDirectories.MacroPartials;
if (snippetName.IsNullOrWhiteSpace() == false)
codeFileDisplay.Content = Services.FileService.GetPartialViewMacroSnippetContent(snippetName);
@@ -475,7 +475,7 @@ namespace Umbraco.Web.Editors
}
else
{
view = new PartialView(virtualPath + display.Name);
view = new PartialView(PartialViewType.PartialView, virtualPath + display.Name);
view.Content = display.Content;
partialViewResult = createView(view, display.Snippet, Security.CurrentUser.Id);
}

View File

@@ -103,7 +103,7 @@ namespace Umbraco.Web.WebServices
: get(svce, oldname);
if (currentView == null)
currentView = new PartialView(filename);
currentView = new PartialView(PartialViewType.PartialView, filename);
else
currentView.Path = filename;
currentView.Content = contents;

View File

@@ -46,7 +46,7 @@ namespace umbraco
fileName += ".cshtml";
}
var model = new PartialView(fileName);
var model = new PartialView(IsPartialViewMacro ? PartialViewType.PartialViewMacro : PartialViewType.PartialView, fileName);
var fileService = (FileService)ApplicationContext.Current.Services.FileService;
var macroService = ApplicationContext.Current.Services.MacroService;