Files: added property InRoom for docspace owner

This commit is contained in:
pavelbannov 2023-09-18 20:20:34 +03:00
parent 84f77d3b3d
commit afb7ec9264
4 changed files with 48 additions and 31 deletions

View File

@ -24,7 +24,6 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
namespace ASC.Files.Core.ApiModels.ResponseDto;
/// <summary>
@ -89,6 +88,8 @@ public class FolderContentDto<T>
public class FolderContentDtoHelper
{
private readonly FileSecurity _fileSecurity;
private readonly FileSecurityCommon _fileSecurityCommon;
private readonly AuthContext _authContext;
private readonly IDaoFactory _daoFactory;
private readonly FileDtoHelper _fileDtoHelper;
private readonly FolderDtoHelper _folderDtoHelper;
@ -99,13 +100,17 @@ public class FolderContentDtoHelper
IDaoFactory daoFactory,
FileDtoHelper fileWrapperHelper,
FolderDtoHelper folderWrapperHelper,
BadgesSettingsHelper badgesSettingsHelper)
BadgesSettingsHelper badgesSettingsHelper,
FileSecurityCommon fileSecurityCommon,
AuthContext authContext)
{
_fileSecurity = fileSecurity;
_daoFactory = daoFactory;
_fileDtoHelper = fileWrapperHelper;
_folderDtoHelper = folderWrapperHelper;
_badgesSettingsHelper = badgesSettingsHelper;
_fileSecurityCommon = fileSecurityCommon;
_authContext = authContext;
}
public async Task<FolderContentDto<T>> GetAsync<T>(DataWrapper<T> folderItems, int startIndex)
@ -201,17 +206,45 @@ public class FolderContentDtoHelper
async IAsyncEnumerable<FileEntryDto> GetFoldersDto(IEnumerable<FileEntry> folderEntries)
{
List<FileShareRecord> currentUsersRecords = null;
foreach (var r in folderEntries)
{
if (r is Folder<int> fol1)
{
yield return await _folderDtoHelper.GetAsync(fol1, foldersIntWithRights);
yield return await GetFolder(fol1, foldersIntWithRights);
}
else if (r is Folder<string> fol2)
{
yield return await _folderDtoHelper.GetAsync(fol2, foldersStringWithRights);
yield return await GetFolder(fol2, foldersStringWithRights);
}
}
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 (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.Any(c => c.EntryId.Equals(fol1.Id));
}
}
}
return result;
}
}
}
}

View File

@ -78,6 +78,8 @@ public class FolderDto<T> : FileEntryDto<T>
/// <type>System.Boolean, System</type>
public bool Private { get; set; }
public bool? InRoom { get; set; }
protected internal override FileEntryType EntryType { get => FileEntryType.Folder; }
public FolderDto() { }

View File

@ -375,9 +375,10 @@ public class FileStorageService //: IFileStorageService
}
}
parent.Shareable = await shareableTask
|| parent.FolderType == FolderType.SHARE
|| parent.RootFolderType == FolderType.Privacy;
parent.Shareable =
parent.FolderType == FolderType.SHARE ||
parent.RootFolderType == FolderType.Privacy ||
await shareableTask;
entries = entries.Where(x =>
{
@ -2407,22 +2408,15 @@ public class FileStorageService //: IFileStorageService
#endregion
public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(IEnumerable<T> fileIds, IEnumerable<T> folderIds, IEnumerable<SubjectType> subjectTypes = null,
public async Task<List<AceWrapper>> GetSharedInfoAsync<T>(
IEnumerable<T> fileIds,
IEnumerable<T> folderIds,
IEnumerable<SubjectType> subjectTypes = null,
bool withoutTemplates = false)
{
return await _fileSharing.GetSharedInfoAsync(fileIds, folderIds, subjectTypes, withoutTemplates);
}
public async Task<List<AceShortWrapper>> GetSharedInfoShortFileAsync<T>(T fileId)
{
return await _fileSharing.GetSharedInfoShortFileAsync(fileId);
}
public async Task<List<AceShortWrapper>> GetSharedInfoShortFolder<T>(T folderId)
{
return await _fileSharing.GetSharedInfoShortFolderAsync(folderId);
}
public async Task<string> SetAceObjectAsync<T>(AceCollection<T> aceCollection, bool notify)
{
var fileDao = GetFileDao<T>();
@ -2825,7 +2819,7 @@ public class FileStorageService //: IFileStorageService
_logger.ErrorWithException(ex);
}
return showSharingSettings ? await GetSharedInfoShortFileAsync(fileId) : null;
return showSharingSettings ? await _fileSharing.GetSharedInfoShortFileAsync(fileId) : null;
}
public async Task<List<EncryptionKeyPairDto>> GetEncryptionAccessAsync<T>(T fileId)

View File

@ -817,18 +817,6 @@ public class FileSharing
{
var aces = await GetSharedInfoAsync(new List<T> { fileID }, new List<T>());
return GetAceShortWrappers(aces);
}
public async Task<List<AceShortWrapper>> GetSharedInfoShortFolderAsync<T>(T folderId)
{
var aces = await GetSharedInfoAsync(new List<T>(), new List<T> { folderId });
return GetAceShortWrappers(aces);
}
private List<AceShortWrapper> GetAceShortWrappers(List<AceWrapper> aces)
{
return new List<AceShortWrapper>(aces
.Where(aceWrapper => !aceWrapper.Id.Equals(FileConstant.ShareLinkId) || aceWrapper.Access != FileShare.Restrict)
.Select(aceWrapper => new AceShortWrapper(aceWrapper)));