diff --git a/products/ASC.Files/Core/Core/FileStorageService.cs b/products/ASC.Files/Core/Core/FileStorageService.cs index 44050a975a..d088c5af8f 100644 --- a/products/ASC.Files/Core/Core/FileStorageService.cs +++ b/products/ASC.Files/Core/Core/FileStorageService.cs @@ -2044,7 +2044,7 @@ public class FileStorageService //: IFileStorageService { try { - var changed = await _fileSharingAceHelper.SetAceObjectAsync(aceCollection.Aces, entry, notify, aceCollection.Message); + var changed = await _fileSharingAceHelper.SetAceObjectAsync(aceCollection.Aces, entry, notify, aceCollection.Message, _coreBaseSettings.DocSpace); if (changed) { _filesMessageService.Send(entry, GetHttpHeaders(), diff --git a/products/ASC.Files/Core/Utils/FileSharing.cs b/products/ASC.Files/Core/Utils/FileSharing.cs index 1c2306c70d..aa91c4d4e6 100644 --- a/products/ASC.Files/Core/Utils/FileSharing.cs +++ b/products/ASC.Files/Core/Utils/FileSharing.cs @@ -24,6 +24,8 @@ // 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 +using ASC.Files.Core.Helpers; + namespace ASC.Web.Files.Utils; [Scope] @@ -40,6 +42,7 @@ public class FileSharingAceHelper private readonly GlobalFolderHelper _globalFolderHelper; private readonly FileSharingHelper _fileSharingHelper; private readonly FileTrackerHelper _fileTracker; + private readonly FileSecurityCommon _fileSecurityCommon; public FileSharingAceHelper( FileSecurity fileSecurity, @@ -52,7 +55,8 @@ public class FileSharingAceHelper NotifyClient notifyClient, GlobalFolderHelper globalFolderHelper, FileSharingHelper fileSharingHelper, - FileTrackerHelper fileTracker) + FileTrackerHelper fileTracker, + FileSecurityCommon fileSecurityCommon) { _fileSecurity = fileSecurity; _coreBaseSettings = coreBaseSettings; @@ -65,9 +69,10 @@ public class FileSharingAceHelper _globalFolderHelper = globalFolderHelper; _fileSharingHelper = fileSharingHelper; _fileTracker = fileTracker; + _fileSecurityCommon = fileSecurityCommon; } - public async Task SetAceObjectAsync(List aceWrappers, FileEntry entry, bool notify, string message) + public async Task SetAceObjectAsync(List aceWrappers, FileEntry entry, bool notify, string message, bool handleForRooms = false) { if (entry == null) { @@ -85,6 +90,8 @@ public class FileSharingAceHelper var recipients = new Dictionary(); var usersWithoutRight = new List(); var changed = false; + + aceWrappers = handleForRooms ? FilterAndProcessForRooms(entry, aceWrappers) : aceWrappers; foreach (var w in aceWrappers.OrderByDescending(ace => ace.SubjectGroup)) { @@ -220,6 +227,60 @@ public class FileSharingAceHelper await _fileMarker.RemoveMarkAsNewAsync(entry); }); } + + private List FilterAndProcessForRooms(FileEntry entry, List aceWrappers) + { + if (entry.FileEntryType == FileEntryType.File) + { + return aceWrappers; + } + + var folderType = ((IFolder)entry).FolderType; + + if (folderType != FolderType.FillingFormsRoom && folderType != FolderType.EditingRoom + && folderType != FolderType.ReadOnlyRoom && folderType != FolderType.ReviewRoom + && folderType != FolderType.CustomRoom) + { + return aceWrappers; + } + + var result = new List(aceWrappers.Count); + + var isAdmin = _fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID); + var isRoomManager = !isAdmin ? false : true; + + foreach (var ace in aceWrappers) + { + if (ace.SubjectGroup) + { + continue; + } + + if (!RoomTemplateValidator.Validate(ace.Share, folderType)) + { + continue; + } + + if (ace.Share == FileShare.RoomManager && isAdmin) + { + result.Add(ace); + continue; + } + + if ((ace.Share == FileShare.None || ace.Share == FileShare.Restrict ) && isAdmin) + { + result.Add(ace); + continue; + } + + if (ace.Share != FileShare.RoomManager && isRoomManager) + { + result.Add(ace); + } + } + + return result; + } } [Scope]