Make an exception for root path (#15570)

This commit is contained in:
Mole
2024-01-12 12:29:23 +01:00
committed by GitHub
parent c5c24d36d9
commit a8fd00a3b4
3 changed files with 14 additions and 5 deletions

View File

@@ -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)
{

View File

@@ -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);
}

View File

@@ -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;
}