mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
reference event changes and cleanup (#823)
This commit is contained in:
@ -18,5 +18,11 @@ namespace Bit.Core.Enums
|
||||
ReinstateSubscription,
|
||||
[EnumMember(Value = "delete-account")]
|
||||
DeleteAccount,
|
||||
[EnumMember(Value = "confirm-email")]
|
||||
ConfirmEmailAddress,
|
||||
[EnumMember(Value = "invited-users")]
|
||||
InvitedUsers,
|
||||
[EnumMember(Value = "rebilled")]
|
||||
Rebilled,
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public DateTime EventDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public int? Users { get; set; }
|
||||
|
||||
public bool? EndOfPeriod { get; set; }
|
||||
|
||||
public string PlanName { get; set; }
|
||||
|
@ -949,6 +949,7 @@ namespace Bit.Core.Services
|
||||
}
|
||||
|
||||
var orgUsers = new List<OrganizationUser>();
|
||||
var orgUserInvitedCount = 0;
|
||||
foreach (var email in emails)
|
||||
{
|
||||
// Make sure user is not already invited
|
||||
@ -982,10 +983,16 @@ namespace Bit.Core.Services
|
||||
await _organizationUserRepository.CreateAsync(orgUser);
|
||||
}
|
||||
|
||||
await SendInviteAsync(orgUser);
|
||||
await SendInviteAsync(orgUser, organization);
|
||||
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Invited);
|
||||
orgUsers.Add(orgUser);
|
||||
orgUserInvitedCount++;
|
||||
}
|
||||
await _referenceEventService.RaiseEventAsync(
|
||||
new ReferenceEvent(ReferenceEventType.InvitedUsers, organization)
|
||||
{
|
||||
Users = orgUserInvitedCount
|
||||
});
|
||||
|
||||
return orgUsers;
|
||||
}
|
||||
@ -999,16 +1006,16 @@ namespace Bit.Core.Services
|
||||
throw new BadRequestException("User invalid.");
|
||||
}
|
||||
|
||||
await SendInviteAsync(orgUser);
|
||||
var org = await GetOrgById(orgUser.OrganizationId);
|
||||
await SendInviteAsync(orgUser, org);
|
||||
}
|
||||
|
||||
private async Task SendInviteAsync(OrganizationUser orgUser)
|
||||
private async Task SendInviteAsync(OrganizationUser orgUser, Organization organization)
|
||||
{
|
||||
var org = await GetOrgById(orgUser.OrganizationId);
|
||||
var nowMillis = CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow);
|
||||
var token = _dataProtector.Protect(
|
||||
$"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {nowMillis}");
|
||||
await _mailService.SendOrganizationInviteEmailAsync(org.Name, orgUser, token);
|
||||
await _mailService.SendOrganizationInviteEmailAsync(organization.Name, orgUser, token);
|
||||
}
|
||||
|
||||
public async Task<OrganizationUser> AcceptUserAsync(Guid organizationUserId, User user, string token,
|
||||
|
@ -1135,5 +1135,16 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task<IdentityResult> ConfirmEmailAsync(User user, string token)
|
||||
{
|
||||
var result = await base.ConfirmEmailAsync(user, token);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
await _referenceEventService.RaiseEventAsync(
|
||||
new ReferenceEvent(ReferenceEventType.ConfirmEmailAddress, user));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user