From 597baeb510b6861a8826ef1aa8264c157f4b7666 Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Fri, 15 Apr 2022 17:23:31 +0300 Subject: [PATCH] Files: added archive folder --- .../Core/Core/Security/FileSecurity.cs | 68 ++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/products/ASC.Files/Core/Core/Security/FileSecurity.cs b/products/ASC.Files/Core/Core/Security/FileSecurity.cs index 5f764ad120..f08bdc2943 100644 --- a/products/ASC.Files/Core/Core/Security/FileSecurity.cs +++ b/products/ASC.Files/Core/Core/Security/FileSecurity.cs @@ -134,11 +134,6 @@ public class FileSecurity : IFileSecurity { return CanAsync(entry, userId, FilesSecurityActions.RoomEdit); } - - public Task CanRenameAsync(FileEntry entry, Guid userId) - { - return CanAsync(entry, userId, FilesSecurityActions.Rename); - } public Task CanReadAsync(FileEntry entry) { @@ -184,11 +179,6 @@ public class FileSecurity : IFileSecurity { return CanEditRoomAsync(entry, _authContext.CurrentAccount.ID); } - - public Task CanRenameAsync(FileEntry entry) - { - return CanRenameAsync(entry, _authContext.CurrentAccount.ID); - } public Task> WhoCanReadAsync(FileEntry entry) { @@ -399,7 +389,8 @@ public class FileSecurity : IFileSecurity f.RootFolderType == FolderType.Templates || f.RootFolderType == FolderType.Privacy || f.RootFolderType == FolderType.Projects || - f.RootFolderType == FolderType.VirtualRooms; + f.RootFolderType == FolderType.VirtualRooms || + f.RootFolderType == FolderType.Archive; var isVisitor = user.IsVisitor(_userManager); @@ -479,6 +470,11 @@ public class FileSecurity : IFileSecurity // Templates folder read-only continue; } + + if (folder.FolderType == FolderType.Archive) + { + continue; + } } if (isVisitor && e.ProviderEntry) @@ -569,6 +565,12 @@ public class FileSecurity : IFileSecurity result.Add(e); continue; } + + if (action == FilesSecurityActions.Delete && e.RootFolderType == FolderType.Archive && _fileSecurityCommon.IsAdministrator(userId)) + { + result.Add(e); + continue; + } if (subjects == null) { @@ -651,10 +653,6 @@ public class FileSecurity : IFileSecurity { result.Add(e); } - else if (action == FilesSecurityActions.Rename && (e.Access == FileShare.ReadWrite || e.Access == FileShare.RoomManager)) - { - result.Add(e); - } else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || folder.FolderType != FolderType.COMMON)) { result.Add(e); @@ -970,6 +968,45 @@ public class FileSecurity : IFileSecurity return entries; } + public async Task> GetArchiveForMeAsync() + { + var securityDao = _daoFactory.GetSecurityDao(); + var subjects = GetUserSubjects(_authContext.CurrentAccount.ID); + var records = await securityDao.GetSharesAsync(subjects); + + var result = new List(); + result.AddRange(await GetArchiveForMeAsync(records, subjects)); + + return result; + } + + private async Task> GetArchiveForMeAsync(IEnumerable records, List subjects) +{ + var folderDao = _daoFactory.GetFolderDao(); + var folderIds = new Dictionary(); + + var recordGroup = records.GroupBy(r => new { r.EntryId, r.EntryType }, (key, group) => new + { + firstRecord = group.OrderBy(r => r, new SubjectComparer(subjects)) + .ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer()) + .First() + }); + + foreach (var record in recordGroup.Where(r => r.firstRecord.Share == FileShare.RoomManager)) + { + if (!folderIds.ContainsKey((T)record.firstRecord.EntryId)) + { + folderIds.Add((T)record.firstRecord.EntryId, record.firstRecord.Share); + } + } + + var entries = new List(); + + entries.AddRange(await folderDao.GetFoldersAsync(folderIds.Keys).Where(f => f.RootFolderType == FolderType.Archive).ToListAsync()); + + return entries; + } + public async Task> GetPrivacyForMeAsync(FilterType filterType, bool subjectGroup, Guid subjectID, string searchText = "", bool searchInContent = false, bool withSubfolders = false) { var securityDao = _daoFactory.GetSecurityDao(); @@ -1141,6 +1178,5 @@ public class FileSecurity : IFileSecurity Delete, CustomFilter, RoomEdit, - Rename } }