From c9357da3b03f40a0ccadde09a301c349ee80a47a Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Mon, 23 May 2022 12:25:33 +0300 Subject: [PATCH] Files: added deleting tags, fix --- .../RequestDto/DeleteTagsRequestDto.cs | 32 +++++++++++++++++++ .../Core/VirtualRooms/CustomTagsService.cs | 20 +++--------- .../Server/Api/VirtualRoomsController.cs | 18 ++++++++--- 3 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 products/ASC.Files/Core/ApiModels/RequestDto/DeleteTagsRequestDto.cs diff --git a/products/ASC.Files/Core/ApiModels/RequestDto/DeleteTagsRequestDto.cs b/products/ASC.Files/Core/ApiModels/RequestDto/DeleteTagsRequestDto.cs new file mode 100644 index 0000000000..55e08d7dc3 --- /dev/null +++ b/products/ASC.Files/Core/ApiModels/RequestDto/DeleteTagsRequestDto.cs @@ -0,0 +1,32 @@ +// (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.Core.ApiModels.RequestDto; + +public class DeleteTagsRequestDto +{ + public IEnumerable TagIds { get; set; } +} \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/VirtualRooms/CustomTagsService.cs b/products/ASC.Files/Core/Core/VirtualRooms/CustomTagsService.cs index 12784f3f8f..56e22cf9d2 100644 --- a/products/ASC.Files/Core/Core/VirtualRooms/CustomTagsService.cs +++ b/products/ASC.Files/Core/Core/VirtualRooms/CustomTagsService.cs @@ -47,7 +47,7 @@ public class CustomTagsService public async Task CreateTagAsync(string name) { - if (_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) + if (!_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) { throw new SecurityException("You do not have permission to create tags"); } @@ -71,9 +71,9 @@ public class CustomTagsService return await TagDao.SaveTagInfoAsync(tagInfo); } - public async IAsyncEnumerable DeleteTagsAsync(IEnumerable tagIds) + public async Task DeleteTagsAsync(IEnumerable tagIds) { - if (_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) + if (!_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) { throw new SecurityException("You do not have permission to remove tags"); } @@ -81,11 +81,6 @@ public class CustomTagsService var tagDao = TagDao; await tagDao.RemoveTagsAsync(tagIds); - - await foreach (var tag in GetTagsInfoAsync(string.Empty, TagType.Custom)) - { - yield return tag; - } } public async Task> AddRoomTagsAsync(T folderId, IEnumerable tagsIds) @@ -94,7 +89,7 @@ public class CustomTagsService if (!await _fileSecurity.CanEditRoomAsync(folder)) { - throw new SecurityException("You do not have rights to edit the room"); + throw new SecurityException("You do not have permission to edit the room"); } var tagDao = TagDao; @@ -110,16 +105,11 @@ public class CustomTagsService public async Task> DeleteRoomTagsAsync(T folderId, IEnumerable tagsIds) { - if (_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) - { - throw new SecurityException("You do not have permission to create tags"); - } - var folder = await FolderDao.GetFolderAsync(folderId); if (!await _fileSecurity.CanEditRoomAsync(folder)) { - throw new SecurityException("You do not have rights to edit the room"); + throw new SecurityException("You do not have permission to edit the room"); } var tagDao = TagDao; diff --git a/products/ASC.Files/Server/Api/VirtualRoomsController.cs b/products/ASC.Files/Server/Api/VirtualRoomsController.cs index cbe0181cfb..ce3448acf6 100644 --- a/products/ASC.Files/Server/Api/VirtualRoomsController.cs +++ b/products/ASC.Files/Server/Api/VirtualRoomsController.cs @@ -219,7 +219,7 @@ public abstract class VirtualRoomsController : ApiControllerBase } [Create("rooms/{id}/tags")] - public async Task> AddTags(T id, [FromBody] UpdateTagsRequestDto inDto) + public async Task> AddTagsAsync(T id, [FromBody] UpdateTagsRequestDto inDto) { ErrorIfNotDocSpace(); @@ -229,7 +229,7 @@ public abstract class VirtualRoomsController : ApiControllerBase } [Delete("rooms/{id}/tags")] - public async Task> DeleteTags(T id, [FromBody] UpdateTagsRequestDto inDto) + public async Task> DeleteTagsAsync(T id, [FromBody] UpdateTagsRequestDto inDto) { ErrorIfNotDocSpace(); @@ -238,15 +238,15 @@ public abstract class VirtualRoomsController : ApiControllerBase return await _folderDtoHelper.GetAsync(room); } - [Create("rooms/tags")] - public async Task CreateTag(CreateTagRequestDto inDto) + [Create("tags")] + public async Task CreateTagAsync([FromBody] CreateTagRequestDto inDto) { ErrorIfNotDocSpace(); return await _customTagsService.CreateTagAsync(inDto.Name); } - [Read("rooms/tags")] + [Read("tags")] public async IAsyncEnumerable GetTagsInfoAsync() { ErrorIfNotDocSpace(); @@ -259,6 +259,14 @@ public abstract class VirtualRoomsController : ApiControllerBase } } + [Delete("tags")] + public async Task DeleteTagsAsync([FromBody] DeleteTagsRequestDto inDto) + { + ErrorIfNotDocSpace(); + + await _customTagsService.DeleteTagsAsync(inDto.TagIds); + } + private void ErrorIfNotDocSpace() { if (_coreBaseSettings.DisableDocSpace)