diff --git a/products/ASC.Files/Core/Core/Security/FileSecurity.cs b/products/ASC.Files/Core/Core/Security/FileSecurity.cs index 9551f14f93..83fad58c4c 100644 --- a/products/ASC.Files/Core/Core/Security/FileSecurity.cs +++ b/products/ASC.Files/Core/Core/Security/FileSecurity.cs @@ -899,6 +899,48 @@ public class FileSecurity : IFileSecurity return entries.Where(x => string.IsNullOrEmpty(x.Error)).Cast().ToList(); } + public async Task> GetVirtualRoomsForMeAsync() + { + var securityDao = _daoFactory.GetSecurityDao(); + var subjects = GetUserSubjects(_authContext.CurrentAccount.ID); + var records = await securityDao.GetSharesAsync(subjects); + + var result = new List(); + result.AddRange(await GetVirtualRoomsForMeAsync(records.Where(r => r.EntryId.GetType() == typeof(int)), subjects)); + result.AddRange(await GetVirtualRoomsForMeAsync(records.Where(r => r.EntryId.GetType() == typeof(string)), subjects)); + + return result; + } + + private async Task> GetVirtualRoomsForMeAsync(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) + { + if (!folderIds.ContainsKey((T)record.firstRecord.EntryId)) + { + folderIds.Add((T)record.firstRecord.EntryId, record.firstRecord.Share); + } + } + + var entries = new List(); + + var folders = await folderDao.GetFoldersAsync(folderIds.Keys).Where(f => f.RootFolderType == FolderType.VirtualRooms).ToListAsync(); + + entries.AddRange(folders); + + return entries; + } + public async Task> GetPrivacyForMeAsync(FilterType filterType, bool subjectGroup, Guid subjectID, string searchText = "", bool searchInContent = false, bool withSubfolders = false) { var securityDao = _daoFactory.GetSecurityDao(); diff --git a/products/ASC.Files/Core/Utils/EntryManager.cs b/products/ASC.Files/Core/Utils/EntryManager.cs index f2b5e848dc..5ed9a4149b 100644 --- a/products/ASC.Files/Core/Utils/EntryManager.cs +++ b/products/ASC.Files/Core/Utils/EntryManager.cs @@ -252,7 +252,7 @@ public class EntryManager { private const string UpdateList = "filesUpdateList"; - private ICache _cache; + private readonly ICache _cache; private readonly FileTrackerHelper _fileTracker; private readonly EntryStatusManager _entryStatusManager; private readonly IDaoFactory _daoFactory; @@ -278,6 +278,7 @@ public class EntryManager private readonly IServiceProvider _serviceProvider; private readonly ILog _logger; private readonly IHttpClientFactory _clientFactory; + private readonly Global _global; public EntryManager( IDaoFactory daoFactory, @@ -305,7 +306,8 @@ public class EntryManager ICache cache, FileTrackerHelper fileTracker, EntryStatusManager entryStatusManager, - IHttpClientFactory clientFactory) + IHttpClientFactory clientFactory, + Global global) { _daoFactory = daoFactory; _fileSecurity = fileSecurity; @@ -333,6 +335,7 @@ public class EntryManager _fileTracker = fileTracker; _entryStatusManager = entryStatusManager; _clientFactory = clientFactory; + _global = global; } public async Task<(IEnumerable Entries, int Total)> GetEntriesAsync(Folder parent, int from, int count, FilterType filter, bool subjectGroup, Guid subjectId, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy) @@ -510,6 +513,22 @@ public class EntryManager CalculateTotal(); } + else if (parent.FolderType == FolderType.VirtualRooms) + { + if (_global.IsAdministrator) + { + var folderDao = _daoFactory.GetFolderDao(); + var folders = await folderDao.GetFoldersAsync(parent.Id, orderBy, filter, subjectGroup, subjectId, searchText, withSubfolders).ToListAsync(); + + entries = entries.Concat(folders); + } + else + { + entries = await fileSecurity.GetVirtualRoomsForMeAsync(); + } + + CalculateTotal(); + } else { if (parent.FolderType == FolderType.TRASH)