Skip to content

Commit

Permalink
Merge pull request #143 from ONLYOFFICE/bugfix/leave-the-room
Browse files Browse the repository at this point in the history
Bugfix/leave the room
  • Loading branch information
pavelbannov authored Jan 12, 2024
2 parents 76ce026 + b48976e commit 830dead
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
63 changes: 26 additions & 37 deletions products/ASC.Files/Core/ApiModels/ResponseDto/FolderContentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,27 @@ public async Task<FolderContentDto<T>> GetAsync<T>(DataWrapper<T> folderItems, i

IAsyncEnumerable<Tuple<FileEntry<T1>, bool>> GetFoldersWithRightsAsync<T1>(IEnumerable<T1> ids)
{
if (ids.Any())
if (!ids.Any())
{
var folderDao = _daoFactory.GetFolderDao<T1>();

return _fileSecurity.CanReadAsync(folderDao.GetFoldersAsync(ids));
return AsyncEnumerable.Empty<Tuple<FileEntry<T1>, bool>>();
}

return AsyncEnumerable.Empty<Tuple<FileEntry<T1>, bool>>();
var folderDao = _daoFactory.GetFolderDao<T1>();
return _fileSecurity.CanReadAsync(folderDao.GetFoldersAsync(ids));
}

async IAsyncEnumerable<FileEntryDto> GetFilesDto(IEnumerable<FileEntry> fileEntries)
{
foreach (var r in fileEntries)
{
if (r is File<int> fol1)
{
yield return await _fileDtoHelper.GetAsync(fol1, foldersIntWithRights);
}
else if (r is File<string> fol2)
switch (r)
{
yield return await _fileDtoHelper.GetAsync(fol2, foldersStringWithRights);
case File<int> fol1:
yield return await _fileDtoHelper.GetAsync(fol1, foldersIntWithRights);
break;
case File<string> fol2:
yield return await _fileDtoHelper.GetAsync(fol2, foldersStringWithRights);
break;
}
}
}
Expand All @@ -208,40 +208,29 @@ async IAsyncEnumerable<FileEntryDto> GetFoldersDto(IEnumerable<FileEntry> folder

foreach (var r in folderEntries)
{
if (r is Folder<int> fol1)
switch (r)
{
yield return await GetFolder(fol1, foldersIntWithRights);
}
else if (r is Folder<string> fol2)
{
yield return await GetFolder(fol2, foldersStringWithRights);
case Folder<int> fol1:
yield return await GetFolder(fol1, foldersIntWithRights);
break;
case Folder<string> fol2:
yield return await GetFolder(fol2, foldersStringWithRights);
break;
}
}

yield break;

async Task<FolderDto<T1>> GetFolder<T1>(Folder<T1> fol1, List<Tuple<FileEntry<T1>, bool>> foldersWithRights)
{
var result = await _folderDtoHelper.GetAsync(fol1, foldersWithRights);
if (DocSpaceHelper.IsRoom(fol1.FolderType))
if (currentUsersRecords == null &&
DocSpaceHelper.IsRoom(fol1.FolderType) &&
await _fileSecurityCommon.IsDocSpaceAdministratorAsync(_authContext.CurrentAccount.ID))
{
if (fol1.CreateBy == _authContext.CurrentAccount.ID)
{
result.InRoom = true;
}
else
{
if (currentUsersRecords == null && await _fileSecurityCommon.IsDocSpaceAdministratorAsync(_authContext.CurrentAccount.ID))
{
var securityDao = _daoFactory.GetSecurityDao<T>();
var currentUserSubjects = await _fileSecurity.GetUserSubjectsAsync(_authContext.CurrentAccount.ID);
currentUsersRecords = await securityDao.GetSharesAsync(currentUserSubjects).ToListAsync();
}
if (currentUsersRecords != null)
{
result.InRoom = currentUsersRecords.Exists(c => c.EntryId.Equals(fol1.Id));
}
}
currentUsersRecords = await _fileSecurity.GetUserRecordsAsync<T>(_authContext.CurrentAccount.ID).ToListAsync();
}
return result;

return await _folderDtoHelper.GetAsync(fol1, foldersWithRights, currentUsersRecords);
}
}
}
Expand Down
25 changes: 18 additions & 7 deletions products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public class FolderDtoHelper : FileEntryDtoHelper
private readonly RoomLogoManager _roomLogoManager;
private readonly RoomsNotificationSettingsHelper _roomsNotificationSettingsHelper;
private readonly BadgesSettingsHelper _badgesSettingsHelper;

