From 186bc608ae7682966e351c6b113c489026fbc20e Mon Sep 17 00:00:00 2001 From: Maksim Chegulov Date: Tue, 16 Jan 2024 11:53:54 +0300 Subject: [PATCH] fix Bug 65889 --- products/ASC.Files/Core/Utils/FileSharing.cs | 50 ++++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/products/ASC.Files/Core/Utils/FileSharing.cs b/products/ASC.Files/Core/Utils/FileSharing.cs index 58611c3995a..aa896cc7f58 100644 --- a/products/ASC.Files/Core/Utils/FileSharing.cs +++ b/products/ASC.Files/Core/Utils/FileSharing.cs @@ -145,25 +145,6 @@ public async Task SetAceObjectAsync(List ace continue; } - if (w.IsLink && eventType == EventType.Create) - { - var (filter, maxCount) = w.SubjectType switch - { - SubjectType.InvitationLink => (ShareFilterType.InvitationLink, MaxInvitationLinks), - SubjectType.ExternalLink => (ShareFilterType.AdditionalExternalLink, MaxAdditionalExternalLinks), - SubjectType.PrimaryExternalLink => (ShareFilterType.PrimaryExternalLink, MaxPrimaryExternalLinks), - _ => (ShareFilterType.Link, 0) - }; - - var linksCount = await _fileSecurity.GetPureSharesCountAsync(entry, filter, null); - - if (linksCount >= maxCount) - { - warning ??= string.Format(FilesCommonResource.ErrorMessage_MaxLinksCount, maxCount); - continue; - } - } - if (w.SubjectType == SubjectType.PrimaryExternalLink && w.FileShareOptions != null) { w.FileShareOptions.ExpirationDate = default; @@ -262,7 +243,36 @@ public async Task SetAceObjectAsync(List ace : w.Access; } - await _fileSecurity.ShareAsync(entry.Id, entryType, w.Id, share, w.SubjectType, w.FileShareOptions); + try + { + if (w.IsLink && eventType == EventType.Create) + { + var (filter, maxCount) = w.SubjectType switch + { + SubjectType.InvitationLink => (ShareFilterType.InvitationLink, MaxInvitationLinks), + SubjectType.ExternalLink => (ShareFilterType.AdditionalExternalLink, MaxAdditionalExternalLinks), + SubjectType.PrimaryExternalLink => (ShareFilterType.PrimaryExternalLink, MaxPrimaryExternalLinks), + _ => (ShareFilterType.Link, 0) + }; + + //TODO: Replace with a distributed lock + await _semaphore.WaitAsync(); + + var linksCount = await _fileSecurity.GetPureSharesCountAsync(entry, filter, null); + if (linksCount >= maxCount) + { + warning ??= string.Format(FilesCommonResource.ErrorMessage_MaxLinksCount, maxCount); + continue; + } + } + + await _fileSecurity.ShareAsync(entry.Id, entryType, w.Id, share, w.SubjectType, w.FileShareOptions); + } + finally + { + _semaphore.Release(); + } + if (socket && room != null) { if (share == FileShare.None)