namespace ASC.Files.Api; public class FoldersController : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; private readonly TenantManager _tenantManager; private readonly FoldersControllerHelper _foldersControllerHelperInt; private readonly FoldersControllerHelper _foldersControllerHelperString; public FoldersController( GlobalFolderHelper globalFolderHelper, TenantManager tenantManager, FoldersControllerHelper foldersControllerHelperInt, FoldersControllerHelper foldersControllerHelperString) { _globalFolderHelper = globalFolderHelper; _tenantManager = tenantManager; _foldersControllerHelperInt = foldersControllerHelperInt; _foldersControllerHelperString = foldersControllerHelperString; } /// /// Creates a new folder with the title sent in the request. The ID of a parent folder can be also specified. /// /// /// New folder /// /// Folders /// Parent folder ID /// Title of new folder /// New folder contents [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> CreateFolderFromBodyAsync(string folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelperString.CreateFolderAsync(folderId, inDto.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> CreateFolderFromBodyAsync(int folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelperInt.CreateFolderAsync(folderId, inDto.Title); } [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFolderFromFormAsync(string folderId, [FromForm] CreateFolderRequestDto inDto) { return _foldersControllerHelperString.CreateFolderAsync(folderId, inDto.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFolderFromFormAsync(int folderId, [FromForm] CreateFolderRequestDto inDto) { return _foldersControllerHelperInt.CreateFolderAsync(folderId, inDto.Title); } /// /// Deletes the folder with the ID specified in the request /// /// Delete folder /// Folders /// Folder ID /// Delete after finished /// Don't move to the Recycle Bin /// Operation result [Delete("folder/{folderId}", order: int.MaxValue - 1, DisableFormat = true)] public Task> DeleteFolder(string folderId, bool deleteAfter, bool immediately) { return _foldersControllerHelperString.DeleteFolder(folderId, deleteAfter, immediately); } [Delete("folder/{folderId:int}")] public Task> DeleteFolder(int folderId, bool deleteAfter, bool immediately) { return _foldersControllerHelperInt.DeleteFolder(folderId, deleteAfter, immediately); } /// /// Returns the detailed list of files and folders located in the 'Common Documents' section /// /// /// Common folder /// /// Folders /// Common folder contents [Read("@common")] public async Task> GetCommonFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderCommonAsync, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of favorites files /// /// Section Favorite /// Folders /// Favorites contents [Read("@favorites")] public async Task> GetFavoritesFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderFavoritesAsync, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of files and folders located in the folder with the ID specified in the request /// /// /// Folder by ID /// /// Folders /// Folder ID /// User or group ID /// Filter type /// Folder contents [Read("{folderId}", order: int.MaxValue, DisableFormat = true)] public async Task> GetFolderAsync(string folderId, Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { var folder = await _foldersControllerHelperString.GetFolderAsync(folderId, userIdOrGroupId, filterType, withsubfolders); return folder.NotFoundIfNull(); } [Read("{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> GetFolderAsync(int folderId, Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(folderId, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns a detailed information about the folder with the ID specified in the request /// /// Folder information /// Folders /// Folder info [Read("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> GetFolderInfoAsync(string folderId) { return _foldersControllerHelperString.GetFolderInfoAsync(folderId); } [Read("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> GetFolderInfoAsync(int folderId) { return _foldersControllerHelperInt.GetFolderInfoAsync(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [Read("folder/{folderId}/path")] public IAsyncEnumerable GetFolderPathAsync(string folderId) { return _foldersControllerHelperString.GetFolderPathAsync(folderId); } [Read("folder/{folderId:int}/path")] public IAsyncEnumerable GetFolderPathAsync(int folderId) { return _foldersControllerHelperInt.GetFolderPathAsync(folderId); } [Read("{folderId}/subfolders")] public IAsyncEnumerable GetFoldersAsync(string folderId) { return _foldersControllerHelperString.GetFoldersAsync(folderId); } [Read("{folderId:int}/subfolders")] public IAsyncEnumerable GetFoldersAsync(int folderId) { return _foldersControllerHelperInt.GetFoldersAsync(folderId); } /// /// Returns the detailed list of files and folders located in the current user 'My Documents' section /// /// /// My folder /// /// Folders /// My folder contents [Read("@my")] public Task> GetMyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(_globalFolderHelper.FolderMy, userIdOrGroupId, filterType, withsubfolders); } [Read("{folderId}/news")] public Task> GetNewItemsAsync(string folderId) { return _foldersControllerHelperString.GetNewItemsAsync(folderId); } [Read("{folderId:int}/news")] public Task> GetNewItemsAsync(int folderId) { return _foldersControllerHelperInt.GetNewItemsAsync(folderId); } [Read("@privacy")] public Task> GetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { if (PrivacyRoomSettings.IsAvailable(_tenantManager)) { throw new System.Security.SecurityException(); } return InternalGetPrivacyFolderAsync(userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of files and folders located in the current user 'Projects Documents' section /// /// /// Projects folder /// /// Folders /// Projects folder contents [Read("@projects")] public async Task> GetProjectsFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperString.GetFolderAsync(await _globalFolderHelper.GetFolderProjectsAsync(), userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of recent files /// /// Section Recent /// Folders /// Recent contents [Read("@recent")] public async Task> GetRecentFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderRecentAsync, userIdOrGroupId, filterType, withsubfolders); } [Read("@root")] public async Task>> GetRootFoldersAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders, bool withoutTrash, bool withoutAdditionalFolder) { var foldersIds = await _foldersControllerHelperInt.GetRootFoldersIdsAsync(withoutTrash, withoutAdditionalFolder); var result = new List>(); foreach (var folder in foldersIds) { result.Add(await _foldersControllerHelperInt.GetFolderAsync(folder, userIdOrGroupId, filterType, withsubfolders)); } return result; } /// /// Returns the detailed list of files and folders located in the 'Shared with Me' section /// /// /// Shared folder /// /// Folders /// Shared folder contents [Read("@share")] public async Task> GetShareFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderShareAsync, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of templates files /// /// Section Template /// Folders /// Templates contents [Read("@templates")] public async Task> GetTemplatesFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderTemplatesAsync, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Recycle Bin' section /// /// /// Trash folder /// /// Folders /// Trash folder contents [Read("@trash")] public Task> GetTrashFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(Convert.ToInt32(_globalFolderHelper.FolderTrash), userIdOrGroupId, filterType, withsubfolders); } /// /// Renames the selected folder to the new title specified in the request /// /// /// Rename folder /// /// Folders /// Folder ID /// New title /// Folder contents [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> RenameFolderFromBodyAsync(string folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelperString.RenameFolderAsync(folderId, inDto.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> RenameFolderFromBodyAsync(int folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelperInt.RenameFolderAsync(folderId, inDto.Title); } [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> RenameFolderFromFormAsync(string folderId, [FromForm] CreateFolderRequestDto inDto) { return _foldersControllerHelperString.RenameFolderAsync(folderId, inDto.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> RenameFolderFromFormAsync(int folderId, [FromForm] CreateFolderRequestDto inDto) { return _foldersControllerHelperInt.RenameFolderAsync(folderId, inDto.Title); } private async Task> InternalGetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderPrivacyAsync, userIdOrGroupId, filterType, withsubfolders); } }