Make an exception for root path (#15570)
This commit is contained in:
@@ -39,6 +39,15 @@ public abstract class FileServiceBase<TRepository, TEntity> : RepositoryService,
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a path is considered a root path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to check.</param>
|
||||
/// <returns>True if the path is considered a root path.</returns>
|
||||
protected virtual bool IsRootPath(string? path)
|
||||
// We use "/" here instead of path separator because it's the virtual path used by backoffice, and not an actual FS path.
|
||||
=> string.IsNullOrWhiteSpace(path) || path == "/";
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<TEntity?> GetAsync(string path)
|
||||
{
|
||||
|
||||
@@ -105,13 +105,13 @@ public class ScriptService : FileServiceBase<IScriptRepository, IScript>, IScrip
|
||||
return Task.FromResult(ScriptOperationStatus.AlreadyExists);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(createModel.ParentPath) is false &&
|
||||
Repository.FolderExists(createModel.ParentPath) is false)
|
||||
if (IsRootPath(createModel.ParentPath) is false &&
|
||||
Repository.FolderExists(createModel.ParentPath!) is false)
|
||||
{
|
||||
return Task.FromResult(ScriptOperationStatus.ParentNotFound);
|
||||
}
|
||||
|
||||
if(HasValidFileName(createModel.Name) is false)
|
||||
if (HasValidFileName(createModel.Name) is false)
|
||||
{
|
||||
return Task.FromResult(ScriptOperationStatus.InvalidName);
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ public class StylesheetService : FileServiceBase<IStylesheetRepository, IStylesh
|
||||
return StylesheetOperationStatus.AlreadyExists;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(createModel.ParentPath) is false
|
||||
&& Repository.FolderExists(createModel.ParentPath) is false)
|
||||
if (IsRootPath(createModel.ParentPath) is false
|
||||
&& Repository.FolderExists(createModel.ParentPath!) is false)
|
||||
{
|
||||
return StylesheetOperationStatus.ParentNotFound;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user