mirror of
https://github.com/bitwarden/server.git
synced 2025-04-22 21:45:15 -05:00
reference event changes and cleanup (#823)
This commit is contained in:
parent
a2b46daf59
commit
2742b414fd
@ -1,5 +1,6 @@
|
|||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
|
using Bit.Core.Models.Business;
|
||||||
using Bit.Core.Models.Table;
|
using Bit.Core.Models.Table;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
@ -34,6 +35,7 @@ namespace Bit.Billing.Controllers
|
|||||||
private readonly IMailService _mailService;
|
private readonly IMailService _mailService;
|
||||||
private readonly ILogger<StripeController> _logger;
|
private readonly ILogger<StripeController> _logger;
|
||||||
private readonly Braintree.BraintreeGateway _btGateway;
|
private readonly Braintree.BraintreeGateway _btGateway;
|
||||||
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
|
|
||||||
public StripeController(
|
public StripeController(
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
@ -45,6 +47,7 @@ namespace Bit.Billing.Controllers
|
|||||||
IUserService userService,
|
IUserService userService,
|
||||||
IAppleIapService appleIapService,
|
IAppleIapService appleIapService,
|
||||||
IMailService mailService,
|
IMailService mailService,
|
||||||
|
IReferenceEventService referenceEventService,
|
||||||
ILogger<StripeController> logger)
|
ILogger<StripeController> logger)
|
||||||
{
|
{
|
||||||
_billingSettings = billingSettings?.Value;
|
_billingSettings = billingSettings?.Value;
|
||||||
@ -55,6 +58,7 @@ namespace Bit.Billing.Controllers
|
|||||||
_userService = userService;
|
_userService = userService;
|
||||||
_appleIapService = appleIapService;
|
_appleIapService = appleIapService;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
|
_referenceEventService = referenceEventService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_btGateway = new Braintree.BraintreeGateway
|
_btGateway = new Braintree.BraintreeGateway
|
||||||
{
|
{
|
||||||
@ -382,6 +386,17 @@ namespace Bit.Billing.Controllers
|
|||||||
await _userService.EnablePremiumAsync(ids.Item2.Value, subscription.CurrentPeriodEnd);
|
await _userService.EnablePremiumAsync(ids.Item2.Value, subscription.CurrentPeriodEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ids.Item1.HasValue || ids.Item2.HasValue)
|
||||||
|
{
|
||||||
|
await _referenceEventService.RaiseEventAsync(
|
||||||
|
new ReferenceEvent(ReferenceEventType.Rebilled, null)
|
||||||
|
{
|
||||||
|
Id = ids.Item1 ?? ids.Item2 ?? default,
|
||||||
|
Source = ids.Item1.HasValue
|
||||||
|
? ReferenceEventSource.Organization
|
||||||
|
: ReferenceEventSource.User,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,11 @@ namespace Bit.Core.Enums
|
|||||||
ReinstateSubscription,
|
ReinstateSubscription,
|
||||||
[EnumMember(Value = "delete-account")]
|
[EnumMember(Value = "delete-account")]
|
||||||
DeleteAccount,
|
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 DateTime EventDate { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public int? Users { get; set; }
|
||||||
|
|
||||||
public bool? EndOfPeriod { get; set; }
|
public bool? EndOfPeriod { get; set; }
|
||||||
|
|
||||||
public string PlanName { get; set; }
|
public string PlanName { get; set; }
|
||||||
|
@ -949,6 +949,7 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
var orgUsers = new List<OrganizationUser>();
|
var orgUsers = new List<OrganizationUser>();
|
||||||
|
var orgUserInvitedCount = 0;
|
||||||
foreach (var email in emails)
|
foreach (var email in emails)
|
||||||
{
|
{
|
||||||
// Make sure user is not already invited
|
// Make sure user is not already invited
|
||||||
@ -982,10 +983,16 @@ namespace Bit.Core.Services
|
|||||||
await _organizationUserRepository.CreateAsync(orgUser);
|
await _organizationUserRepository.CreateAsync(orgUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SendInviteAsync(orgUser);
|
await SendInviteAsync(orgUser, organization);
|
||||||
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Invited);
|
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Invited);
|
||||||
orgUsers.Add(orgUser);
|
orgUsers.Add(orgUser);
|
||||||
|
orgUserInvitedCount++;
|
||||||
}
|
}
|
||||||
|
await _referenceEventService.RaiseEventAsync(
|
||||||
|
new ReferenceEvent(ReferenceEventType.InvitedUsers, organization)
|
||||||
|
{
|
||||||
|
Users = orgUserInvitedCount
|
||||||
|
});
|
||||||
|
|
||||||
return orgUsers;
|
return orgUsers;
|
||||||
}
|
}
|
||||||
@ -999,16 +1006,16 @@ namespace Bit.Core.Services
|
|||||||
throw new BadRequestException("User invalid.");
|
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 nowMillis = CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow);
|
||||||
var token = _dataProtector.Protect(
|
var token = _dataProtector.Protect(
|
||||||
$"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {nowMillis}");
|
$"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,
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user