private readonly FileSecurityCommon _fileSecurityCommon;

public FolderDtoHelper(
ApiDateTimeHelper apiDateTimeHelper,
EmployeeDtoHelper employeeWrapperHelper,
Expand All @@ -124,18 +125,20 @@ public FolderDtoHelper(
BadgesSettingsHelper badgesSettingsHelper,
RoomsNotificationSettingsHelper roomsNotificationSettingsHelper,
FilesSettingsHelper filesSettingsHelper,
FileDateTime fileDateTime)
FileDateTime fileDateTime,
FileSecurityCommon fileSecurityCommon)
: base(apiDateTimeHelper, employeeWrapperHelper, fileSharingHelper, fileSecurity, globalFolderHelper, filesSettingsHelper, fileDateTime)
{
_authContext = authContext;
_daoFactory = daoFactory;
_globalFolderHelper = globalFolderHelper;
_roomLogoManager = roomLogoManager;
_roomsNotificationSettingsHelper = roomsNotificationSettingsHelper;
_fileSecurityCommon = fileSecurityCommon;
_badgesSettingsHelper = badgesSettingsHelper;
}

public async Task<FolderDto<T>> GetAsync<T>(Folder<T> folder, List<Tuple<FileEntry<T>, bool>> folders = null)
public async Task<FolderDto<T>> GetAsync<T>(Folder<T> folder, List<Tuple<FileEntry<T>, bool>> folders = null, List<FileShareRecord> currentUserRecords = null)
{
var result = await GetFolderWrapperAsync(folder);

Expand All @@ -146,7 +149,6 @@ public async Task<FolderDto<T>> GetAsync<T>(Folder<T> folder, List<Tuple<FileEnt
if (folder.Tags == null)
{
var tagDao = _daoFactory.GetTagDao<T>();

result.Tags = await tagDao.GetTagsAsync(TagType.Custom, new[] { folder }).Select(t => t.Name).ToListAsync();
}
else
Expand All @@ -161,10 +163,19 @@ public async Task<FolderDto<T>> GetAsync<T>(Folder<T> folder, List<Tuple<FileEnt
{
result.ParentId = IdConverter.Convert<T>(await _globalFolderHelper.GetFolderVirtualRooms());
}

if (DocSpaceHelper.IsRoom(folder.FolderType))

result.Mute = _roomsNotificationSettingsHelper.CheckMuteForRoom(result.Id.ToString());

if (folder.CreateBy == _authContext.CurrentAccount.ID ||
!await _fileSecurityCommon.IsDocSpaceAdministratorAsync(_authContext.CurrentAccount.ID))
{
result.Mute = _roomsNotificationSettingsHelper.CheckMuteForRoom(result.Id.ToString());
result.InRoom = true;
}
else
{
currentUserRecords ??= await _fileSecurity.GetUserRecordsAsync<T>(_authContext.CurrentAccount.ID).ToListAsync();

result.InRoom = currentUserRecords.Exists(c => c.EntryId.Equals(folder.Id));
}
}

Expand Down
11 changes: 11 additions & 0 deletions products/ASC.Files/Core/Core/Security/FileSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,17 @@ public async Task<List<Guid>> GetUserSubjectsAsync(Guid userId)
return result;
}

public async IAsyncEnumerable<FileShareRecord> GetUserRecordsAsync<T>(Guid userId)
{
var securityDao = _daoFactory.GetSecurityDao<T>();
var currentUserSubjects = await GetUserSubjectsAsync(_authContext.CurrentAccount.ID);

await foreach (var record in securityDao.GetSharesAsync(currentUserSubjects))
{
yield return record;
}
}

public static void CorrectSecurityByLockedStatus<T>(FileEntry<T> entry)
{
if (entry is not File<T> file || file.Security == null || file.LockedBy == null)
Expand Down

0 comments on commit 830dead

Please sign in to comment.