Skip to content

Commit

Permalink
Merge pull request #262 from ONLYOFFICE/feature/remove-old-sharelinkid
Browse files Browse the repository at this point in the history
Remove old shared link functionality from Files module
  • Loading branch information
pavelbannov authored Mar 1, 2024
2 parents 08926a6 + 6acd35b commit 2dd6fd9
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 290 deletions.

This file was deleted.

4 changes: 1 addition & 3 deletions products/ASC.Files/Core/Core/Entries/EncryptionKeyPairDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ public async Task<IEnumerable<EncryptionKeyPairDto>> GetKeyPairAsync<T>(T fileId

var tmpFiles = await FileStorageService.GetSharedInfoAsync(new List<T> { fileId }, new List<T>());
var fileShares = tmpFiles.ToList();
fileShares = fileShares.Where(share => !share.SubjectGroup
&& !share.Id.Equals(FileConstant.ShareLinkId)
&& share.Access == FileShare.ReadWrite).ToList();
fileShares = fileShares.Where(share => !share.SubjectGroup && share.Access == FileShare.ReadWrite).ToList();

var tasks = fileShares.Select(async share =>
{
Expand Down
26 changes: 1 addition & 25 deletions products/ASC.Files/Core/Core/FileStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,30 +2670,6 @@ public async Task<AceWrapper> SetExternalLinkAsync<T>(T entryId, FileEntryType e
return await SetExternalLinkAsync(entry.NotFoundIfNull(), linkId, share, title, expirationDate, password, denyDownload, primary, requiredAuth);
}

public async Task<bool> SetAceLinkAsync<T>(T fileId, FileShare share)
{
var fileDao = daoFactory.GetFileDao<T>();
FileEntry<T> file = await fileDao.GetFileAsync(fileId);
var aces = new List<AceWrapper> { new() { Access = share, Id = FileConstant.ShareLinkId, SubjectGroup = true } };

try
{
var result = await fileSharingAceHelper.SetAceObjectAsync(aces, file, false, null, null);
if (result.Changed)
{
await filesMessageService.SendAsync(MessageAction.FileExternalLinkAccessUpdated, file, file.Title, FileShareExtensions.GetAccessString(share));
}
}
catch (Exception e)
{
throw GenerateException(e);
}

var securityDao = daoFactory.GetSecurityDao<T>();

return await securityDao.IsSharedAsync(file.Id, FileEntryType.File);
}

public Task<List<MentionWrapper>> SharedUsersAsync<T>(T fileId)
{
if (!authContext.IsAuthenticated)
Expand Down Expand Up @@ -3242,7 +3218,7 @@ public async Task<List<MentionWrapper>> ProtectUsersAsync<T>(T fileId)
var usersInfo = new List<UserInfo>();
foreach (var ace in acesForObject)
{
if (ace.Access == FileShare.Restrict || ace.Id.Equals(FileConstant.ShareLinkId))
if (ace.Access == FileShare.Restrict)
{
continue;
}
Expand Down
6 changes: 0 additions & 6 deletions products/ASC.Files/Core/Core/Security/FileSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ await externalShare.ValidateRecordAsync(ace, null, isAuthenticated, e) != Status
}

var defaultShare =
userId == FileConstant.ShareLinkId ? FileShare.Restrict :
e.RootFolderType == FolderType.VirtualRooms ? DefaultVirtualRoomsShare :
e.RootFolderType == FolderType.USER ? DefaultMyShare :
e.RootFolderType == FolderType.Privacy ? DefaultPrivacyShare :
Expand Down Expand Up @@ -1998,11 +1997,6 @@ private async Task<List<Guid>> GetUserSubjectsAsync<T>(Guid userId, FileEntry<T>
{
result.Add(linkId);
}

if (userId == FileConstant.ShareLinkId)
{
return result;
}

if (entry is { RootFolderType: FolderType.USER } and not IFolder { FolderType: FolderType.USER } &&
entry.RootCreateBy != userId && linkId == Guid.Empty)
Expand Down
5 changes: 1 addition & 4 deletions products/ASC.Files/Core/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public static class FileConstant
public static readonly string StorageModule = "files";
public static readonly string StorageDomainTmp = "files_temp";
public static readonly string StorageTemplate = "files_template";

public static readonly string DatabaseId = "files";

public static readonly Guid ShareLinkId = new("{D77BD6AF-828B-41f5-84ED-7FFE2565B13A}");

public static readonly Guid DenyDownloadId = new("{EE7A7468-CDA5-4F8B-AFDB-F4E42C318EB6}");
public static readonly Guid DenySharingId = new("{AAFD9C26-9686-4996-9665-35CA72721C4C}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,11 @@ public async Task<string> GetDocKeyAsync<T>(T fileId, int fileVersion, DateTime

public async Task CheckUsersForDropAsync<T>(File<T> file)
{
var sharedLink =
await fileSecurity.CanEditAsync(file, FileConstant.ShareLinkId)
|| await fileSecurity.CanCustomFilterEditAsync(file, FileConstant.ShareLinkId)
|| await fileSecurity.CanReviewAsync(file, FileConstant.ShareLinkId)
|| await fileSecurity.CanFillFormsAsync(file, FileConstant.ShareLinkId)
|| await fileSecurity.CanCommentAsync(file, FileConstant.ShareLinkId);

var usersDrop = new List<string>();

foreach (var uid in fileTracker.GetEditingBy(file.Id))
{
if (!await userManager.UserExistsAsync(uid) && !sharedLink)
if (!await userManager.UserExistsAsync(uid))
{
usersDrop.Add(uid.ToString());
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public class AceShortWrapper
/// <type>System.String, System</type>
public string Permissions { get; set; }

/// <summary>Specifies if the external link is available or not</summary>
/// <type>System.Nullable{System.Boolean}, System</type>
public bool? IsLink { get; set; }

public AceShortWrapper(AceWrapper aceWrapper)
{
var permission = aceWrapper.Access switch
Expand All @@ -98,11 +94,6 @@ public AceShortWrapper(AceWrapper aceWrapper)
};

User = aceWrapper.SubjectName;
if (aceWrapper.Id.Equals(FileConstant.ShareLinkId))
{
IsLink = true;
User = FilesCommonResource.AceShareLink;
}

Permissions = permission;
}
Expand Down
57 changes: 3 additions & 54 deletions products/ASC.Files/Core/Utils/FileShareLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,8 @@
namespace ASC.Web.Files.Utils;

[Scope]
public class FileShareLink(FileUtility fileUtility,
FilesLinkUtility filesLinkUtility,
BaseCommonLinkUtility baseCommonLinkUtility,
Global global,
FileSecurity fileSecurity,
FilesSettingsHelper filesSettingsHelper)
public class FileShareLink(Global global, FilesSettingsHelper filesSettingsHelper)
{
public async Task<string> GetLinkAsync<T>(File<T> file, bool withHash = true)
{
var url = file.DownloadUrl;

if (fileUtility.CanWebView(file.Title))
{
url = filesLinkUtility.GetFileWebPreviewUrl(fileUtility, file.Title, file.Id);
}

if (withHash)
{
var linkParams = await CreateKeyAsync(file.Id);
url += "&" + FilesLinkUtility.DocShareKey + "=" + HttpUtility.UrlEncode(linkParams);
}

return baseCommonLinkUtility.GetFullAbsolutePath(url);
}

public async Task<string> CreateKeyAsync<T>(T fileId)
{
return Signature.Create(fileId, await global.GetDocDbKeyAsync());
Expand All @@ -61,6 +38,7 @@ public async Task<string> ParseAsync(string doc)
{
return Signature.Read<string>(doc ?? string.Empty, await global.GetDocDbKeyAsync());
}

public async Task<T> ParseAsync<T>(string doc)
{
return Signature.Read<T>(doc ?? string.Empty, await global.GetDocDbKeyAsync());
Expand Down Expand Up @@ -101,36 +79,7 @@ public async Task<T> ParseAsync<T>(string doc)
{
return (FileShare.Restrict, file);
}

if (await fileSecurity.CanEditAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.ReadWrite, file);
}

if (await fileSecurity.CanCustomFilterEditAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.CustomFilter, file);
}

if (await fileSecurity.CanReviewAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.Review, file);
}

if (await fileSecurity.CanFillFormsAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.FillForms, file);
}

if (await fileSecurity.CanCommentAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.Comment, file);
}

if (await fileSecurity.CanReadAsync(file, FileConstant.ShareLinkId))
{
return (FileShare.Read, file);
}


return (FileShare.Restrict, file);
}
Expand Down
Loading

0 comments on commit 2dd6fd9

Please sign in to comment.