diff --git a/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs index 6d2dd4bc57..d3835b8e7e 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs @@ -1,15 +1,9 @@ -using System.IO; using Umbraco.Cms.Core.Models; namespace Umbraco.Cms.Core.Persistence.Repositories { public interface IScriptRepository : IReadRepository, IWriteRepository { - bool ValidateScript(IScript script); - Stream GetFileContentStream(string filepath); - void SetFileContent(string filepath, Stream content); - long GetFileSize(string filepath); - void AddFolder(string folderPath); void DeleteFolder(string folderPath); } diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs index 1f4d33388c..c2d99aceed 100644 --- a/src/Umbraco.Core/Services/IFileService.cs +++ b/src/Umbraco.Core/Services/IFileService.cs @@ -61,12 +61,6 @@ namespace Umbraco.Cms.Core.Services /// True if Stylesheet is valid, otherwise false bool ValidateStylesheet(IStylesheet stylesheet); - /// - /// Gets a list of all objects - /// - /// An enumerable list of objects - IEnumerable GetScripts(params string[] names); - /// /// Gets a object by its name /// @@ -88,13 +82,6 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user deleting the script void DeleteScript(string path, int userId = Constants.Security.SuperUserId); - /// - /// Validates a - /// - /// to validate - /// True if Script is valid, otherwise false - bool ValidateScript(IScript script); - /// /// Creates a folder for scripts /// @@ -216,27 +203,6 @@ namespace Umbraco.Cms.Core.Services /// The size of the stylesheet. long GetStylesheetFileSize(string filepath); - /// - /// Gets the content of a script file as a stream. - /// - /// The filesystem path to the script. - /// The content of the script file. - Stream GetScriptFileContentStream(string filepath); - - /// - /// Sets the content of a script file. - /// - /// The filesystem path to the script. - /// The content of the script file. - void SetScriptFileContent(string filepath, Stream content); - - /// - /// Gets the size of a script file. - /// - /// The filesystem path to the script file. - /// The size of the script file. - long GetScriptFileSize(string filepath); - /// /// Gets the content of a macro partial view as a stream. /// diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/FileRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/FileRepository.cs index 742f4ab94c..2e7e8af144 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/FileRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/FileRepository.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Text; using Umbraco.Cms.Core.IO; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs index 77b8ac9e20..3cebe816fb 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; @@ -16,14 +12,9 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement /// internal class ScriptRepository : FileRepository, IScriptRepository { - private readonly IIOHelper _ioHelper; - private readonly GlobalSettings _globalSettings; - - public ScriptRepository(FileSystems fileSystems, IIOHelper ioHelper, IOptions globalSettings) + public ScriptRepository(FileSystems fileSystems) : base(fileSystems.ScriptsFileSystem) { - _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - _globalSettings = globalSettings.Value; } #region Implementation of IRepository @@ -93,47 +84,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement } } - public bool ValidateScript(IScript script) - { - // get full path - string fullPath; - try - { - // may throw for security reasons - fullPath = FileSystem.GetFullPath(script.Path); - } - catch - { - return false; - } - - // validate path & extension - var validDir = _globalSettings.UmbracoScriptsPath; - var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir); - var validExts = new[] {"js"}; - var isValidExtension = _ioHelper.VerifyFileExtension(script.Path, validExts); - return isValidPath && isValidExtension; - } - - public Stream GetFileContentStream(string filepath) - { - if (FileSystem.FileExists(filepath) == false) return null; - - try - { - return FileSystem.OpenFile(filepath); - } - catch - { - return null; // deal with race conds - } - } - - public void SetFileContent(string filepath, Stream content) - { - FileSystem.AddFile(filepath, content, true); - } - #endregion } } diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 0a01f345dc..d946863781 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -179,15 +179,6 @@ namespace Umbraco.Cms.Core.Services.Implement #region Scripts - /// - public IEnumerable GetScripts(params string[] names) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _scriptRepository.GetMany(names); - } - } - /// public IScript GetScriptByName(string name) { @@ -246,15 +237,6 @@ namespace Umbraco.Cms.Core.Services.Implement } } - /// - public bool ValidateScript(IScript script) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _scriptRepository.ValidateScript(script); - } - } - public void CreateScriptFolder(string folderPath) { using (var scope = ScopeProvider.CreateScope()) @@ -273,31 +255,6 @@ namespace Umbraco.Cms.Core.Services.Implement } } - public Stream GetScriptFileContentStream(string filepath) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _scriptRepository.GetFileContentStream(filepath); - } - } - - public void SetScriptFileContent(string filepath, Stream content) - { - using (var scope = ScopeProvider.CreateScope()) - { - _scriptRepository.SetFileContent(filepath, content); - scope.Complete(); - } - } - - public long GetScriptFileSize(string filepath) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _scriptRepository.GetFileSize(filepath); - } - } - #endregion #region Templates diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs index 001fd89f03..28f9a9eff1 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos private IScriptRepository CreateRepository() { var globalSettings = new GlobalSettings(); - return new ScriptRepository(_fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings)); + return new ScriptRepository(_fileSystems); } [Test]