Skip to content

Commit

Permalink
Merge pull request #148 from ONLYOFFICE/bugfix/65889
Browse files Browse the repository at this point in the history
Bugfix/65889
  • Loading branch information
pavelbannov authored Jan 16, 2024
2 parents 602e9ff + 186bc60 commit ddd8c92
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions products/ASC.Files/Core/Utils/FileSharing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,6 @@ public async Task<AceProcessingResult> SetAceObjectAsync<T>(List<AceWrapper> 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;
Expand Down Expand Up @@ -262,7 +243,36 @@ public async Task<AceProcessingResult> SetAceObjectAsync<T>(List<AceWrapper> 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)
Expand Down

0 comments on commit ddd8c92

Please sign in to comment.