From afb7ec9264c2b327413d05734821039291cc5962 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Mon, 18 Sep 2023 20:20:34 +0300 Subject: [PATCH] Files: added property InRoom for docspace owner --- .../ApiModels/ResponseDto/FolderContentDto.cs | 41 +++++++++++++++++-- .../Core/ApiModels/ResponseDto/FolderDto.cs | 2 + .../ASC.Files/Core/Core/FileStorageService.cs | 24 ++++------- products/ASC.Files/Core/Utils/FileSharing.cs | 12 ------ 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/products/ASC.Files/Core/ApiModels/ResponseDto/FolderContentDto.cs b/products/ASC.Files/Core/ApiModels/ResponseDto/FolderContentDto.cs index 7490fe64d7..b811eab915 100644 --- a/products/ASC.Files/Core/ApiModels/ResponseDto/FolderContentDto.cs +++ b/products/ASC.Files/Core/ApiModels/ResponseDto/FolderContentDto.cs @@ -24,7 +24,6 @@ // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - namespace ASC.Files.Core.ApiModels.ResponseDto; /// @@ -89,6 +88,8 @@ public class FolderContentDto public class FolderContentDtoHelper { private readonly FileSecurity _fileSecurity; + private readonly FileSecurityCommon _fileSecurityCommon; + private readonly AuthContext _authContext; private readonly IDaoFactory _daoFactory; private readonly FileDtoHelper _fileDtoHelper; private readonly FolderDtoHelper _folderDtoHelper; @@ -99,13 +100,17 @@ public class FolderContentDtoHelper IDaoFactory daoFactory, FileDtoHelper fileWrapperHelper, FolderDtoHelper folderWrapperHelper, - BadgesSettingsHelper badgesSettingsHelper) + BadgesSettingsHelper badgesSettingsHelper, + FileSecurityCommon fileSecurityCommon, + AuthContext authContext) { _fileSecurity = fileSecurity; _daoFactory = daoFactory; _fileDtoHelper = fileWrapperHelper; _folderDtoHelper = folderWrapperHelper; _badgesSettingsHelper = badgesSettingsHelper; + _fileSecurityCommon = fileSecurityCommon; + _authContext = authContext; } public async Task> GetAsync(DataWrapper folderItems, int startIndex) @@ -201,17 +206,45 @@ public class FolderContentDtoHelper async IAsyncEnumerable GetFoldersDto(IEnumerable folderEntries) { + List currentUsersRecords = null; + foreach (var r in folderEntries) { if (r is Folder fol1) { - yield return await _folderDtoHelper.GetAsync(fol1, foldersIntWithRights); + yield return await GetFolder(fol1, foldersIntWithRights); } else if (r is Folder fol2) { - yield return await _folderDtoHelper.GetAsync(fol2, foldersStringWithRights); + yield return await GetFolder(fol2, foldersStringWithRights); } } + + async Task> GetFolder(Folder fol1, List, bool>> foldersWithRights) + { + var result = await _folderDtoHelper.GetAsync(fol1, foldersWithRights); + if (DocSpaceHelper.IsRoom(fol1.FolderType)) + { + if (fol1.CreateBy == _authContext.CurrentAccount.ID) + { + result.InRoom = true; + } + else + { + if (currentUsersRecords == null && await _fileSecurityCommon.IsDocSpaceAdministratorAsync(_authContext.CurrentAccount.ID)) + { + var securityDao = _daoFactory.GetSecurityDao(); + var currentUserSubjects = await _fileSecurity.GetUserSubjectsAsync(_authContext.CurrentAccount.ID); + currentUsersRecords = await securityDao.GetSharesAsync(currentUserSubjects).ToListAsync(); + } + if (currentUsersRecords != null) + { + result.InRoom = currentUsersRecords.Any(c => c.EntryId.Equals(fol1.Id)); + } + } + } + return result; + } } } } diff --git a/products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs b/products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs index 71952267fe..c6f2b703e7 100644 --- a/products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs +++ b/products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs @@ -78,6 +78,8 @@ public class FolderDto : FileEntryDto /// System.Boolean, System public bool Private { get; set; } + public bool? InRoom { get; set; } + protected internal override FileEntryType EntryType { get => FileEntryType.Folder; } public FolderDto() { } diff --git a/products/ASC.Files/Core/Core/FileStorageService.cs b/products/ASC.Files/Core/Core/FileStorageService.cs index 90921edf47..9ab78dc5fa 100644 --- a/products/ASC.Files/Core/Core/FileStorageService.cs +++ b/products/ASC.Files/Core/Core/FileStorageService.cs @@ -375,9 +375,10 @@ public class FileStorageService //: IFileStorageService } } - parent.Shareable = await shareableTask - || parent.FolderType == FolderType.SHARE - || parent.RootFolderType == FolderType.Privacy; + parent.Shareable = + parent.FolderType == FolderType.SHARE || + parent.RootFolderType == FolderType.Privacy || + await shareableTask; entries = entries.Where(x => { @@ -2407,22 +2408,15 @@ public class FileStorageService //: IFileStorageService #endregion - public async Task> GetSharedInfoAsync(IEnumerable fileIds, IEnumerable folderIds, IEnumerable subjectTypes = null, + public async Task> GetSharedInfoAsync( + IEnumerable fileIds, + IEnumerable folderIds, + IEnumerable subjectTypes = null, bool withoutTemplates = false) { return await _fileSharing.GetSharedInfoAsync(fileIds, folderIds, subjectTypes, withoutTemplates); } - public async Task> GetSharedInfoShortFileAsync(T fileId) - { - return await _fileSharing.GetSharedInfoShortFileAsync(fileId); - } - - public async Task> GetSharedInfoShortFolder(T folderId) - { - return await _fileSharing.GetSharedInfoShortFolderAsync(folderId); - } - public async Task SetAceObjectAsync(AceCollection aceCollection, bool notify) { var fileDao = GetFileDao(); @@ -2825,7 +2819,7 @@ public class FileStorageService //: IFileStorageService _logger.ErrorWithException(ex); } - return showSharingSettings ? await GetSharedInfoShortFileAsync(fileId) : null; + return showSharingSettings ? await _fileSharing.GetSharedInfoShortFileAsync(fileId) : null; } public async Task> GetEncryptionAccessAsync(T fileId) diff --git a/products/ASC.Files/Core/Utils/FileSharing.cs b/products/ASC.Files/Core/Utils/FileSharing.cs index d2ff00138d..d0d068ee2d 100644 --- a/products/ASC.Files/Core/Utils/FileSharing.cs +++ b/products/ASC.Files/Core/Utils/FileSharing.cs @@ -817,18 +817,6 @@ public class FileSharing { var aces = await GetSharedInfoAsync(new List { fileID }, new List()); - return GetAceShortWrappers(aces); - } - - public async Task> GetSharedInfoShortFolderAsync(T folderId) - { - var aces = await GetSharedInfoAsync(new List(), new List { folderId }); - - return GetAceShortWrappers(aces); - } - - private List GetAceShortWrappers(List aces) - { return new List(aces .Where(aceWrapper => !aceWrapper.Id.Equals(FileConstant.ShareLinkId) || aceWrapper.Access != FileShare.Restrict) .Select(aceWrapper => new AceShortWrapper(aceWrapper)));