From 70173016ead050f76a4f5a520ed532349f28cb3c Mon Sep 17 00:00:00 2001 From: Maksim Chegulov Date: Wed, 13 Mar 2024 13:51:56 +0300 Subject: [PATCH] fix Bug 66865 - In the Access rights tab of the editor, return the name of links and the corresponding icon --- .../ApiModels/ResponseDto/ConfigurationDto.cs | 2 +- .../ASC.Files/Core/Core/FileStorageService.cs | 2 +- .../ASC.Files/Core/Core/Security/FileShare.cs | 2 +- .../Services/DocumentService/Configuration.cs | 2 +- .../WCFService/Wrappers/AceWrapper.cs | 27 ++---- products/ASC.Files/Core/Utils/FileSharing.cs | 88 +++++-------------- 6 files changed, 32 insertions(+), 91 deletions(-) diff --git a/products/ASC.Files/Core/ApiModels/ResponseDto/ConfigurationDto.cs b/products/ASC.Files/Core/ApiModels/ResponseDto/ConfigurationDto.cs index f0a4d0df7d1..e0bc0f0a1c5 100644 --- a/products/ASC.Files/Core/ApiModels/ResponseDto/ConfigurationDto.cs +++ b/products/ASC.Files/Core/ApiModels/ResponseDto/ConfigurationDto.cs @@ -371,7 +371,7 @@ public async Task Convert(InfoConfig source, File file) SharingSettings = await source.GetSharingSettings(file), Type = source.Type, Uploaded = source.GetUploaded(file) - }; + }; return result; } diff --git a/products/ASC.Files/Core/Core/FileStorageService.cs b/products/ASC.Files/Core/Core/FileStorageService.cs index 30195c75583..d1c937c45ad 100644 --- a/products/ASC.Files/Core/Core/FileStorageService.cs +++ b/products/ASC.Files/Core/Core/FileStorageService.cs @@ -2943,7 +2943,7 @@ public async Task> SendEditorNotifyAsync(T fileId, Ment _logger.ErrorWithException(ex); } - return showSharingSettings ? await fileSharing.GetSharedInfoShortFileAsync(fileId) : null; + return showSharingSettings ? await fileSharing.GetSharedInfoShortFileAsync(file) : null; } public async Task> GetEncryptionAccessAsync(T fileId) diff --git a/products/ASC.Files/Core/Core/Security/FileShare.cs b/products/ASC.Files/Core/Core/Security/FileShare.cs index c3fee606f24..5bb7a8b1f83 100644 --- a/products/ASC.Files/Core/Core/Security/FileShare.cs +++ b/products/ASC.Files/Core/Core/Security/FileShare.cs @@ -73,7 +73,7 @@ public static partial class FileShareExtensions { public static string GetAccessString(FileShare fileShare, bool useRoomFormat = false, CultureInfo cultureInfo = null) { - var prefix = useRoomFormat ? "RoleEnum_" : "AceStatusEnum_"; + var prefix = useRoomFormat && fileShare != FileShare.ReadWrite ? "RoleEnum_" : "AceStatusEnum_"; switch (fileShare) { diff --git a/products/ASC.Files/Core/Services/DocumentService/Configuration.cs b/products/ASC.Files/Core/Services/DocumentService/Configuration.cs index 4934fccb4b7..b1f0fcc0866 100644 --- a/products/ASC.Files/Core/Services/DocumentService/Configuration.cs +++ b/products/ASC.Files/Core/Services/DocumentService/Configuration.cs @@ -453,7 +453,7 @@ public async Task> GetSharingSettings(File file) try { - return await fileSharing.GetSharedInfoShortFileAsync(file.Id); + return await fileSharing.GetSharedInfoShortFileAsync(file); } catch { diff --git a/products/ASC.Files/Core/Services/WCFService/Wrappers/AceWrapper.cs b/products/ASC.Files/Core/Services/WCFService/Wrappers/AceWrapper.cs index d21c08da914..00b3a5769f1 100644 --- a/products/ASC.Files/Core/Services/WCFService/Wrappers/AceWrapper.cs +++ b/products/ASC.Files/Core/Services/WCFService/Wrappers/AceWrapper.cs @@ -69,34 +69,19 @@ public class AceWrapper : IMapFrom /// /// -public class AceShortWrapper +public class AceShortWrapper(string subjectName, string permission, bool isLink) { /// User /// System.String, System - public string User { get; set; } + public string User { get; init; } = subjectName; /// User access rights to the file /// System.String, System - public string Permissions { get; set; } + public string Permissions { get; init; } = permission; - public AceShortWrapper(AceWrapper aceWrapper) - { - var permission = aceWrapper.Access switch - { - FileShare.Read => FilesCommonResource.AceStatusEnum_Read, - FileShare.ReadWrite => FilesCommonResource.AceStatusEnum_ReadWrite, - FileShare.CustomFilter => FilesCommonResource.AceStatusEnum_CustomFilter, - FileShare.Review => FilesCommonResource.AceStatusEnum_Review, - FileShare.FillForms => FilesCommonResource.AceStatusEnum_FillForms, - FileShare.Comment => FilesCommonResource.AceStatusEnum_Comment, - FileShare.Restrict => FilesCommonResource.AceStatusEnum_Restrict, - _ => string.Empty - }; - - User = aceWrapper.SubjectName; - - Permissions = permission; - } + /// Is link + /// System.Boolean, System + public bool isLink { get; init; } = isLink; } public class AceAdvancedSettingsWrapper diff --git a/products/ASC.Files/Core/Utils/FileSharing.cs b/products/ASC.Files/Core/Utils/FileSharing.cs index 7d46a28c17b..b61aa345050 100644 --- a/products/ASC.Files/Core/Utils/FileSharing.cs +++ b/products/ASC.Files/Core/Utils/FileSharing.cs @@ -575,12 +575,10 @@ public async Task> GetSharedInfoAsync(FileEntry entry, IE logger.ErrorUserCanTGetSharedInfo(authContext.CurrentAccount.ID, entry.FileEntryType, entry.Id.ToString()); return []; - //throw new SecurityException(FilesCommonResource.ErrorMessage_SecurityException); } var result = new List(); var shares = await fileSecurity.GetSharesAsync(entry); - var isRoom = entry is Folder { SettingsPrivate: false } room && DocSpaceHelper.IsRoom(room.FolderType); var canEditAccess = await fileSecurity.CanEditAccessAsync(entry); var canReadLinks = await fileSecurity.CanReadLinksAsync(entry); @@ -592,6 +590,11 @@ public async Task> GetSharedInfoAsync(FileEntry entry, IE foreach (var r in records) { + if (r == null) + { + continue; + } + if (r.IsLink && !canReadLinks) { continue; @@ -607,66 +610,15 @@ public async Task> GetSharedInfoAsync(FileEntry entry, IE continue; } - var u = await userManager.GetUsersAsync(r.Subject); - var isgroup = false; - var title = u.DisplayUserName(false, displayUserSettingsHelper); - var share = r.Share; - - if (u.Id == Constants.LostUser.Id && !r.IsLink) - { - var g = await userManager.GetGroupInfoAsync(r.Subject); - isgroup = true; - title = g.Name; - - if (g.ID == Constants.GroupAdmin.ID) - { - title = FilesCommonResource.Admin; - } - - if (g.ID == Constants.GroupEveryone.ID) - { - title = FilesCommonResource.Everyone; - } - - if (g.ID == Constants.LostGroupInfo.ID) - { - await fileSecurity.RemoveSubjectAsync(r.Subject, true); - - continue; - } - } - - var w = new AceWrapper { Id = r.Subject, SubjectGroup = isgroup, Access = share, FileShareOptions = r.Options }; - - w.CanEditAccess = authContext.CurrentAccount.ID != w.Id && w.SubjectType is SubjectType.User or SubjectType.Group && canEditAccess; - - if (isRoom && r.IsLink) - { - if (!canEditAccess) - { - continue; - } - - var link = r.SubjectType == SubjectType.InvitationLink - ? invitationLinkService.GetInvitationLink(r.Subject, authContext.CurrentAccount.ID) - : (await externalShare.GetLinkDataAsync(entry, r.Subject)).Url; - - w.Link = await urlShortener.GetShortenLinkAsync(link); - w.SubjectGroup = true; - w.CanEditAccess = false; - w.FileShareOptions.Password = await externalShare.GetPasswordAsync(w.FileShareOptions.Password); - w.SubjectType = r.SubjectType; - } - else + var ace = await ToAceAsync(entry, r, canEditAccess); + + if (ace.SubjectType == SubjectType.Group && ace.Id == Constants.LostGroupInfo.ID) { - w.SubjectName = title; - w.Owner = entry.RootFolderType == FolderType.USER - ? entry.RootCreateBy == r.Subject - : entry.CreateBy == r.Subject; - w.LockedRights = r.Subject == authContext.CurrentAccount.ID; + await fileSecurity.RemoveSubjectAsync(r.Subject, true); + continue; } - result.Add(w); + result.Add(ace); } if (!result.Exists(w => w.Owner) && (subjectsTypes == null || subjectsTypes.Contains(SubjectType.User) || subjectsTypes.Contains(SubjectType.Group))) @@ -834,15 +786,16 @@ public async Task> GetSharedInfoAsync(IEnumerable fileIds return [..result]; } - public async Task> GetSharedInfoShortFileAsync(T fileID) + public async Task> GetSharedInfoShortFileAsync(File file) { - var aces = await GetSharedInfoAsync(new List { fileID }, new List()); - + var aces = await GetSharedInfoAsync(new List { file.Id }, new List()); + var inRoom = file.RootFolderType is FolderType.VirtualRooms or FolderType.Archive; + return [ ..aces - .Where(aceWrapper => aceWrapper.Access != FileShare.Restrict) - .Select(aceWrapper => new AceShortWrapper(aceWrapper)) + .Where(aceWrapper => aceWrapper.Access != FileShare.Restrict && aceWrapper.SubjectType != SubjectType.InvitationLink) + .Select(aceWrapper => new AceShortWrapper(aceWrapper.SubjectName, FileShareExtensions.GetAccessString(aceWrapper.Access, inRoom), aceWrapper.IsLink)) ]; } @@ -959,7 +912,9 @@ private async Task ToAceAsync(FileEntry entry, FileShareRecord { var group = await userManager.GetGroupInfoAsync(record.Subject); w.SubjectGroup = true; - w.SubjectName = group.ID == Constants.GroupEveryone.ID ? FilesCommonResource.Everyone : group.Name; + + w.SubjectName = group.ID == Constants.GroupEveryone.ID ? FilesCommonResource.Everyone : + group.ID == Constants.GroupAdmin.ID ? FilesCommonResource.Admin : group.Name; } else { @@ -987,7 +942,8 @@ private async Task ToAceAsync(FileEntry entry, FileShareRecord link = linkData.Url; w.RequestToken = linkData.Token; } - + + w.SubjectName = record.Options.Title; w.Link = await urlShortener.GetShortenLinkAsync(link); w.SubjectGroup = true; w.CanEditAccess = false;