Skip to content

Commit

Permalink
fix Bug 66865 - In the Access rights tab of the editor, return the na…
Browse files Browse the repository at this point in the history
…me of links and the corresponding icon
  • Loading branch information
MaksimChegulov committed Mar 13, 2024
1 parent 3bb1577 commit 7017301
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public async Task<InfoConfigDto> Convert(InfoConfig<T> source, File<T> file)
SharingSettings = await source.GetSharingSettings(file),
Type = source.Type,
Uploaded = source.GetUploaded(file)
};
};

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion products/ASC.Files/Core/Core/FileStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2943,7 +2943,7 @@ public async Task<List<AceShortWrapper>> SendEditorNotifyAsync<T>(T fileId, Ment
_logger.ErrorWithException(ex);
}

return showSharingSettings ? await fileSharing.GetSharedInfoShortFileAsync(fileId) : null;
return showSharingSettings ? await fileSharing.GetSharedInfoShortFileAsync(file) : null;
}

public async Task<List<EncryptionKeyPairDto>> GetEncryptionAccessAsync<T>(T fileId)
Expand Down
2 changes: 1 addition & 1 deletion products/ASC.Files/Core/Core/Security/FileShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public async Task<List<AceShortWrapper>> GetSharingSettings(File<T> file)

try
{
return await fileSharing.GetSharedInfoShortFileAsync(file.Id);
return await fileSharing.GetSharedInfoShortFileAsync(file);
}
catch
{
Expand Down
27 changes: 6 additions & 21 deletions products/ASC.Files/Core/Services/WCFService/Wrappers/AceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,19 @@ public class AceWrapper : IMapFrom<RoomInvitation>

/// <summary>
/// </summary>
public class AceShortWrapper
public class AceShortWrapper(string subjectName, string permission, bool isLink)
{
/// <summary>User</summary>
/// <type>System.String, System</type>
public string User { get; set; }
public string User { get; init; } = subjectName;

/// <summary>User access rights to the file</summary>
/// <type>System.String, System</type>
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;
}
/// <summary>Is link</summary>
/// <type>System.Boolean, System</type>
public bool isLink { get; init; } = isLink;
}

public class AceAdvancedSettingsWrapper
Expand Down
88 changes: 22 additions & 66 deletions products/ASC.Files/Core/Utils/FileSharing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,10 @@ public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(FileEntry<T> entry, IE
logger.ErrorUserCanTGetSharedInfo(authContext.CurrentAccount.ID, entry.FileEntryType, entry.Id.ToString());

return [];
//throw new SecurityException(FilesCommonResource.ErrorMessage_SecurityException);
}

var result = new List<AceWrapper>();
var shares = await fileSecurity.GetSharesAsync(entry);
var isRoom = entry is Folder<T> { SettingsPrivate: false } room && DocSpaceHelper.IsRoom(room.FolderType);
var canEditAccess = await fileSecurity.CanEditAccessAsync(entry);
var canReadLinks = await fileSecurity.CanReadLinksAsync(entry);

Expand All @@ -592,6 +590,11 @@ public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(FileEntry<T> entry, IE

foreach (var r in records)
{
if (r == null)
{
continue;
}

if (r.IsLink && !canReadLinks)
{
continue;
Expand All @@ -607,66 +610,15 @@ public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(FileEntry<T> 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<T>(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<T>(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)))
Expand Down Expand Up @@ -834,15 +786,16 @@ public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(IEnumerable<T> fileIds
return [..result];
}

public async Task<List<AceShortWrapper>> GetSharedInfoShortFileAsync<T>(T fileID)
public async Task<List<AceShortWrapper>> GetSharedInfoShortFileAsync<T>(File<T> file)
{
var aces = await GetSharedInfoAsync(new List<T> { fileID }, new List<T>());

var aces = await GetSharedInfoAsync(new List<T> { file.Id }, new List<T>());
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))
];
}

Expand Down Expand Up @@ -959,7 +912,9 @@ private async Task<AceWrapper> ToAceAsync<T>(FileEntry<T> 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
{
Expand Down Expand Up @@ -987,7 +942,8 @@ private async Task<AceWrapper> ToAceAsync<T>(FileEntry<T> 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;
Expand Down

0 comments on commit 7017301

Please sign in to comment.