Skip to content

Commit

Permalink
fix Bug 69663
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimChegulov committed Aug 16, 2024
1 parent ea24d9d commit e9a8f97
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
25 changes: 22 additions & 3 deletions products/ASC.Files/Core/Core/VirtualRooms/InvitationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -64,7 +65,7 @@ public async Task<Validation> 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)
Expand Down Expand Up @@ -192,8 +193,26 @@ await filesMessageService.SendAsync(MessageAction.RoomCreateUser, entryString, c
return validation;
}

public async Task<InvitationLinkData> GetLinkDataAsync(string key, string email, EmployeeType employeeType = EmployeeType.All, Guid? userId = default)
public async Task<InvitationLinkData> 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
{
Expand Down
2 changes: 1 addition & 1 deletion products/ASC.People/Server/Api/ThirdpartyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 5 additions & 3 deletions products/ASC.People/Server/Api/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task<EmployeeFullDto> 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);
Expand All @@ -190,8 +190,7 @@ public async Task<EmployeeFullDto> 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);
Expand All @@ -200,7 +199,10 @@ public async Task<EmployeeFullDto> AddMember(MemberRequestDto inDto)
{
throw new SecurityException(FilesCommonResource.ErrorMessage_InvintationLink);
}
}

if (byEmail || linkData?.ConfirmType is ConfirmType.EmpInvite)
{
await userInvitationLimitHelper.IncreaseLimit();
}

Expand Down
4 changes: 2 additions & 2 deletions web/ASC.Web.Api/Api/Settings/MessageSettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public async Task<object> 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;
}
Expand All @@ -235,7 +235,7 @@ public async Task<object> 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;
}
Expand Down
7 changes: 6 additions & 1 deletion web/ASC.Web.Core/Notify/StudioNotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit e9a8f97

Please sign in to comment.