Skip to content

Commit

Permalink
Merge pull request #124 from ONLYOFFICE/bugfix/disable-invite-link
Browse files Browse the repository at this point in the history
Bugfix/disable invite link
  • Loading branch information
pavelbannov authored Dec 26, 2023
2 parents c605e9e + 674fd46 commit a45f8ec
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/SecurityDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ public async IAsyncEnumerable<FileShareRecord> GetPureSharesAsync(FileEntry<T> e
q = q.Take(count);
}

await foreach (var r in q.ToAsyncEnumerable())
var records = q.ToAsyncEnumerable().SelectAwait(async r => await ToFileShareRecordAsync(r));

await foreach (var r in DeleteExpiredAsync(records, filesDbContext))
{
yield return await ToFileShareRecordAsync(r);
yield return r;
}
}

Expand Down Expand Up @@ -516,6 +518,33 @@ private async Task<IQueryable<DbFilesSecurity>> GetPureSharesQuery(FileEntry<T>

return q;
}

protected async IAsyncEnumerable<FileShareRecord> DeleteExpiredAsync(IAsyncEnumerable<FileShareRecord> records, FilesDbContext filesDbContext)
{
var expired = new List<Guid>();

await foreach (var r in records)
{
if (r.SubjectType == SubjectType.InvitationLink && r.Options is { IsExpired: true })
{
expired.Add(r.Subject);
continue;
}

yield return r;
}

if (expired.Count <= 0)
{
yield break;
}

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await filesDbContext.Security
.Where(s => s.TenantId == tenantId && s.SubjectType == SubjectType.InvitationLink && expired.Contains(s.Subject))
.ExecuteDeleteAsync();
}
}

[Scope]
Expand Down Expand Up @@ -597,41 +626,12 @@ public async Task<IEnumerable<FileShareRecord>> GetSharesAsync(FileEntry<int> en
q = q.Where(r => subjects.Contains(r.Subject));
}

var records = await q.ToAsyncEnumerable()
var records = q.ToAsyncEnumerable()
.Select(ToFileShareRecord)
.OrderBy(r => r.Level)
.ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer())
.ToListAsync();

await DeleteExpiredAsync(records, filesDbContext);

return records;
}
.ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer());

private async Task DeleteExpiredAsync(List<FileShareRecord> records, FilesDbContext filesDbContext)
{
var expired = new List<Guid>();

for (var i = 0; i < records.Count; i++)
{
var r = records[i];
if (r.SubjectType != SubjectType.InvitationLink || r.Options is not { IsExpired: true })
{
continue;
}

expired.Add(r.Subject);
records.RemoveAt(i);
}

if (expired.Count > 0)
{
var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await filesDbContext.Security
.Where(s => s.TenantId == tenantId && s.SubjectType == SubjectType.InvitationLink && expired.Contains(s.Subject))
.ExecuteDeleteAsync();
}
return await DeleteExpiredAsync(records, filesDbContext).ToListAsync();
}
}

Expand Down

0 comments on commit a45f8ec

Please sign in to comment.