diff --git a/products/ASC.Files/Core/Core/VirtualRooms/InvitationService.cs b/products/ASC.Files/Core/Core/VirtualRooms/InvitationService.cs index f9f409872a..d361fb5a40 100644 --- a/products/ASC.Files/Core/Core/VirtualRooms/InvitationService.cs +++ b/products/ASC.Files/Core/Core/VirtualRooms/InvitationService.cs @@ -42,7 +42,8 @@ public class InvitationService( FilesMessageService filesMessageService, DisplayUserSettingsHelper displayUserSettingsHelper, IDistributedLockProvider distributedLockProvider, - UsersInRoomChecker usersInRoomChecker) + UsersInRoomChecker usersInRoomChecker, + EmailValidationKeyModelHelper validationHelper) { public string GetInvitationLink(Guid linkId, Guid createdBy) { @@ -64,7 +65,7 @@ public async Task ConfirmAsync(string key, string email, EmployeeTyp throw new SecurityException(); } - var data = await GetLinkDataAsync(key, email, employeeType, userId); + var data = await GetLinkDataAsync(key, email, null, employeeType, userId); var validation = new Validation { Result = data.Result }; if (data.Result is EmailValidationKeyProvider.ValidationResult.Invalid or EmailValidationKeyProvider.ValidationResult.Expired) @@ -192,8 +193,26 @@ await filesMessageService.SendAsync(MessageAction.RoomCreateUser, entryString, c return validation; } - public async Task GetLinkDataAsync(string key, string email, EmployeeType employeeType = EmployeeType.All, Guid? userId = default) + public async Task GetLinkDataAsync(string key, string email, ConfirmType? confirmType, EmployeeType employeeType = EmployeeType.All, Guid? userId = default) { + if (confirmType is ConfirmType.EmpInvite) + { + return new InvitationLinkData + { + Result = await validationHelper.ValidateAsync(new EmailValidationKeyModel + { + Key = key, + Email = email, + Type = ConfirmType.EmpInvite, + EmplType = employeeType, + UiD = userId + }), + ConfirmType = confirmType, + EmployeeType = employeeType, + LinkType = InvitationLinkType.Individual + }; + } + var result = await invitationValidator.ValidateAsync(key, email, employeeType, userId); var data = new InvitationLinkData { diff --git a/products/ASC.People/Server/Api/ThirdpartyController.cs b/products/ASC.People/Server/Api/ThirdpartyController.cs index 1d9013f125..3b0355c067 100644 --- a/products/ASC.People/Server/Api/ThirdpartyController.cs +++ b/products/ASC.People/Server/Api/ThirdpartyController.cs @@ -186,7 +186,7 @@ public async Task SignupAccountAsync(SignupAccountRequestDto inDto) } var model = emailValidationKeyModelHelper.GetModel(); - var linkData = await invitationService.GetLinkDataAsync(inDto.Key, inDto.Email, inDto.EmployeeType ?? EmployeeType.RoomAdmin, model?.UiD); + var linkData = await invitationService.GetLinkDataAsync(inDto.Key, inDto.Email, null, inDto.EmployeeType ?? EmployeeType.RoomAdmin, model?.UiD); if (!linkData.IsCorrect) { diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index bba05434d0..efc4933a75 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -171,7 +171,7 @@ public async Task AddMember(MemberRequestDto inDto) { await _apiContext.AuthByClaimAsync(); var model = emailValidationKeyModelHelper.GetModel(); - var linkData = inDto.FromInviteLink ? await invitationService.GetLinkDataAsync(inDto.Key, inDto.Email, inDto.Type, model?.UiD) : null; + var linkData = inDto.FromInviteLink ? await invitationService.GetLinkDataAsync(inDto.Key, inDto.Email, model.Type, inDto.Type, model?.UiD) : null; if (linkData is { IsCorrect: false }) { throw new SecurityException(FilesCommonResource.ErrorMessage_InvintationLink); @@ -190,8 +190,7 @@ public async Task AddMember(MemberRequestDto inDto) var user = new UserInfo(); - var byEmail = linkData?.LinkType == InvitationLinkType.Individual; - + var byEmail = linkData is { LinkType: InvitationLinkType.Individual, ConfirmType: not ConfirmType.EmpInvite }; if (byEmail) { user = await _userManager.GetUserByEmailAsync(inDto.Email); @@ -200,7 +199,10 @@ public async Task AddMember(MemberRequestDto inDto) { throw new SecurityException(FilesCommonResource.ErrorMessage_InvintationLink); } + } + if (byEmail || linkData?.ConfirmType is ConfirmType.EmpInvite) + { await userInvitationLimitHelper.IncreaseLimit(); } diff --git a/web/ASC.Web.Api/Api/Settings/MessageSettingsController.cs b/web/ASC.Web.Api/Api/Settings/MessageSettingsController.cs index cce56c2480..787e84ff97 100644 --- a/web/ASC.Web.Api/Api/Settings/MessageSettingsController.cs +++ b/web/ASC.Web.Api/Api/Settings/MessageSettingsController.cs @@ -226,7 +226,7 @@ public async Task SendJoinInviteMail(AdminMessageSettingsRequestsDto inD var address = new MailAddress(email); if (tenant.TrustedDomains.Any(d => address.Address.EndsWith("@" + d.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase))) { - await studioNotifyService.SendJoinMsgAsync(email, emplType, inDto.Culture); + await studioNotifyService.SendJoinMsgAsync(email, emplType, inDto.Culture, true); await messageService.SendAsync(MessageInitiator.System, MessageAction.SentInviteInstructions, email); return Resource.FinishInviteJoinEmailMessage; } @@ -235,7 +235,7 @@ public async Task SendJoinInviteMail(AdminMessageSettingsRequestsDto inD } case TenantTrustedDomainsType.All: { - await studioNotifyService.SendJoinMsgAsync(email, emplType, inDto.Culture); + await studioNotifyService.SendJoinMsgAsync(email, emplType, inDto.Culture, true); await messageService.SendAsync(MessageInitiator.System, MessageAction.SentInviteInstructions, email); return Resource.FinishInviteJoinEmailMessage; } diff --git a/web/ASC.Web.Core/Notify/StudioNotifyService.cs b/web/ASC.Web.Core/Notify/StudioNotifyService.cs index 16396f0adc..aaff7d3c41 100644 --- a/web/ASC.Web.Core/Notify/StudioNotifyService.cs +++ b/web/ASC.Web.Core/Notify/StudioNotifyService.cs @@ -308,7 +308,7 @@ public async ValueTask UserHasJoinAsync() await studioNotifyServiceHelper.SendNoticeAsync(Actions.UserHasJoin); } - public async Task SendJoinMsgAsync(string email, EmployeeType emplType, string culture) + public async Task SendJoinMsgAsync(string email, EmployeeType emplType, string culture, bool limitation = false) { var inviteUrl = await commonLinkUtility.GetConfirmationEmailUrlAsync(email, ConfirmType.EmpInvite, (int)emplType + "trust") + $"&emplType={(int)emplType}"; var shortLink = await urlShortener.GetShortenLinkAsync(inviteUrl); @@ -331,6 +331,11 @@ await studioNotifyServiceHelper.SendNoticeToAsync( await studioNotifyHelper.RecipientFromEmailAsync(email, false), [EMailSenderName], tags.ToArray()); + + if (limitation) + { + await userInvitationLimitHelper.ReduceLimit(); + } } public async Task UserInfoAddedAfterInviteAsync(UserInfo newUserInfo)