Files: audit edits

This commit is contained in:
Maksim Chegulov 2023-03-13 19:03:50 +03:00
parent 0c7410814d
commit 8b33140c65
3 changed files with 23 additions and 34 deletions

View File

@ -1506,7 +1506,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
{
var rootFolderType = fileEntry.RootFolderType;
if (rootFolderType != FolderType.VirtualRooms)
if (rootFolderType != FolderType.VirtualRooms && rootFolderType != FolderType.Archive)
{
return (-1,"");
}
@ -1519,26 +1519,14 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
return (-1, "");
}
var parentId = Convert.ToInt32(fileEntry.ParentId);
var folderId = Convert.ToInt32(fileEntry.ParentId);
using var filesDbContext = _dbContextFactory.CreateDbContext();
if (rootFolderId == parentId)
if (rootFolderId == folderId)
{
return (entryId, fileEntry.Title);
}
int folderId;
var entryType = fileEntry.FileEntryType;
if (entryType == FileEntryType.File)
{
folderId = parentId;
}
else
{
folderId = entryId;
}
using var filesDbContext = _dbContextFactory.CreateDbContext();
var parentFolders = await filesDbContext.Tree
.Join(filesDbContext.Folders, r => r.ParentId, s => s.Id, (t, f) => new { Tree = t, Folders = f })
@ -1547,7 +1535,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
.Select(r => new { r.Tree.ParentId, r.Folders.Title})
.ToListAsync();
if(parentFolders.Count() > 1)
if (parentFolders.Count > 1)
{
return (parentFolders[1].ParentId, parentFolders[1].Title);
}

View File

@ -120,13 +120,20 @@ public class FilesMessageService
SendHeadersMessage(headers, action, _messageTarget.Create(entry.Id), description);
}
public void Send<T1, T2>(FileEntry<T1> entry1, FileEntry<T2> entry2, IDictionary<string, StringValues> headers, MessageAction action, params string[] description)
public async Task Send<T1, T2>(FileEntry<T1> entry1, FileEntry<T2> entry2, IDictionary<string, StringValues> headers, MessageAction action, params string[] description)
{
if (entry1 == null || entry2 == null)
{
return;
}
var additionalParams = await GetAdditionalNotificationParamAsync(entry1, action);
if (!string.IsNullOrEmpty(additionalParams))
{
description = description.Append(additionalParams).ToArray();
}
SendHeadersMessage(headers, action, _messageTarget.CreateFromGroupValues(new[] { entry1.Id.ToString(), entry2.Id.ToString() }), description);
}
@ -203,12 +210,6 @@ public class FilesMessageService
private async Task<string> GetAdditionalNotificationParamAsync<T>(FileEntry<T> entry, MessageAction action, string oldTitle = null, Guid userid = default(Guid), FileShare userRole = FileShare.None)
{
if (!StudioWhatsNewNotify.DailyActions.Contains(action)
&& !StudioWhatsNewNotify.RoomsActivityActions.Contains(action))
{
return "";
}
var folderDao = _daoFactory.GetFolderDao<int>();
var roomInfo = await folderDao.GetParentRoomInfoFromFileEntryAsync(entry);
@ -242,4 +243,4 @@ public class FilesMessageService
return serializedParam;
}
}
}

View File

@ -319,7 +319,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
else
{
newFolder = await FolderDao.CopyFolderAsync(folder.Id, toFolderId, CancellationToken);
filesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopied, newFolder.Title, toFolder.Title);
_ = filesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopied, newFolder.Title, toFolder.Title);
if (isToFolder)
{
@ -366,7 +366,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
{
newFolder = await FolderDao.CopyFolderAsync(folder.Id, toFolderId, CancellationToken);
newFolderId = newFolder.Id;
filesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopiedWithOverwriting, newFolder.Title, toFolder.Title);
_ = filesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopiedWithOverwriting, newFolder.Title, toFolder.Title);
if (isToFolder)
{
@ -392,7 +392,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
newFolderId = await FolderDao.MoveFolderAsync(folder.Id, toFolderId, CancellationToken);
newFolder = await folderDao.GetFolderAsync(newFolderId);
filesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title);
_ = filesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title);
if (isToFolder)
{
@ -477,7 +477,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
}
else
{
filesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedFrom, folder.Title, parentFolder.Title, toFolder.Title);
_ = filesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMoved, folder.Title, parentFolder.Title, toFolder.Title);
}
@ -586,7 +586,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
try
{
newFile = await FileDao.CopyFileAsync(file.Id, toFolderId); //Stream copy will occur inside dao
filesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopied, newFile.Title, parentFolder.Title, toFolder.Title);
_ = filesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopied, newFile.Title, parentFolder.Title, toFolder.Title);
if (Equals(newFile.ParentId.ToString(), _daoFolderId))
{
@ -623,7 +623,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
var newFileId = await FileDao.MoveFileAsync(file.Id, toFolderId);
newFile = await fileDao.GetFileAsync(newFileId);
filesMessageService.Send(file, toFolder, _headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title);
_ = filesMessageService.Send(file, toFolder, _headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title);
if (file.RootFolderType == FolderType.TRASH && newFile.ThumbnailStatus == Thumbnail.NotRequired)
{
@ -711,7 +711,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
if (copy)
{
filesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopiedWithOverwriting, newFile.Title, parentFolder.Title, toFolder.Title);
_ = filesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopiedWithOverwriting, newFile.Title, parentFolder.Title, toFolder.Title);
if (ProcessedFile(fileId))
{
sb.Append($"file_{newFile.Id}{SplitChar}");
@ -738,7 +738,7 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
await LinkDao.DeleteAllLinkAsync(file.Id.ToString());
filesMessageService.Send(file, toFolder, _headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);
_ = filesMessageService.Send(file, toFolder, _headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title);
await socketManager.DeleteFile(file);