From 47600daa03ae4d1b6647631084d8cc129ab27212 Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Thu, 8 Sep 2022 13:11:14 +0300 Subject: [PATCH] Files: added api for resend room invintation --- .../RequestDto/UserInvintationRequestDto.cs | 32 +++++++++++ .../ASC.Files/Core/Core/FileStorageService.cs | 39 +++++++++++++- .../Server/Api/VirtualRoomsController.cs | 53 +++---------------- 3 files changed, 76 insertions(+), 48 deletions(-) create mode 100644 products/ASC.Files/Core/ApiModels/RequestDto/UserInvintationRequestDto.cs diff --git a/products/ASC.Files/Core/ApiModels/RequestDto/UserInvintationRequestDto.cs b/products/ASC.Files/Core/ApiModels/RequestDto/UserInvintationRequestDto.cs new file mode 100644 index 0000000000..6e82e60e56 --- /dev/null +++ b/products/ASC.Files/Core/ApiModels/RequestDto/UserInvintationRequestDto.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 UserInvintationRequestDto +{ + public IEnumerable UsersIds { get; set; } +} \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/FileStorageService.cs b/products/ASC.Files/Core/Core/FileStorageService.cs index 422a99fb04..bbc015d953 100644 --- a/products/ASC.Files/Core/Core/FileStorageService.cs +++ b/products/ASC.Files/Core/Core/FileStorageService.cs @@ -81,6 +81,8 @@ public class FileStorageService //: IFileStorageService private readonly ILogger _logger; private readonly FileShareParamsHelper _fileShareParamsHelper; private readonly EncryptionLoginProvider _encryptionLoginProvider; + private readonly DocSpaceLinksHelper _docSpaceLinksHelper; + private readonly StudioNotifyService _studioNotifyService; public FileStorageService( Global global, @@ -132,7 +134,9 @@ public class FileStorageService //: IFileStorageService ThirdPartySelector thirdPartySelector, ThumbnailSettings thumbnailSettings, FileShareParamsHelper fileShareParamsHelper, - EncryptionLoginProvider encryptionLoginProvider) + EncryptionLoginProvider encryptionLoginProvider, + DocSpaceLinksHelper docSpaceLinksHelper, + StudioNotifyService studioNotifyService) { _global = global; _globalStore = globalStore; @@ -184,6 +188,8 @@ public class FileStorageService //: IFileStorageService _thumbnailSettings = thumbnailSettings; _fileShareParamsHelper = fileShareParamsHelper; _encryptionLoginProvider = encryptionLoginProvider; + _docSpaceLinksHelper = docSpaceLinksHelper; + _studioNotifyService = studioNotifyService; } public async Task> GetFolderAsync(T folderId) @@ -3058,6 +3064,37 @@ public class FileStorageService //: IFileStorageService return fileIds; } + public async Task ResendEmailInvitationsAsync(T id, IEnumerable usersIds) + { + ArgumentNullException.ThrowIfNull(usersIds); + + var folderDao = _daoFactory.GetFolderDao(); + var room = await folderDao.GetFolderAsync(id); + + ErrorIf(room == null, FilesCommonResource.ErrorMassage_FolderNotFound); + ErrorIf(!await _fileSecurity.CanEditRoomAsync(room), FilesCommonResource.ErrorMassage_SecurityException); + + var shares = (await _fileSharing.GetSharedInfoAsync(room)).ToDictionary(k => k.SubjectId, v => v); + + foreach (var userId in usersIds) + { + if (!shares.TryGetValue(userId, out var share)) + { + continue; + } + + var user = _userManager.GetUser(share.SubjectId, null); + + if (user.ActivationStatus != EmployeeActivationStatus.Pending) + { + continue; + } + + var link = _docSpaceLinksHelper.GenerateInvitationRoomLink(user.Email, EmployeeType.User, _authContext.CurrentAccount.ID, user.Id); + _studioNotifyService.SendEmailRoomInvite(user.Email, link); + } + } + public string GetHelpCenter() { return string.Empty; //TODO: Studio.UserControls.Common.HelpCenter.HelpCenter.RenderControlToString(); diff --git a/products/ASC.Files/Server/Api/VirtualRoomsController.cs b/products/ASC.Files/Server/Api/VirtualRoomsController.cs index 94f966fb7e..fe9712bb70 100644 --- a/products/ASC.Files/Server/Api/VirtualRoomsController.cs +++ b/products/ASC.Files/Server/Api/VirtualRoomsController.cs @@ -32,36 +32,26 @@ namespace ASC.Files.Api; public class VirtualRoomsInternalController : VirtualRoomsController { public VirtualRoomsInternalController( - FoldersControllerHelper foldersControllerHelper, GlobalFolderHelper globalFolderHelper, FileOperationDtoHelper fileOperationDtoHelper, SecurityControllerHelper securityControllerHelper, CoreBaseSettings coreBaseSettings, AuthContext authContext, - DocSpaceLinksHelper docSpaceLinksService, CustomTagsService customTagsService, RoomLogoManager roomLogoManager, - StudioNotifyService studioNotifyService, FileStorageService fileStorageService, - FileSecurity fileSecurity, - FileSecurityCommon fileSecurityCommon, EmailValidationKeyProvider emailValidationKeyProvider, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper, FileShareDtoHelper fileShareDtoHelper) : base( - foldersControllerHelper, globalFolderHelper, fileOperationDtoHelper, securityControllerHelper, coreBaseSettings, authContext, - docSpaceLinksService, customTagsService, roomLogoManager, - studioNotifyService, fileStorageService, - fileSecurity, - fileSecurityCommon, emailValidationKeyProvider, folderDtoHelper, fileDtoHelper, @@ -69,7 +59,6 @@ public class VirtualRoomsInternalController : VirtualRoomsController { } - /// /// Create a room in the virtual rooms section /// @@ -99,36 +88,26 @@ public class VirtualRoomsInternalController : VirtualRoomsController public class VirtualRoomsThirdPartyController : VirtualRoomsController { public VirtualRoomsThirdPartyController( - FoldersControllerHelper foldersControllerHelper, GlobalFolderHelper globalFolderHelper, FileOperationDtoHelper fileOperationDtoHelper, SecurityControllerHelper securityControllerHelper, CoreBaseSettings coreBaseSettings, AuthContext authContext, - DocSpaceLinksHelper docSpaceLinksHelper, CustomTagsService customTagsService, RoomLogoManager roomLogoManager, - StudioNotifyService studioNotifyService, FileStorageService fileStorageService, - FileSecurity fileSecurity, - FileSecurityCommon fileSecurityCommon, EmailValidationKeyProvider emailValidationKeyProvider, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper, FileShareDtoHelper fileShareDtoHelper) : base( - foldersControllerHelper, globalFolderHelper, fileOperationDtoHelper, securityControllerHelper, coreBaseSettings, authContext, - docSpaceLinksHelper, customTagsService, roomLogoManager, - studioNotifyService, fileStorageService, - fileSecurity, - fileSecurityCommon, emailValidationKeyProvider, folderDtoHelper, fileDtoHelper, @@ -167,54 +146,39 @@ public class VirtualRoomsThirdPartyController : VirtualRoomsController public abstract class VirtualRoomsController : ApiControllerBase { - private readonly FoldersControllerHelper _foldersControllerHelper; private readonly GlobalFolderHelper _globalFolderHelper; private readonly FileOperationDtoHelper _fileOperationDtoHelper; private readonly SecurityControllerHelper _securityControllerHelper; private readonly CoreBaseSettings _coreBaseSettings; private readonly AuthContext _authContext; - private readonly DocSpaceLinksHelper _docSpaceLinksHelper; private readonly CustomTagsService _customTagsService; private readonly RoomLogoManager _roomLogoManager; - private readonly StudioNotifyService _studioNotifyService; protected readonly FileStorageService _fileStorageService; - private readonly FileSecurity _fileSecurity; - private readonly FileSecurityCommon _fileSecurityCommon; private readonly EmailValidationKeyProvider _emailValidationKeyProvider; private readonly FileShareDtoHelper _fileShareDtoHelper; protected VirtualRoomsController( - FoldersControllerHelper foldersControllerHelper, GlobalFolderHelper globalFolderHelper, FileOperationDtoHelper fileOperationDtoHelper, SecurityControllerHelper securityControllerHelper, CoreBaseSettings coreBaseSettings, AuthContext authContext, - DocSpaceLinksHelper docSpaceLinksHelper, CustomTagsService customTagsService, RoomLogoManager roomLogoManager, - StudioNotifyService studioNotifyService, FileStorageService fileStorageService, - FileSecurity fileSecurity, - FileSecurityCommon fileSecurityCommon, EmailValidationKeyProvider emailValidationKeyProvider, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper, FileShareDtoHelper fileShareDtoHelper) : base(folderDtoHelper, fileDtoHelper) { - _foldersControllerHelper = foldersControllerHelper; _globalFolderHelper = globalFolderHelper; _fileOperationDtoHelper = fileOperationDtoHelper; _securityControllerHelper = securityControllerHelper; _coreBaseSettings = coreBaseSettings; _authContext = authContext; - _docSpaceLinksHelper = docSpaceLinksHelper; _customTagsService = customTagsService; _roomLogoManager = roomLogoManager; - _studioNotifyService = studioNotifyService; _fileStorageService = fileStorageService; - _fileSecurity = fileSecurity; - _fileSecurityCommon = fileSecurityCommon; _emailValidationKeyProvider = emailValidationKeyProvider; _fileShareDtoHelper = fileShareDtoHelper; } @@ -560,6 +524,12 @@ public abstract class VirtualRoomsController : ApiControllerBase return await _folderDtoHelper.GetAsync(room); } + [HttpPost("rooms/{id}/resend")] + public async Task ResendEmailInvitationsAsync(T id, UserInvintationRequestDto inDto) + { + await _fileStorageService.ResendEmailInvitationsAsync(id, inDto.UsersIds); + } + protected void ErrorIfNotDocSpace() { if (_coreBaseSettings.DisableDocSpace) @@ -589,17 +559,6 @@ public abstract class VirtualRoomsController : ApiControllerBase yield return s; } } - - private async Task ErrorIfNotRights(T id, FileShare share) - { - var room = await _fileStorageService.GetFolderAsync(id); - - if ((share == FileShare.RoomManager && !_fileSecurityCommon.IsAdministrator(_authContext.CurrentAccount.ID)) - || !await _fileSecurity.CanEditRoomAsync(room)) - { - throw new InvalidOperationException("You don't have the rights to invite users to the room"); - } - } } public class VirtualRoomsCommonController : ApiControllerBase