From 7600d7e19b78d25a84b63373449ffed0632ca326 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Wed, 13 Nov 2024 15:37:20 +0300 Subject: [PATCH] Quota: add room filtering by quota for all user types --- .../ASC.Files/Core/Configuration/ProductEntryPoint.cs | 2 +- .../ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs | 2 +- products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs | 5 +++-- products/ASC.Files/Core/Core/Security/FileSecurity.cs | 9 +++++---- .../Core/Thirdparty/ProviderDao/ProviderFolderDao.cs | 4 ++-- .../Core/Thirdparty/SharePoint/SharePointFolderDao.cs | 2 +- .../Core/Core/Thirdparty/ThirdPartyFolderDao.cs | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs b/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs index f6ebd680ba4..d497ce335ef 100644 --- a/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs +++ b/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs @@ -294,7 +294,7 @@ private async Task> GetUserRoomsWithRoleAsync(Guid user var virtualRoomsFolderId = await _globalFolder.GetFolderVirtualRoomsAsync(_daoFactory); var archiveFolderId = await _globalFolder.GetFolderArchiveAsync(_daoFactory); - var rooms = await folderDao.GetRoomsAsync(new List { virtualRoomsFolderId, archiveFolderId }, null, null, Guid.Empty, null, false, false, false, ProviderFilter.None, SubjectFilter.Owner, null).ToListAsync(); + var rooms = await folderDao.GetRoomsAsync(new List { virtualRoomsFolderId, archiveFolderId }, null, null, Guid.Empty, null, false, false, false, ProviderFilter.None, SubjectFilter.Owner, null, null).ToListAsync(); foreach (var room in rooms) { diff --git a/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs b/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs index eb26fadd3cd..cc3c1521634 100644 --- a/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs @@ -60,7 +60,7 @@ IAsyncEnumerable> GetRoomsAsync(IEnumerable parentsIds, IEnumerable bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, QuotaFilter quotaFilter); IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, - bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null); + bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null, QuotaFilter quotaFilter = QuotaFilter.All); IAsyncEnumerable> GetProviderBasedRoomsAsync(SearchArea searchArea, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds); diff --git a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs index 9b0d6387829..d3e57c26c84 100644 --- a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs @@ -201,7 +201,8 @@ public async IAsyncEnumerable> GetRoomsAsync( ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, - IEnumerable parentsIds) + IEnumerable parentsIds, + QuotaFilter quotaFilter) { if (CheckInvalidFilters(filterTypes) || provider != ProviderFilter.None) { @@ -216,7 +217,7 @@ public async IAsyncEnumerable> GetRoomsAsync( await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync(); var q = await GetFolderQuery(filesDbContext, f => roomsIds.Contains(f.Id) || (f.CreateBy == _authContext.CurrentAccount.ID && parentsIds != null && parentsIds.Contains(f.ParentId))); - q = !withSubfolders ? BuildRoomsQuery(filesDbContext, q, filter, tags, subjectId, searchByTags, withoutTags, searchByTypes, false, excludeSubject, subjectFilter, subjectEntriesIds) + q = !withSubfolders ? BuildRoomsQuery(filesDbContext, q, filter, tags, subjectId, searchByTags, withoutTags, searchByTypes, false, excludeSubject, subjectFilter, subjectEntriesIds, quotaFilter) : await BuildRoomsWithSubfoldersQuery(filesDbContext, roomsIds, filter, tags, searchByTags, searchByTypes, withoutTags, excludeSubject, subjectId, subjectFilter, subjectEntriesIds); if (!string.IsNullOrEmpty(searchText)) diff --git a/products/ASC.Files/Core/Core/Security/FileSecurity.cs b/products/ASC.Files/Core/Core/Security/FileSecurity.cs index 2c2a1cc97d1..2815da38faf 100644 --- a/products/ASC.Files/Core/Core/Security/FileSecurity.cs +++ b/products/ASC.Files/Core/Core/Security/FileSecurity.cs @@ -1812,12 +1812,12 @@ public async Task> GetVirtualRoomsAsync( if (isAdmin) { - return await GetAllVirtualRoomsAsync(filterTypes, subjectId, searchText, searchInContent, withSubfolders, searchArea, withoutTags, tagNames, excludeSubject, provider, + return await GetAllVirtualRoomsAsync(filterTypes, subjectId, searchText, searchInContent, withSubfolders, searchArea, withoutTags, tagNames, excludeSubject, provider, subjectFilter, subjectEntries, quotaFilter, storageFilter, internalRoomsRecords, thirdPartyRoomsRecords); } - return await GetVirtualRoomsForMeAsync(filterTypes, subjectId, searchText, searchInContent, withSubfolders, searchArea, withoutTags, tagNames, excludeSubject, provider, - subjectFilter, subjectEntries, storageFilter, internalRoomsRecords, thirdPartyRoomsRecords); + return await GetVirtualRoomsForMeAsync(filterTypes, subjectId, searchText, searchInContent, withSubfolders, searchArea, withoutTags, tagNames, excludeSubject, provider, + subjectFilter, subjectEntries, quotaFilter, storageFilter, internalRoomsRecords, thirdPartyRoomsRecords); } private async Task> GetAllVirtualRoomsAsync( @@ -1930,6 +1930,7 @@ private async Task> GetVirtualRoomsForMeAsync( ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntries, + QuotaFilter quotaFilter, StorageFilter storageFilter, Dictionary> internalRecords, Dictionary> thirdPartyRecords) @@ -1950,7 +1951,7 @@ private async Task> GetVirtualRoomsForMeAsync( var rooms = storageFilter == StorageFilter.ThirdParty ? [] : await folderDao.GetRoomsAsync(internalRecords.Keys, filterTypes, tagNames, subjectId, search, withSubfolders, withoutTags, excludeSubject, provider, - subjectFilter, subjectEntries, rootFoldersIds).Where(r => Filter(r, internalRecords)).ToListAsync(); + subjectFilter, subjectEntries, rootFoldersIds, quotaFilter).Where(r => Filter(r, internalRecords)).ToListAsync(); var thirdPartyRooms = storageFilter == StorageFilter.Internal ? [] diff --git a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs index 476b2505fb4..a58398e8c2d 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs @@ -83,7 +83,7 @@ public async Task> GetRootFolderByFileAsync(string fileId) return await ResolveParentAsync(folder); } - public IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null) + public IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null, QuotaFilter quotaFilter = QuotaFilter.All) { var result = AsyncEnumerable.Empty>(); @@ -100,7 +100,7 @@ public IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsI var folderDao = selectorLocal.GetFolderDao(matchedId.FirstOrDefault()); return folderDao.GetRoomsAsync(matchedId.Select(selectorLocal.ConvertId).ToList(), filterTypes, tags, subjectId, searchText, withSubfolders, withoutTags, - excludeSubject, provider, subjectFilter, subjectEntriesIds); + excludeSubject, provider, subjectFilter, subjectEntriesIds, quotaFilter); }) .Where(r => r != null)) .SelectAwait(async r => await ResolveParentAsync(r)); diff --git a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs index 92d8362c26f..09fc45ad707 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs @@ -80,7 +80,7 @@ public Task> GetRootFolderByFileAsync(string fileId) return Task.FromResult(SharePointProviderInfo.ToFolder(SharePointProviderInfo.RootFolder)); } - public async IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null) + public async IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, bool withoutTags, bool excludeSubject, ProviderFilter provider, SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null, QuotaFilter quotaFilter = QuotaFilter.All) { if (CheckInvalidFilters(filterTypes) || (provider != ProviderFilter.None && provider != SharePointProviderInfo.ProviderFilter)) { diff --git a/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs index b3d246c230a..27e58781f71 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs @@ -98,7 +98,7 @@ public Task> GetRootFolderByFileAsync(string fileId) } public async IAsyncEnumerable> GetRoomsAsync(IEnumerable roomsIds, IEnumerable filterTypes, IEnumerable tags, Guid subjectId, string searchText, bool withSubfolders, bool withoutTags, bool excludeSubject, ProviderFilter provider, - SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null) + SubjectFilter subjectFilter, IEnumerable subjectEntriesIds, IEnumerable parentsIds = null, QuotaFilter quotaFilter = QuotaFilter.All) { if (dao.CheckInvalidFilters(filterTypes) || (provider != ProviderFilter.None && provider != _providerInfo.ProviderFilter)) {