namespace ASC.Files.Api; public class SecutiryController : ApiControllerBase { private readonly FileStorageService _fileStorageServiceInt; private readonly FileStorageService _fileStorageServiceString; private readonly SecurityControllerHelper _securityControllerHelperInt; private readonly SecurityControllerHelper _securityControllerHelperString; public SecutiryController( FileStorageService fileStorageServiceInt, FileStorageService fileStorageServiceString, SecurityControllerHelper securityControllerHelperInt, SecurityControllerHelper securityControllerHelperString) { _fileStorageServiceInt = fileStorageServiceInt; _fileStorageServiceString = fileStorageServiceString; _securityControllerHelperInt = securityControllerHelperInt; _securityControllerHelperString = securityControllerHelperString; } [Create("owner")] public IAsyncEnumerable ChangeOwnerFromBodyAsync([FromBody] ChangeOwnerRequestDto inDto) { return ChangeOwnerAsync(inDto); } [Create("owner")] [Consumes("application/x-www-form-urlencoded")] public IAsyncEnumerable ChangeOwnerFromFormAsync([FromForm] ChangeOwnerRequestDto inDto) { return ChangeOwnerAsync(inDto); } /// /// Returns the external link to the shared file with the ID specified in the request /// /// /// File external link /// /// File ID /// Access right /// Files /// Shared file link [Update("{fileId}/sharedlinkAsync")] public async Task GenerateSharedLinkFromBodyAsync(string fileId, [FromBody] GenerateSharedLinkRequestDto inDto) { return await _securityControllerHelperString.GenerateSharedLinkAsync(fileId, inDto.Share); } [Update("{fileId:int}/sharedlinkAsync")] public async Task GenerateSharedLinkFromBodyAsync(int fileId, [FromBody] GenerateSharedLinkRequestDto inDto) { return await _securityControllerHelperInt.GenerateSharedLinkAsync(fileId, inDto.Share); } [Update("{fileId}/sharedlinkAsync")] [Consumes("application/x-www-form-urlencoded")] public async Task GenerateSharedLinkFromFormAsync(string fileId, [FromForm] GenerateSharedLinkRequestDto inDto) { return await _securityControllerHelperString.GenerateSharedLinkAsync(fileId, inDto.Share); } [Update("{fileId:int}/sharedlinkAsync")] [Consumes("application/x-www-form-urlencoded")] public async Task GenerateSharedLinkFromFormAsync(int fileId, [FromForm] GenerateSharedLinkRequestDto inDto) { return await _securityControllerHelperInt.GenerateSharedLinkAsync(fileId, inDto.Share); } /// /// Returns the detailed information about shared file with the ID specified in the request /// /// File sharing /// Sharing /// File ID /// Shared file information [Read("file/{fileId}/share")] public Task> GetFileSecurityInfoAsync(string fileId) { return _securityControllerHelperString.GetFileSecurityInfoAsync(fileId); } [Read("file/{fileId:int}/share")] public Task> GetFileSecurityInfoAsync(int fileId) { return _securityControllerHelperInt.GetFileSecurityInfoAsync(fileId); } /// /// Returns the detailed information about shared folder with the ID specified in the request /// /// Folder sharing /// Folder ID /// Sharing /// Shared folder information [Read("folder/{folderId}/share")] public Task> GetFolderSecurityInfoAsync(string folderId) { return _securityControllerHelperString.GetFolderSecurityInfoAsync(folderId); } [Read("folder/{folderId:int}/share")] public Task> GetFolderSecurityInfoAsync(int folderId) { return _securityControllerHelperInt.GetFolderSecurityInfoAsync(folderId); } [Create("share")] public async Task> GetSecurityInfoFromBodyAsync([FromBody] BaseBatchRequestDto inDto) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds); var result = new List(); result.AddRange(await _securityControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds)); result.AddRange(await _securityControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds)); return result; } [Create("share")] [Consumes("application/x-www-form-urlencoded")] public async Task> GetSecurityInfoFromFormAsync([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchRequestDto inDto) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds); var result = new List(); result.AddRange(await _securityControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds)); result.AddRange(await _securityControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds)); return result; } /// /// Removes sharing rights for the group with the ID specified in the request /// /// Folders ID /// Files ID /// Remove group sharing rights /// Sharing /// Shared file information [Delete("share")] public async Task RemoveSecurityInfoAsync(BaseBatchRequestDto inDto) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds); await _securityControllerHelperInt.RemoveSecurityInfoAsync(fileIntIds, folderIntIds); await _securityControllerHelperString.RemoveSecurityInfoAsync(fileStringIds, folderStringIds); return true; } [Update("{fileId:int}/setacelink")] public Task SetAceLinkAsync(int fileId, [FromBody] GenerateSharedLinkRequestDto inDto) { return _fileStorageServiceInt.SetAceLinkAsync(fileId, inDto.Share); } [Update("{fileId}/setacelink")] public Task SetAceLinkAsync(string fileId, [FromBody] GenerateSharedLinkRequestDto inDto) { return _fileStorageServiceString.SetAceLinkAsync(fileId, inDto.Share); } /// /// Sets sharing settings for the file with the ID specified in the request /// /// File ID /// Collection of sharing rights /// Should notify people /// Sharing message to send when notifying /// Share file /// Sharing /// /// Each of the FileShareParams must contain two parameters: 'ShareTo' - ID of the user with whom we want to share and 'Access' - access type which we want to grant to the user (Read, ReadWrite, etc) /// /// Shared file information [Update("file/{fileId}/share")] public Task> SetFileSecurityInfoFromBodyAsync(string fileId, [FromBody] SecurityInfoRequestDto inDto) { return _securityControllerHelperString.SetFileSecurityInfoAsync(fileId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("file/{fileId:int}/share")] public Task> SetFileSecurityInfoFromBodyAsync(int fileId, [FromBody] SecurityInfoRequestDto inDto) { return _securityControllerHelperInt.SetFileSecurityInfoAsync(fileId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("file/{fileId}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFileSecurityInfoFromFormAsync(string fileId, [FromForm] SecurityInfoRequestDto inDto) { return _securityControllerHelperString.SetFileSecurityInfoAsync(fileId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("file/{fileId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFileSecurityInfoFromFormAsync(int fileId, [FromForm] SecurityInfoRequestDto inDto) { return _securityControllerHelperInt.SetFileSecurityInfoAsync(fileId, inDto.Share, inDto.Notify, inDto.SharingMessage); } /// /// Sets sharing settings for the folder with the ID specified in the request /// /// Share folder /// Folder ID /// Collection of sharing rights /// Should notify people /// Sharing message to send when notifying /// /// Each of the FileShareParams must contain two parameters: 'ShareTo' - ID of the user with whom we want to share and 'Access' - access type which we want to grant to the user (Read, ReadWrite, etc) /// /// Sharing /// Shared folder information [Update("folder/{folderId}/share")] public Task> SetFolderSecurityInfoFromBodyAsync(string folderId, [FromBody] SecurityInfoRequestDto inDto) { return _securityControllerHelperString.SetFolderSecurityInfoAsync(folderId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("folder/{folderId:int}/share")] public Task> SetFolderSecurityInfoFromBodyAsync(int folderId, [FromBody] SecurityInfoRequestDto inDto) { return _securityControllerHelperInt.SetFolderSecurityInfoAsync(folderId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("folder/{folderId}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFolderSecurityInfoFromFormAsync(string folderId, [FromForm] SecurityInfoRequestDto inDto) { return _securityControllerHelperString.SetFolderSecurityInfoAsync(folderId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("folder/{folderId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFolderSecurityInfoFromFormAsync(int folderId, [FromForm] SecurityInfoRequestDto inDto) { return _securityControllerHelperInt.SetFolderSecurityInfoAsync(folderId, inDto.Share, inDto.Notify, inDto.SharingMessage); } [Update("share")] public Task> SetSecurityInfoFromBodyAsync([FromBody] SecurityInfoRequestDto inDto) { return SetSecurityInfoAsync(inDto); } [Update("share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetSecurityInfoFromFormAsync([FromForm] SecurityInfoRequestDto inDto) { return SetSecurityInfoAsync(inDto); } private async IAsyncEnumerable ChangeOwnerAsync(ChangeOwnerRequestDto inDto) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds); var result = AsyncEnumerable.Empty(); result.Concat(_fileStorageServiceInt.ChangeOwnerAsync(folderIntIds, fileIntIds, inDto.UserId)); result.Concat(_fileStorageServiceString.ChangeOwnerAsync(folderStringIds, fileStringIds, inDto.UserId)); await foreach (var e in result) { yield return await _securityControllerHelperInt.GetFileEntryWrapperAsync(e); } } private async Task> SetSecurityInfoAsync(SecurityInfoRequestDto inDto) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds); var result = new List(); result.AddRange(await _securityControllerHelperInt.SetSecurityInfoAsync(fileIntIds, folderIntIds, inDto.Share, inDto.Notify, inDto.SharingMessage)); result.AddRange(await _securityControllerHelperString.SetSecurityInfoAsync(fileStringIds, folderStringIds, inDto.Share, inDto.Notify, inDto.SharingMessage)); return result; } }