Files: added creating private thirdparty room

This commit is contained in:
Maksim Chegulov 2022-07-21 12:38:23 +03:00
parent f92144d9df
commit 987788bab7
5 changed files with 58 additions and 57 deletions

View File

@ -35,7 +35,7 @@ public interface IProviderDao
IAsyncEnumerable<IProviderInfo> GetProvidersInfoAsync(Guid userId); IAsyncEnumerable<IProviderInfo> GetProvidersInfoAsync(Guid userId);
Task<int> SaveProviderInfoAsync(string providerKey, string customerTitle, AuthData authData, FolderType folderType); Task<int> SaveProviderInfoAsync(string providerKey, string customerTitle, AuthData authData, FolderType folderType);
Task<bool> UpdateProviderInfoAsync(int linkId, FolderType rootFolderType); Task<bool> UpdateProviderInfoAsync(int linkId, FolderType rootFolderType);
Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType); Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType, bool @private);
Task<int> UpdateProviderInfoAsync(int linkId, string customerTitle, AuthData authData, FolderType folderType, Guid? userId = null); Task<int> UpdateProviderInfoAsync(int linkId, string customerTitle, AuthData authData, FolderType folderType, Guid? userId = null);
Task RemoveProviderInfoAsync(int linkId); Task RemoveProviderInfoAsync(int linkId);
} }

View File

@ -424,11 +424,11 @@ public class FileStorageService<T> //: IFileStorageService
return InternalCreateNewFolderAsync(parentId, title); return InternalCreateNewFolderAsync(parentId, title);
} }
public async Task<Folder<T>> CreateRoomAsync(string title, RoomType roomType, bool privacy, IEnumerable<FileShareParams> share, bool notify, string sharingMessage) public async Task<Folder<T>> CreateRoomAsync(string title, RoomType roomType, bool @private, IEnumerable<FileShareParams> share, bool notify, string sharingMessage)
{ {
ArgumentNullException.ThrowIfNull(title, nameof(title)); ArgumentNullException.ThrowIfNull(title, nameof(title));
if (privacy && (share == null || !share.Any())) if (@private && (share == null || !share.Any()))
{ {
throw new ArgumentNullException(nameof(share)); throw new ArgumentNullException(nameof(share));
} }
@ -437,50 +437,23 @@ public class FileStorageService<T> //: IFileStorageService
var room = roomType switch var room = roomType switch
{ {
RoomType.CustomRoom => await CreateCustomRoomAsync(title, parentId, privacy), RoomType.CustomRoom => await CreateCustomRoomAsync(title, parentId, @private),
RoomType.FillingFormsRoom => await CreateFillingFormsRoom(title, parentId, privacy), RoomType.FillingFormsRoom => await CreateFillingFormsRoom(title, parentId, @private),
RoomType.EditingRoom => await CreateEditingRoom(title, parentId, privacy), RoomType.EditingRoom => await CreateEditingRoom(title, parentId, @private),
RoomType.ReviewRoom => await CreateReviewRoom(title, parentId, privacy), RoomType.ReviewRoom => await CreateReviewRoom(title, parentId, @private),
RoomType.ReadOnlyRoom => await CreateReadOnlyRoom(title, parentId, privacy), RoomType.ReadOnlyRoom => await CreateReadOnlyRoom(title, parentId, @private),
_ => await CreateCustomRoomAsync(title, parentId, privacy), _ => await CreateCustomRoomAsync(title, parentId, @private),
}; };
if (privacy) if (@private)
{ {
var list = new List<AceWrapper>(share.Select(_fileShareParamsHelper.ToAceObject)); await SetAcesForPrivateRoomAsync(room, share, notify, sharingMessage);
var admins = _userManager.GetUsersByGroup(Constants.GroupAdmin.ID);
var onlyFilesAdmins = _userManager.GetUsersByGroup(WebItemManager.DocumentsProductID);
var userInfos = admins.Union(onlyFilesAdmins).ToList();
list.AddRange(admins.Select(admin => new AceWrapper
{
Share = FileShare.ReadWrite,
SubjectId = admin.Id
}));
var advancedSettings = new AceAdvancedSettingsWrapper
{
AllowSharingPrivateRoom = true
};
var aceCollection = new AceCollection<T>
{
Folders = new[] { room.Id },
Files = Array.Empty<T>(),
Aces = list,
Message = sharingMessage,
AdvancedSettings = advancedSettings
};
await SetAceObjectAsync(aceCollection, notify);
} }
return room; return room;
} }
public async Task<Folder<T>> CreateThirdPartyRoomAsync(string title, RoomType roomType, T parentId, bool privacy) public async Task<Folder<T>> CreateThirdPartyRoomAsync(string title, RoomType roomType, T parentId, bool @private, IEnumerable<FileShareParams> share, bool notify, string sharingMessage)
{ {
ArgumentNullException.ThrowIfNull(title, nameof(title)); ArgumentNullException.ThrowIfNull(title, nameof(title));
ArgumentNullException.ThrowIfNull(parentId, nameof(parentId)); ArgumentNullException.ThrowIfNull(parentId, nameof(parentId));
@ -503,25 +476,20 @@ public class FileStorageService<T> //: IFileStorageService
var room = roomType switch var room = roomType switch
{ {
RoomType.CustomRoom => await CreateCustomRoomAsync(title, parentId, privacy), RoomType.CustomRoom => await CreateCustomRoomAsync(title, parentId, @private),
RoomType.FillingFormsRoom => await CreateFillingFormsRoom(title, parentId, privacy), RoomType.FillingFormsRoom => await CreateFillingFormsRoom(title, parentId, @private),
RoomType.EditingRoom => await CreateEditingRoom(title, parentId, privacy), RoomType.EditingRoom => await CreateEditingRoom(title, parentId, @private),
RoomType.ReviewRoom => await CreateReviewRoom(title, parentId, privacy), RoomType.ReviewRoom => await CreateReviewRoom(title, parentId, @private),
RoomType.ReadOnlyRoom => await CreateReadOnlyRoom(title, parentId, privacy), RoomType.ReadOnlyRoom => await CreateReadOnlyRoom(title, parentId, @private),
_ => await CreateCustomRoomAsync(title, parentId, privacy), _ => await CreateCustomRoomAsync(title, parentId, @private),
}; };
var folderType = roomType switch if (@private)
{ {
RoomType.CustomRoom => FolderType.CustomRoom, await SetAcesForPrivateRoomAsync(room, share, notify, sharingMessage);
RoomType.ReviewRoom => FolderType.ReviewRoom, }
RoomType.EditingRoom => FolderType.EditingRoom,
RoomType.FillingFormsRoom => FolderType.FillingFormsRoom,
RoomType.ReadOnlyRoom => FolderType.ReadOnlyRoom,
_ => FolderType.CustomRoom
};
await providerDao.UpdateProviderInfoAsync(providerInfo.ID, room.Id.ToString(), folderType); await providerDao.UpdateProviderInfoAsync(providerInfo.ID, room.Id.ToString(), room.FolderType, @private);
return room; return room;
} }
@ -3066,6 +3034,38 @@ public class FileStorageService<T> //: IFileStorageService
return string.Empty; return string.Empty;
} }
} }
private async Task SetAcesForPrivateRoomAsync(Folder<T> room, IEnumerable<FileShareParams> share, bool notify, string sharingMessage)
{
var list = new List<AceWrapper>(share.Select(_fileShareParamsHelper.ToAceObject));
var admins = _userManager.GetUsersByGroup(Constants.GroupAdmin.ID);
var onlyFilesAdmins = _userManager.GetUsersByGroup(WebItemManager.DocumentsProductID);
var userInfos = admins.Union(onlyFilesAdmins).ToList();
list.AddRange(admins.Select(admin => new AceWrapper
{
Share = FileShare.ReadWrite,
SubjectId = admin.Id
}));
var advancedSettings = new AceAdvancedSettingsWrapper
{
AllowSharingPrivateRoom = true
};
var aceCollection = new AceCollection<T>
{
Folders = new[] { room.Id },
Files = Array.Empty<T>(),
Aces = list,
Message = sharingMessage,
AdvancedSettings = advancedSettings
};
await SetAceObjectAsync(aceCollection, notify);
}
} }
public class FileModel<T, TTempate> public class FileModel<T, TTempate>

