/// <summary> /// Checks if files can be uploaded in a directory. Files can be uploaded if the directory allows file upload in root, /// if files can be uploaded in path and does not contain sub directories /// </summary> /// <param name="parentPath">The path the user wants to upload to</param> /// <param name="fullPath">The full path</param> /// <param name="userUuid">The uuid of the requesting user</param> /// <returns>True if the above conditions are met false if not</returns> public static async Task <bool> CanUploadFilesInDirectory(string parentPath, string fullPath, Guid userUuid) { if (!Directory.Exists(fullPath)) { return(false); } if (!PathIsValid(parentPath)) { return(false); } bool directoryContainsFolders = GetFoldersInDirectory(fullPath).Any(); if (directoryContainsFolders) { return(false); } FilePath filePathInfo = FilePathInfo.Find(parentPath); if (!filePathInfo.FilePathOptions.AllowFileUploadInRoot && parentPath == filePathInfo.Path) { return(false); } var directoryInfoFile = await GetInfoFileFromDirectory($"{Environment.CurrentDirectory}/Media{filePathInfo.Path}"); if (!filePathInfo.FilePathOptions.AllowMultipleFilesByUser && directoryInfoFile.FileInfo.Exists(fi => fi.FileOwnerUuid == userUuid)) { return(false); } return(true); }
/// <summary> /// Checks if an folder can be created in the parent path. Folders can be created if the directory does not contain files, /// the parent directory allows that folders can be created /// </summary> /// <param name="parentPath"></param> /// <returns></returns> public static bool CanCreateFolderInDirectory(string parentPath) { if (!PathIsValid(parentPath)) { return(false); } FilePath filePathInfo = FilePathInfo.Find(parentPath); if (!filePathInfo.FilePathOptions.AllowFolderCreation) { return(false); } string fullPath = FixPath($"{Environment.CurrentDirectory}/Media{parentPath}"); if (GetFilesInDirectory(fullPath).Any()) { return(false); } return(true); }