Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/65889 #148

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading