Remove a bunch of partial views related, unreferenced methods from file service and partial view repositories (#9879)
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.IO;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Core.Persistence.Repositories
|
||||
@@ -7,9 +6,5 @@ namespace Umbraco.Cms.Core.Persistence.Repositories
|
||||
{
|
||||
void AddFolder(string folderPath);
|
||||
void DeleteFolder(string folderPath);
|
||||
bool ValidatePartialView(IPartialView partialView);
|
||||
Stream GetFileContentStream(string filepath);
|
||||
void SetFileContent(string filepath, Stream content);
|
||||
long GetFileSize(string filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,12 @@ namespace Umbraco.Cms.Core.Services
|
||||
void DeletePartialViewMacroFolder(string folderPath);
|
||||
IPartialView GetPartialView(string path);
|
||||
IPartialView GetPartialViewMacro(string path);
|
||||
IEnumerable<IPartialView> GetPartialViewMacros(params string[] names);
|
||||
Attempt<IPartialView> CreatePartialView(IPartialView partialView, string snippetName = null, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = Constants.Security.SuperUserId);
|
||||
bool DeletePartialView(string path, int userId = Constants.Security.SuperUserId);
|
||||
bool DeletePartialViewMacro(string path, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = Constants.Security.SuperUserId);
|
||||
bool ValidatePartialView(IPartialView partialView);
|
||||
bool ValidatePartialViewMacro(IPartialView partialView);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="IStylesheet"/> objects
|
||||
@@ -203,48 +200,6 @@ namespace Umbraco.Cms.Core.Services
|
||||
/// <returns>The size of the stylesheet.</returns>
|
||||
long GetStylesheetFileSize(string filepath);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of a macro partial view as a stream.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the macro partial view.</param>
|
||||
/// <returns>The content of the macro partial view.</returns>
|
||||
Stream GetPartialViewMacroFileContentStream(string filepath);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the content of a macro partial view.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the macro partial view.</param>
|
||||
/// <param name="content">The content of the macro partial view.</param>
|
||||
void SetPartialViewMacroFileContent(string filepath, Stream content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of a macro partial view.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the macro partial view.</param>
|
||||
/// <returns>The size of the macro partial view.</returns>
|
||||
long GetPartialViewMacroFileSize(string filepath);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of a partial view as a stream.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the partial view.</param>
|
||||
/// <returns>The content of the partial view.</returns>
|
||||
Stream GetPartialViewFileContentStream(string filepath);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the content of a partial view.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the partial view.</param>
|
||||
/// <param name="content">The content of the partial view.</param>
|
||||
void SetPartialViewFileContent(string filepath, Stream content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of a partial view.
|
||||
/// </summary>
|
||||
/// <param name="filepath">The filesystem path to the partial view.</param>
|
||||
/// <returns>The size of the partial view.</returns>
|
||||
long GetPartialViewFileSize(string filepath);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of a macro partial view snippet as a string
|
||||
/// </summary>
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class PartialViewMacroRepository : PartialViewRepository, IPartialViewMacroRepository
|
||||
{
|
||||
public PartialViewMacroRepository(FileSystems fileSystems, IIOHelper ioHelper)
|
||||
: base(fileSystems.MacroPartialsFileSystem, ioHelper)
|
||||
public PartialViewMacroRepository(FileSystems fileSystems)
|
||||
: base(fileSystems.MacroPartialsFileSystem)
|
||||
{ }
|
||||
|
||||
protected override PartialViewType ViewType => PartialViewType.PartialViewMacro;
|
||||
|
||||
@@ -11,18 +11,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public PartialViewRepository(FileSystems fileSystems, IIOHelper ioHelper)
|
||||
public PartialViewRepository(FileSystems fileSystems)
|
||||
: base(fileSystems.PartialViewsFileSystem)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
protected PartialViewRepository(IFileSystem fileSystem, IIOHelper ioHelper)
|
||||
protected PartialViewRepository(IFileSystem fileSystem)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
protected virtual PartialViewType ViewType => PartialViewType.PartialView;
|
||||
@@ -93,29 +89,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly List<string> ValidExtensions = new List<string> { "cshtml" };
|
||||
|
||||
public virtual bool ValidatePartialView(IPartialView partialView)
|
||||
{
|
||||
// get full path
|
||||
string fullPath;
|
||||
try
|
||||
{
|
||||
// may throw for security reasons
|
||||
fullPath = FileSystem.GetFullPath(partialView.Path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// validate path & extension
|
||||
var validDir = Cms.Core.Constants.SystemDirectories.MvcViews;
|
||||
var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir);
|
||||
var isValidExtension = _ioHelper.VerifyFileExtension(fullPath, ValidExtensions);
|
||||
return isValidPath && isValidExtension;
|
||||
}
|
||||
|
||||
public Stream GetFileContentStream(string filepath)
|
||||
{
|
||||
if (FileSystem.FileExists(filepath) == false) return null;
|
||||
|
||||
@@ -600,14 +600,6 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IPartialView> GetPartialViewMacros(params string[] names)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewMacroRepository.GetMany(names).OrderBy(x => x.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public Attempt<IPartialView> CreatePartialView(IPartialView partialView, string snippetName = null, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
return CreatePartialViewMacro(partialView, PartialViewType.PartialView, snippetName, userId);
|
||||
@@ -762,22 +754,6 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
return Attempt.Succeed(partialView);
|
||||
}
|
||||
|
||||
public bool ValidatePartialView(IPartialView partialView)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewRepository.ValidatePartialView(partialView);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidatePartialViewMacro(IPartialView partialView)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewMacroRepository.ValidatePartialView(partialView);
|
||||
}
|
||||
}
|
||||
|
||||
internal string StripPartialViewHeader(string contents)
|
||||
{
|
||||
var headerMatch = new Regex("^@inherits\\s+?.*$", RegexOptions.Multiline);
|
||||
@@ -797,40 +773,6 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
: Attempt<string>.Fail();
|
||||
}
|
||||
|
||||
public Stream GetPartialViewMacroFileContentStream(string filepath)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewMacroRepository.GetFileContentStream(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPartialViewMacroFileContent(string filepath, Stream content)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
_partialViewMacroRepository.SetFileContent(filepath, content);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public Stream GetPartialViewFileContentStream(string filepath)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewRepository.GetFileContentStream(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPartialViewFileContent(string filepath, Stream content)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
_partialViewRepository.SetFileContent(filepath, content);
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void CreatePartialViewFolder(string folderPath)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
@@ -849,22 +791,6 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public long GetPartialViewMacroFileSize(string filepath)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewMacroRepository.GetFileSize(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
public long GetPartialViewFileSize(string filepath)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _partialViewRepository.GetFileSize(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
private IPartialViewRepository GetPartialViewRepository(PartialViewType partialViewType)
|
||||
{
|
||||
switch (partialViewType)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos
|
||||
IScopeProvider provider = ScopeProvider;
|
||||
using (IScope scope = provider.CreateScope())
|
||||
{
|
||||
var repository = new PartialViewRepository(fileSystems, IOHelper);
|
||||
var repository = new PartialViewRepository(fileSystems);
|
||||
|
||||
var partialView = new PartialView(PartialViewType.PartialView, "test-path-1.cshtml") { Content = "// partialView" };
|
||||
repository.Save(partialView);
|
||||
|
||||
Reference in New Issue
Block a user