DocSpace-buildtools/products/ASC.Files/Server/Api/VirtualRoomsController.cs

178 lines
7.9 KiB
C#
Raw Normal View History

2022-04-10 12:30:46 +00:00
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// 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.Api;
[ConstraintRoute("int")]
2022-04-12 07:33:59 +00:00
public class VirtualRoomsControllerInternal : VirtualRoomsController<int>
2022-04-10 12:30:46 +00:00
{
public VirtualRoomsControllerInternal(FoldersControllerHelper<int> foldersControllerHelper, GlobalFolderHelper globalFolderHelper, FileStorageService<int> fileStorageService, FolderDtoHelper folderDtoHelper, FileOperationDtoHelper fileOperationDtoHelper, SecurityControllerHelper<int> securityControllerHelper, CoreBaseSettings coreBaseSettings, FolderContentDtoHelper folderContentDtoHelper, ApiContext apiContext) : base(foldersControllerHelper, globalFolderHelper, fileStorageService, folderDtoHelper, fileOperationDtoHelper, securityControllerHelper, coreBaseSettings, folderContentDtoHelper, apiContext)
2022-04-10 12:30:46 +00:00
{
}
}
2022-04-12 07:33:59 +00:00
public abstract class VirtualRoomsController<T> : ApiControllerBase
2022-04-10 12:30:46 +00:00
{
2022-04-12 07:33:59 +00:00
private readonly FoldersControllerHelper<T> _foldersControllerHelper;
private readonly FileStorageService<T> _fileStorageService;
2022-04-11 10:12:34 +00:00
private readonly FolderDtoHelper _folderDtoHelper;
private readonly FolderContentDtoHelper _folderContentDtoHelper;
2022-04-10 12:30:46 +00:00
private readonly GlobalFolderHelper _globalFolderHelper;
2022-04-13 13:01:50 +00:00
private readonly FileOperationDtoHelper _fileOperationDtoHelper;
private readonly SecurityControllerHelper<T> _securityControllerHelper;
2022-04-20 08:26:31 +00:00
private readonly CoreBaseSettings _coreBaseSettings;
private readonly ApiContext _apiContext;
2022-04-10 12:30:46 +00:00
2022-04-12 07:33:59 +00:00
public VirtualRoomsController(FoldersControllerHelper<T> foldersControllerHelper, GlobalFolderHelper globalFolderHelper,
FileStorageService<T> fileStorageService, FolderDtoHelper folderDtoHelper, FileOperationDtoHelper fileOperationDtoHelper,
SecurityControllerHelper<T> securityControllerHelper, CoreBaseSettings coreBaseSettings,
FolderContentDtoHelper folderContentDtoHelper, ApiContext apiContext)
2022-04-10 12:30:46 +00:00
{
2022-04-12 07:33:59 +00:00
_foldersControllerHelper = foldersControllerHelper;
2022-04-10 12:30:46 +00:00
_globalFolderHelper = globalFolderHelper;
2022-04-12 07:33:59 +00:00
_fileStorageService = fileStorageService;
2022-04-11 10:12:34 +00:00
_folderDtoHelper = folderDtoHelper;
2022-04-13 13:01:50 +00:00
_fileOperationDtoHelper = fileOperationDtoHelper;
_securityControllerHelper = securityControllerHelper;
2022-04-20 08:26:31 +00:00
_coreBaseSettings = coreBaseSettings;
_folderContentDtoHelper = folderContentDtoHelper;
_apiContext = apiContext;
2022-04-10 12:30:46 +00:00
}
2022-04-22 08:28:57 +00:00
[Read("rooms")]
public async Task<FolderContentDto<T>> GetRoomsFolderAsync(RoomType type, int from, int count, string search, bool searchInContent, SearchArea searchArea, SortedByType orderBy)
2022-04-10 12:30:46 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
var parentId = searchArea switch
{
SearchArea.Active => await _globalFolderHelper.GetFolderVirtualRooms<T>(),
SearchArea.Archive => await _globalFolderHelper.GetFolderArchive<T>(),
_ => await _globalFolderHelper.GetFolderVirtualRooms<T>()
};
2022-04-11 10:12:34 +00:00
var filter = type switch
{
RoomType.FillingFormsRoom => FilterType.FillingFormsRoomsOnly,
RoomType.ReadOnlyRoom => FilterType.ReadOnlyRoomsOnly,
RoomType.EditingRoom => FilterType.EditingRoomsOnly,
RoomType.ReviewRoom => FilterType.ReviewRoomsOnly,
RoomType.CustomRoom => FilterType.CustomRoomsOnly,
_ => FilterType.None
};
var sortedBy = new OrderBy(orderBy, !_apiContext.SortDescending);
2022-04-20 08:26:31 +00:00
var content = await _fileStorageService.GetFolderItemsAsync(parentId, from, count, filter, false, string.Empty, search, true, false, sortedBy);
var dto = await _folderContentDtoHelper.GetAsync(content, 0);
return dto.NotFoundIfNull();
2022-04-15 14:22:44 +00:00
}
[Create("rooms")]
public async Task<FolderDto<T>> CreateRoomAsync([FromBody] CreateRoomRequestDto inDto)
2022-04-11 10:12:34 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
2022-04-12 07:33:59 +00:00
var room = await _fileStorageService.CreateRoom(inDto.Title, inDto.RoomType);
2022-04-11 10:12:34 +00:00
return await _folderDtoHelper.GetAsync(room);
}
2022-04-13 13:01:50 +00:00
[Read("rooms/{id}")]
public async Task<FolderContentDto<T>> GetRoomAsync(T id, Guid userOrGroupId, FilterType filterType, bool withSubFolders)
2022-04-13 14:25:12 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
return await _foldersControllerHelper.GetFolderAsync(id, userOrGroupId, filterType, withSubFolders);
}
[Update("rooms/{id}")]
public async Task<FolderDto<T>> UpdateRoomAsync(T id, [FromBody] UpdateRoomRequestDto inDto)
{
ErrorIfNotDocSpace();
var room = await _fileStorageService.FolderRenameAsync(id, inDto.Title);
2022-04-13 14:25:12 +00:00
return await _folderDtoHelper.GetAsync(room);
}
[Delete("rooms/{id}")]
public async Task<FileOperationDto> DeleteRoomAsync(T id)
2022-04-13 13:01:50 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
var operationResult = _fileStorageService.DeleteFolder("delete", id, false, true, true)
.FirstOrDefault();
2022-04-13 13:01:50 +00:00
return await _fileOperationDtoHelper.GetAsync(operationResult);
2022-04-13 13:01:50 +00:00
}
2022-04-15 14:22:44 +00:00
[Update("rooms/{id}/archive")]
public async Task<FileOperationDto> ArchiveRoomAsync(T id)
2022-04-15 14:22:44 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
2022-04-15 14:22:44 +00:00
var destFolder = JsonSerializer.SerializeToElement(await _globalFolderHelper.FolderArchiveAsync);
var movableRoom = JsonSerializer.SerializeToElement(id);
2022-04-15 14:22:44 +00:00
var operationResult = _fileStorageService.MoveOrCopyItems(new List<JsonElement> { movableRoom }, new List<JsonElement>(), destFolder, FileConflictResolveType.Skip, false, true)
.FirstOrDefault();
2022-04-15 14:22:44 +00:00
return await _fileOperationDtoHelper.GetAsync(operationResult);
2022-04-15 14:22:44 +00:00
}
[Update("rooms/{id}/unarchive")]
public async Task<FileOperationDto> UnarchiveRoomAsync(T id)
2022-04-15 14:22:44 +00:00
{
2022-04-20 08:26:31 +00:00
ErrorIfNotDocSpace();
2022-04-15 14:22:44 +00:00
var destFolder = JsonSerializer.SerializeToElement(await _globalFolderHelper.FolderVirtualRoomsAsync);
var movableRoom = JsonSerializer.SerializeToElement(id);
2022-04-15 14:22:44 +00:00
var operationResult = _fileStorageService.MoveOrCopyItems(new List<JsonElement> { movableRoom }, new List<JsonElement>(), destFolder, FileConflictResolveType.Skip, false, true)
.FirstOrDefault();
2022-04-15 14:22:44 +00:00
return await _fileOperationDtoHelper.GetAsync(operationResult);
2022-04-15 14:22:44 +00:00
}
2022-04-20 08:26:31 +00:00
[Update("rooms/{id}/share")]
public Task<IEnumerable<FileShareDto>> SetRoomSecurityAsync(T id, [FromBody] SecurityInfoRequestDto inDto)
{
ErrorIfNotDocSpace();
return _securityControllerHelper.SetFolderSecurityInfoAsync(id, inDto.Share, inDto.Notify, inDto.SharingMessage);
}
2022-04-20 08:26:31 +00:00
private void ErrorIfNotDocSpace()
{
if (!_coreBaseSettings.DocSpace)
{
throw new NotSupportedException();
}
}
2022-04-10 12:30:46 +00:00
}