// (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")] public class FoldersControllerInternal : FoldersController { public FoldersControllerInternal( EntryManager entryManager, FoldersControllerHelper foldersControllerHelper, FileStorageService fileStorageService, FileOperationDtoHelper fileOperationDtoHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(entryManager, foldersControllerHelper, fileStorageService, fileOperationDtoHelper, folderDtoHelper, fileDtoHelper) { } } public class FoldersControllerThirdparty : FoldersController { public FoldersControllerThirdparty( EntryManager entryManager, FoldersControllerHelper foldersControllerHelper, FileStorageService fileStorageService, FileOperationDtoHelper fileOperationDtoHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(entryManager, foldersControllerHelper, fileStorageService, fileOperationDtoHelper, folderDtoHelper, fileDtoHelper) { } } public abstract class FoldersController : ApiControllerBase { private readonly EntryManager _entryManager; private readonly FoldersControllerHelper _foldersControllerHelper; private readonly FileStorageService _fileStorageService; private readonly FileOperationDtoHelper _fileOperationDtoHelper; public FoldersController( EntryManager entryManager, FoldersControllerHelper foldersControllerHelper, FileStorageService fileStorageService, FileOperationDtoHelper fileOperationDtoHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(folderDtoHelper, fileDtoHelper) { _entryManager = entryManager; _foldersControllerHelper = foldersControllerHelper; _fileStorageService = fileStorageService; _fileOperationDtoHelper = fileOperationDtoHelper; } /// /// 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 [HttpPost("folder/{folderId}")] public Task> CreateFolderAsync(T folderId, CreateFolderRequestDto inDto) { return _foldersControllerHelper.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 [HttpDelete("folder/{folderId}")] public async IAsyncEnumerable DeleteFolder(T folderId, DeleteFolderDto model) { foreach (var e in _fileStorageService.DeleteFolder("delete", folderId, false, model.DeleteAfter, model.Immediately)) { yield return await _fileOperationDtoHelper.GetAsync(e); } } /// /// 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 [HttpGet("{folderId}", Order = 1)] public async Task> GetFolderAsync(T folderId, Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { var folder = await _foldersControllerHelper.GetFolderAsync(folderId, userIdOrGroupId, filterType, searchInContent, withsubfolders); return folder.NotFoundIfNull(); } /// /// Returns a detailed information about the folder with the ID specified in the request /// /// Folder information /// Folders /// Folder info [HttpGet("folder/{folderId}")] public Task> GetFolderInfoAsync(T folderId) { return _foldersControllerHelper.GetFolderInfoAsync(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [HttpGet("folder/{folderId}/path")] public async IAsyncEnumerable GetFolderPathAsync(T folderId) { var breadCrumbs = await _entryManager.GetBreadCrumbsAsync(folderId); foreach (var e in breadCrumbs) { yield return await GetFileEntryWrapperAsync(e); } } [HttpGet("{folderId}/subfolders")] public async IAsyncEnumerable GetFoldersAsync(T folderId) { var folders = await _fileStorageService.GetFoldersAsync(folderId); foreach (var folder in folders) { yield return await GetFileEntryWrapperAsync(folder); } } [HttpGet("{folderId}/news")] public async IAsyncEnumerable GetNewItemsAsync(T folderId) { var newItems = await _fileStorageService.GetNewItemsAsync(folderId); foreach (var e in newItems) { yield return await GetFileEntryWrapperAsync(e); } } /// /// Renames the selected folder to the new title specified in the request /// /// /// Rename folder /// /// Folders /// Folder ID /// New title /// Folder contents [HttpPut("folder/{folderId}")] public Task> RenameFolderAsync(T folderId, CreateFolderRequestDto inDto) { return _foldersControllerHelper.RenameFolderAsync(folderId, inDto.Title); } } public class FoldersControllerCommon : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; private readonly FoldersControllerHelper _foldersControllerHelperInt; private readonly FoldersControllerHelper _foldersControllerHelperString; public FoldersControllerCommon( GlobalFolderHelper globalFolderHelper, FoldersControllerHelper foldersControllerHelperInt, FoldersControllerHelper foldersControllerHelperString, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(folderDtoHelper, fileDtoHelper) { _globalFolderHelper = globalFolderHelper; _foldersControllerHelperInt = foldersControllerHelperInt; _foldersControllerHelperString = foldersControllerHelperString; } /// /// Returns the detailed list of files and folders located in the 'Common Documents' section /// /// /// Common folder /// /// Folders /// Common folder contents [HttpGet("@common")] public async Task> GetCommonFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderCommonAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of favorites files /// /// Section Favorite /// Folders /// Favorites contents [HttpGet("@favorites")] public async Task> GetFavoritesFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderFavoritesAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the current user 'My Documents' section /// /// /// My folder /// /// Folders /// My folder contents [HttpGet("@my")] public Task> GetMyFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(_globalFolderHelper.FolderMy, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [HttpGet("@privacy")] public async Task> GetPrivacyFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { if (PrivacyRoomSettings.IsAvailable()) { throw new System.Security.SecurityException(); } return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderPrivacyAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the current user 'Projects Documents' section /// /// /// Projects folder /// /// Folders /// Projects folder contents [HttpGet("@projects")] public async Task> GetProjectsFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperString.GetFolderAsync(await _globalFolderHelper.GetFolderProjectsAsync(), userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of recent files /// /// Section Recent /// Folders /// Recent contents [HttpGet("@recent")] public async Task> GetRecentFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderRecentAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [HttpGet("@root")] public async IAsyncEnumerable> GetRootFoldersAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? withsubfolders, bool? withoutTrash, bool? searchInContent, bool? withoutAdditionalFolder) { var foldersIds = _foldersControllerHelperInt.GetRootFoldersIdsAsync(withoutTrash ?? false, withoutAdditionalFolder ?? false); await foreach (var folder in foldersIds) { yield return await _foldersControllerHelperInt.GetFolderAsync(folder, userIdOrGroupId, filterType, searchInContent, withsubfolders); } } /// /// Returns the detailed list of files and folders located in the 'Shared with Me' section /// /// /// Shared folder /// /// Folders /// Shared folder contents [HttpGet("@share")] public async Task> GetShareFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderShareAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of templates files /// /// Section Template /// Folders /// Templates contents [HttpGet("@templates")] public async Task> GetTemplatesFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderTemplatesAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Recycle Bin' section /// /// /// Trash folder /// /// Folders /// Trash folder contents [HttpGet("@trash")] public Task> GetTrashFolderAsync(Guid? userIdOrGroupId, FilterType? filterType, bool? searchInContent, bool? withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(Convert.ToInt32(_globalFolderHelper.FolderTrash), userIdOrGroupId, filterType, searchInContent, withsubfolders); } }