View File

@ -224,7 +224,7 @@ internal class ProviderAccountDao : IProviderDao
return true; return true;
} }
public async Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType) public async Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType, bool @private)
{ {
var forUpdate = await FilesDbContext.ThirdpartyAccount var forUpdate = await FilesDbContext.ThirdpartyAccount
.Where(r => r.Id == linkId) .Where(r => r.Id == linkId)
@ -238,6 +238,7 @@ internal class ProviderAccountDao : IProviderDao
forUpdate.RoomType = folderType; forUpdate.RoomType = folderType;
forUpdate.FolderId = folderId; forUpdate.FolderId = folderId;
forUpdate.Private = @private;
await FilesDbContext.SaveChangesAsync().ConfigureAwait(false); await FilesDbContext.SaveChangesAsync().ConfigureAwait(false);

View File

@ -189,7 +189,7 @@ class FileDeleteOperation<T> : FileOperation<FileDeleteOperationData<T>, T>
{ {
if (folder.ProviderEntry) if (folder.ProviderEntry)
{ {
await ProviderDao.UpdateProviderInfoAsync(folder.ProviderId, null, FolderType.DEFAULT); await ProviderDao.UpdateProviderInfoAsync(folder.ProviderId, null, FolderType.DEFAULT, false);
} }
filesMessageService.Send(folder, _headers, MessageAction.RoomDeleted, folder.Title); filesMessageService.Send(folder, _headers, MessageAction.RoomDeleted, folder.Title);

View File

@ -90,7 +90,7 @@ public class VirtualRoomsThirdPartyController : VirtualRoomsController<string>
{ {
ErrorIfNotDocSpace(); ErrorIfNotDocSpace();
var room = await _fileStorageService.CreateThirdPartyRoomAsync(inDto.Title, inDto.RoomType, id, inDto.Private); var room = await _fileStorageService.CreateThirdPartyRoomAsync(inDto.Title, inDto.RoomType, id, inDto.Private, inDto.Share, inDto.Notify, inDto.SharingMessage);
return await _folderDtoHelper.GetAsync(room); return await _folderDtoHelper.GetAsync(room);
} }