Skip to content

Commit

Permalink
Merge pull request #458 from ONLYOFFICE/bugfix/65023
Browse files Browse the repository at this point in the history
Bugfix/65023
  • Loading branch information
AlexeySafronov authored Aug 2, 2024
2 parents b30bd4a + 15fc64c commit f9155cd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 44 deletions.
2 changes: 2 additions & 0 deletions products/ASC.Files/Core/ApiModels/ResponseDto/FileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public class FileDto<T> : FileEntryDto<T>
public IDictionary<string, bool> AvailableExternalRights { get; set; }
public string RequestToken { get; set; }
public ApiDateTime LastOpened { get; set; }

public override FileEntryType FileEntryType { get => FileEntryType.File; }

public static FileDto<int> GetSample()
{
Expand Down
2 changes: 2 additions & 0 deletions products/ASC.Files/Core/ApiModels/ResponseDto/FileEntryDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public ApiDateTime Updated
public int? ProviderId { get; set; }

public string Order { get; set; }

public abstract FileEntryType FileEntryType { get; }

protected FileEntryDto(FileEntry entry)
{
Expand Down
3 changes: 3 additions & 0 deletions products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class FolderDto<T> : FileEntryDto<T>
/// <summary>Counter</summary>
/// <type>System.Nullable{System.Int64}, System</type>
public long? UsedSpace { get; set; }

public override FileEntryType FileEntryType { get => FileEntryType.Folder; }

public static FolderDto<int> GetSample()
{
return new FolderDto<int>
Expand Down
26 changes: 9 additions & 17 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,15 @@ public Task<IDictionary<int, string>> CanMoveOrCopyAsync(IEnumerable<int> folder
}

public async Task<IDictionary<int, string>> CanMoveOrCopyAsync(IEnumerable<int> folderIds, int to)
{
var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

{
var result = new Dictionary<int, string>();

if (!folderIds.Any())
{
return result;
}

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
foreach (var folderId in folderIds)
{
Expand All @@ -828,19 +832,7 @@ public async Task<IDictionary<int, string>> CanMoveOrCopyAsync(IEnumerable<int>

if (conflict != 0)
{
var files = filesDbContext.DbFilesAsync(tenantId, folderId, conflict);

await foreach (var file in files)
{
result[file.Id] = file.Title;
}

var children = await filesDbContext.ArrayAsync(tenantId, folderId).ToListAsync();

foreach (var pair in await CanMoveOrCopyAsync(children, conflict))
{
result.Add(pair.Key, pair.Value);
}
result[folderId] = "";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ private async Task DoAsync<TTo>(IServiceScope scope, TTo tto)
int.TryParse(toRoom.Id.ToString(), out var trId) &&
trId != frId)
{
if (Folders.Count > 0)
{
this[Err] = FilesCommonResource.ErrorMessage_FolderMoveFormFillingError;
if (Folders.Count > 0)
{
this[Err] = FilesCommonResource.ErrorMessage_FolderMoveFormFillingError;

return;
}
if (Files.Count > 1)
{
this[Err] = FilesCommonResource.ErrorMessage_FilesMoveFormFillingError;
return;
}
if (Files.Count > 1)
{
this[Err] = FilesCommonResource.ErrorMessage_FilesMoveFormFillingError;

return;
}
return;
}
}
}

var isRoom = false;

Expand Down Expand Up @@ -345,7 +345,7 @@ private async Task<List<Folder<TTo>>> MoveOrCopyFoldersAsync<TTo>(IServiceScope

var folder = await FolderDao.GetFolderAsync(folderId);
var cacheKey = "parentRoomInfo" + folder.ParentId;

var parentFolderTask = FolderDao.GetFolderAsync(folder.ParentId);

var parentRoomId = cache.Get<string>(cacheKey);
Expand Down Expand Up @@ -478,17 +478,17 @@ private async Task<List<Folder<TTo>>> MoveOrCopyFoldersAsync<TTo>(IServiceScope
{
if (conflictFolder != null)
{
if (!conflictFolder.ProviderEntry)
if (!conflictFolder.ProviderEntry && _resolveType == FileConflictResolveType.Duplicate)
{
conflictFolder.Id = default;
conflictFolder.Title = await global.GetAvailableTitleAsync(conflictFolder.Title, conflictFolder.ParentId, folderDao.IsExistAsync, FileEntryType.Folder);
conflictFolder.Id = await folderDao.SaveFolderAsync(conflictFolder);
}

newFolder = conflictFolder;

await filesMessageService.SendCopyMessageAsync(newFolder, await parentFolderTask, toFolder, toFolderParents, false, _headers, [newFolder.Title, toFolder.Title, toFolder.Id.ToString()]);

if (isToFolder)
{
needToMark.Add(conflictFolder);
Expand Down Expand Up @@ -536,7 +536,7 @@ private async Task<List<Folder<TTo>>> MoveOrCopyFoldersAsync<TTo>(IServiceScope
await filesMessageService.SendAsync(MessageAction.RoomCopied, newFolder, _headers, newFolder.Title);
}
else
{
{
await filesMessageService.SendCopyMessageAsync(newFolder, await parentFolderTask, toFolder, toFolderParents, false, _headers, [newFolder.Title, toFolder.Title, toFolder.Id.ToString()]);
}

Expand Down Expand Up @@ -583,13 +583,23 @@ private async Task<List<Folder<TTo>>> MoveOrCopyFoldersAsync<TTo>(IServiceScope
else
{
if (conflictFolder != null)
{
{
if (_resolveType == FileConflictResolveType.Overwrite)
{
if (ProcessedFolder(folderId))
{
sb.Append($"folder_{folderId}{SplitChar}");
}

continue;
}

TTo newFolderId;
if (copy)
{
newFolder = await FolderDao.CopyFolderAsync(folder.Id, toFolderId, CancellationToken);
newFolderId = newFolder.Id;

await filesMessageService.SendCopyMessageAsync(newFolder, await parentFolderTask, toFolder, toFolderParents, true, _headers, [newFolder.Title, toFolder.Title, toFolder.Id.ToString()]);

if (isToFolder)
Expand Down Expand Up @@ -742,7 +752,7 @@ await socketManager.DeleteFolder(folder, action: async () =>
if (newFolder != null)
{
await filesMessageService.SendMoveMessageAsync(newFolder, parentFolder, toFolder, toFolderParents, true, _headers, [folder.Title, parentFolder.Title, toFolder.Title, toFolder.Id.ToString()]);
}
}
}


Expand Down Expand Up @@ -927,7 +937,7 @@ private async Task<List<FileEntry<TTo>>> MoveOrCopyFilesAsync<TTo>(IServiceScope
TTo newFileId = default;
await socketManager.DeleteFileAsync(file, action: async () => newFileId = await FileDao.MoveFileAsync(file.Id, toFolderId, deleteLinks));
newFile = await fileDao.GetFileAsync(newFileId);

await filesMessageService.SendMoveMessageAsync(newFile, parentFolder, toFolder, toParentFolders, false, _headers, [file.Title, parentFolder.Title, toFolder.Title, toFolder.Id.ToString()]);

if (file.RootFolderType == FolderType.TRASH && newFile.ThumbnailStatus == Thumbnail.NotRequired)
Expand Down Expand Up @@ -1069,7 +1079,7 @@ await socketManager.DeleteFileAsync(file, action: async () =>
await LinkDao.DeleteAllLinkAsync(file.Id);
});

await filesMessageService.SendMoveMessageAsync(newFile, parentFolder, toFolder, toParentFolders, true, _headers, [file.Title, parentFolder.Title, toFolder.Title, toFolder.Id.ToString()]);

if (ProcessedFile(fileId))
Expand Down
12 changes: 6 additions & 6 deletions products/ASC.Files/Server/Api/OperationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,20 @@ async IAsyncEnumerable<FileEntryDto> GetFilesDto(IEnumerable<FileEntry> fileEntr
public async IAsyncEnumerable<FileEntryDto> MoveOrCopyBatchCheckAsync([ModelBinder(BinderType = typeof(BatchModelBinder))] BatchRequestDto inDto)
{
List<object> checkedFiles;
List<object> checkedFolders;

if (inDto.DestFolderId.ValueKind == JsonValueKind.Number)
{
(checkedFiles, _) = await fileStorageService.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetInt32());
(checkedFiles, checkedFolders) = await fileStorageService.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetInt32());
}
else
{
(checkedFiles, _) = await fileStorageService.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetString());
(checkedFiles, checkedFolders) = await fileStorageService.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetString());
}

var entries = await fileStorageService.GetItemsAsync(checkedFiles.OfType<int>().Select(Convert.ToInt32), checkedFiles.OfType<int>().Select(Convert.ToInt32), FilterType.FilesOnly, false);

entries.AddRange(await fileStorageService.GetItemsAsync(checkedFiles.OfType<string>(), [], FilterType.FilesOnly, false));

var entries = await fileStorageService.GetItemsAsync(checkedFiles.OfType<int>().Select(Convert.ToInt32), checkedFolders.OfType<int>().Select(Convert.ToInt32), FilterType.None, false);
entries.AddRange(await fileStorageService.GetItemsAsync(checkedFiles.OfType<string>(), checkedFolders.OfType<string>(), FilterType.None, false));

foreach (var e in entries)
{
yield return await GetFileEntryWrapperAsync(e);
Expand Down

0 comments on commit f9155cd

Please sign in to comment.