// (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(FoldersControllerHelper foldersControllerHelper) : base(foldersControllerHelper) { } } public class FoldersControllerThirdparty : FoldersController { public FoldersControllerThirdparty(FoldersControllerHelper foldersControllerHelper) : base(foldersControllerHelper) { } } public abstract class FoldersController : ApiControllerBase { private readonly FoldersControllerHelper _foldersControllerHelper; public FoldersController(FoldersControllerHelper foldersControllerHelper) { _foldersControllerHelper = foldersControllerHelper; } /// /// 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(T folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelper.CreateFolderAsync(folderId, inDto.Title); } [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFolderFromFormAsync(T folderId, [FromForm] 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 [Delete("folder/{folderId}", order: int.MaxValue - 1, DisableFormat = true)] public Task> DeleteFolderFromBody(T folderId, [FromBody] DeleteFolderDto model) { return _foldersControllerHelper.DeleteFolder(folderId, model.DeleteAfter, model.Immediately); } [Delete("folder/{folderId}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> DeleteFolderFromForm(T folderId, [FromForm] DeleteFolderDto model) { return _foldersControllerHelper.DeleteFolder(folderId, model.DeleteAfter, model.Immediately); } /// /// 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(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 [Read("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> GetFolderInfoAsync(T folderId) { return _foldersControllerHelper.GetFolderInfoAsync(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [Read("folder/{folderId}/path")] public IAsyncEnumerable GetFolderPathAsync(T folderId) { return _foldersControllerHelper.GetFolderPathAsync(folderId); } [Read("{folderId}/subfolders")] public IAsyncEnumerable GetFoldersAsync(T folderId) { return _foldersControllerHelper.GetFoldersAsync(folderId); } [Read("{folderId}/news")] public Task> GetNewItemsAsync(T folderId) { return _foldersControllerHelper.GetNewItemsAsync(folderId); } /// /// 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(T folderId, [FromBody] CreateFolderRequestDto inDto) { return _foldersControllerHelper.RenameFolderAsync(folderId, inDto.Title); } [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> RenameFolderFromFormAsync(T folderId, [FromForm] CreateFolderRequestDto inDto) { return _foldersControllerHelper.RenameFolderAsync(folderId, inDto.Title); } } public class FoldersControllerCommon : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; private readonly TenantManager _tenantManager; private readonly FoldersControllerHelper _foldersControllerHelperInt; private readonly FoldersControllerHelper _foldersControllerHelperString; public FoldersControllerCommon( GlobalFolderHelper globalFolderHelper, TenantManager tenantManager, FoldersControllerHelper foldersControllerHelperInt, FoldersControllerHelper foldersControllerHelperString) { _globalFolderHelper = globalFolderHelper; _tenantManager = tenantManager; _foldersControllerHelperInt = foldersControllerHelperInt; _foldersControllerHelperString = foldersControllerHelperString; } /// /// 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 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 [Read("@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 [Read("@my")] public Task> GetMyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(_globalFolderHelper.FolderMy, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [Read("@privacy")] public async Task> GetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { if (PrivacyRoomSettings.IsAvailable(_tenantManager)) { 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 [Read("@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 [Read("@recent")] public async Task> GetRecentFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await _foldersControllerHelperInt.GetFolderAsync(await _globalFolderHelper.FolderRecentAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [Read("@root")] public async Task>> GetRootFoldersAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders, bool withoutTrash, bool searchInContent, 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, searchInContent, 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 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 [Read("@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 [Read("@trash")] public Task> GetTrashFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return _foldersControllerHelperInt.GetFolderAsync(Convert.ToInt32(_globalFolderHelper.FolderTrash), userIdOrGroupId, filterType, searchInContent, withsubfolders); } }