Files: added api for resend room invintation

This commit is contained in:
Maksim Chegulov 2022-09-08 13:11:14 +03:00
parent 24c729078e
commit 47600daa03
3 changed files with 76 additions and 48 deletions

View File

@ -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<Guid> UsersIds { get; set; }
}

View File

@ -81,6 +81,8 @@ public class FileStorageService<T> //: 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<T> //: 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<T> //: IFileStorageService
_thumbnailSettings = thumbnailSettings;
_fileShareParamsHelper = fileShareParamsHelper;
_encryptionLoginProvider = encryptionLoginProvider;
_docSpaceLinksHelper = docSpaceLinksHelper;
_studioNotifyService = studioNotifyService;
}
public async Task<Folder<T>> GetFolderAsync(T folderId)
@ -3058,6 +3064,37 @@ public class FileStorageService<T> //: IFileStorageService
return fileIds;
}
public async Task ResendEmailInvitationsAsync(T id, IEnumerable<Guid> usersIds)
{
ArgumentNullException.ThrowIfNull(usersIds);
var folderDao = _daoFactory.GetFolderDao<T>();
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();

View File

@ -32,36 +32,26 @@ namespace ASC.Files.Api;
public class VirtualRoomsInternalController : VirtualRoomsController<int>
{
public VirtualRoomsInternalController(
FoldersControllerHelper<int> foldersControllerHelper,
GlobalFolderHelper globalFolderHelper,
FileOperationDtoHelper fileOperationDtoHelper,
SecurityControllerHelper<int> securityControllerHelper,
CoreBaseSettings coreBaseSettings,
AuthContext authContext,
DocSpaceLinksHelper docSpaceLinksService,
CustomTagsService<int> customTagsService,
RoomLogoManager roomLogoManager,
StudioNotifyService studioNotifyService,
FileStorageService<int> 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<int>
{
}
/// <summary>
/// Create a room in the virtual rooms section
/// </summary>
@ -99,36 +88,26 @@ public class VirtualRoomsInternalController : VirtualRoomsController<int>
public class VirtualRoomsThirdPartyController : VirtualRoomsController<string>
{
public VirtualRoomsThirdPartyController(
FoldersControllerHelper<string> foldersControllerHelper,
GlobalFolderHelper globalFolderHelper,
FileOperationDtoHelper fileOperationDtoHelper,
SecurityControllerHelper<string> securityControllerHelper,
CoreBaseSettings coreBaseSettings,
AuthContext authContext,
DocSpaceLinksHelper docSpaceLinksHelper,
CustomTagsService<string> customTagsService,
RoomLogoManager roomLogoManager,
StudioNotifyService studioNotifyService,
FileStorageService<string> 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<string>
public abstract class VirtualRoomsController<T> : ApiControllerBase
{
private readonly FoldersControllerHelper<T> _foldersControllerHelper;
private readonly GlobalFolderHelper _globalFolderHelper;
private readonly FileOperationDtoHelper _fileOperationDtoHelper;
private readonly SecurityControllerHelper<T> _securityControllerHelper;
private readonly CoreBaseSettings _coreBaseSettings;
private readonly AuthContext _authContext;
private readonly DocSpaceLinksHelper _docSpaceLinksHelper;
private readonly CustomTagsService<T> _customTagsService;
private readonly RoomLogoManager _roomLogoManager;
private readonly StudioNotifyService _studioNotifyService;
protected readonly FileStorageService<T> _fileStorageService;
private readonly FileSecurity _fileSecurity;
private readonly FileSecurityCommon _fileSecurityCommon;
private readonly EmailValidationKeyProvider _emailValidationKeyProvider;
private readonly FileShareDtoHelper _fileShareDtoHelper;
protected VirtualRoomsController(
FoldersControllerHelper<T> foldersControllerHelper,
GlobalFolderHelper globalFolderHelper,
FileOperationDtoHelper fileOperationDtoHelper,
SecurityControllerHelper<T> securityControllerHelper,
CoreBaseSettings coreBaseSettings,
AuthContext authContext,
DocSpaceLinksHelper docSpaceLinksHelper,
CustomTagsService<T> customTagsService,
RoomLogoManager roomLogoManager,
StudioNotifyService studioNotifyService,
FileStorageService<T> 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<T> : 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<T> : 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