mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
Rename of OrgDto
This commit is contained in:
parent
53168717fb
commit
56c7cc8bf4
@ -30,12 +30,12 @@ public class ScimUserRequestModel : BaseScimUserModel
|
||||
public InviteScimOrganizationUserRequest ToRequest(
|
||||
ScimProviderType scimProvider,
|
||||
bool hasSecretsManager,
|
||||
OrganizationDto organization,
|
||||
InviteOrganization inviteOrganization,
|
||||
DateTimeOffset performedAt) =>
|
||||
new(
|
||||
email: EmailForInvite(scimProvider),
|
||||
hasSecretsManager: hasSecretsManager,
|
||||
organization: organization,
|
||||
inviteOrganization: inviteOrganization,
|
||||
performedAt: performedAt,
|
||||
externalId: ExternalIdForInvite());
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class PostUserCommand(
|
||||
var request = model.ToRequest(
|
||||
scimProvider: scimProvider,
|
||||
hasSecretsManager: hasStandaloneSecretsManager,
|
||||
organization: new OrganizationDto(organization, plan),
|
||||
inviteOrganization: new InviteOrganization(organization, plan),
|
||||
performedAt: timeProvider.GetUtcNow());
|
||||
|
||||
var result = await inviteOrganizationUsersCommand.InviteScimOrganizationUserAsync(request);
|
||||
|
@ -4,7 +4,7 @@ using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.AdminConsole.Models.Business;
|
||||
|
||||
public record OrganizationDto
|
||||
public record InviteOrganization
|
||||
{
|
||||
public Guid OrganizationId { get; init; }
|
||||
public int? Seats { get; init; }
|
||||
@ -16,13 +16,13 @@ public record OrganizationDto
|
||||
public string GatewaySubscriptionId { get; init; }
|
||||
public bool UseSecretsManager { get; init; }
|
||||
|
||||
public OrganizationDto()
|
||||
public InviteOrganization()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public OrganizationDto(Organization organization, Plan plan)
|
||||
public InviteOrganization(Organization organization, Plan plan)
|
||||
{
|
||||
OrganizationId = organization.Id;
|
||||
Seats = organization.Seats;
|
||||
@ -35,7 +35,7 @@ public record OrganizationDto
|
||||
UseSecretsManager = organization.UseSecretsManager;
|
||||
}
|
||||
|
||||
public OrganizationDto(Organization organization) : this(organization, StaticStore.GetPlan(organization.PlanType))
|
||||
public InviteOrganization(Organization organization) : this(organization, StaticStore.GetPlan(organization.PlanType))
|
||||
{
|
||||
}
|
||||
}
|
@ -59,13 +59,13 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
private async Task<CommandResult<IEnumerable<OrganizationUser>>> InviteOrganizationUsersAsync(InviteOrganizationUsersRequest request)
|
||||
{
|
||||
var existingEmails = new HashSet<string>(await organizationUserRepository.SelectKnownEmailsAsync(
|
||||
request.Organization.OrganizationId, request.Invites.SelectMany(i => i.Emails), false),
|
||||
request.InviteOrganization.OrganizationId, request.Invites.SelectMany(i => i.Emails), false),
|
||||
StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
var invitesToSend = request.Invites
|
||||
.SelectMany(invite => invite.Emails
|
||||
.Where(email => !existingEmails.Contains(email))
|
||||
.Select(email => OrganizationUserInviteDto.Create(email, invite, request.Organization.OrganizationId))
|
||||
.Select(email => OrganizationUserInviteDto.Create(email, invite, request.InviteOrganization.OrganizationId))
|
||||
).ToArray();
|
||||
|
||||
if (invitesToSend.Length == 0)
|
||||
@ -76,11 +76,11 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
var validationResult = await inviteUsersValidation.ValidateAsync(new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = invitesToSend.ToArray(),
|
||||
Organization = request.Organization,
|
||||
InviteOrganization = request.InviteOrganization,
|
||||
PerformedBy = request.PerformedBy,
|
||||
PerformedAt = request.PerformedAt,
|
||||
OccupiedPmSeats = await organizationUserRepository.GetOccupiedSeatCountByOrganizationIdAsync(request.Organization.OrganizationId),
|
||||
OccupiedSmSeats = await organizationUserRepository.GetOccupiedSmSeatCountByOrganizationIdAsync(request.Organization.OrganizationId)
|
||||
OccupiedPmSeats = await organizationUserRepository.GetOccupiedSeatCountByOrganizationIdAsync(request.InviteOrganization.OrganizationId),
|
||||
OccupiedSmSeats = await organizationUserRepository.GetOccupiedSmSeatCountByOrganizationIdAsync(request.InviteOrganization.OrganizationId)
|
||||
});
|
||||
|
||||
if (validationResult is Invalid<InviteUserOrganizationValidationRequest> invalid)
|
||||
@ -94,7 +94,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
.Select(MapToDataModel(request.PerformedAt))
|
||||
.ToArray();
|
||||
|
||||
var organization = await organizationRepository.GetByIdAsync(validatedRequest!.Value.Organization.OrganizationId);
|
||||
var organization = await organizationRepository.GetByIdAsync(validatedRequest!.Value.InviteOrganization.OrganizationId);
|
||||
try
|
||||
{
|
||||
await organizationUserRepository.CreateManyAsync(organizationUserCollection);
|
||||
@ -129,7 +129,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
{
|
||||
if (valid.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd > 0)
|
||||
{
|
||||
await paymentService.AdjustSeatsAsync(organization, valid.Value.Organization.Plan, -valid.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
||||
await paymentService.AdjustSeatsAsync(organization, valid.Value.InviteOrganization.Plan, -valid.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
||||
|
||||
organization.Seats = (short?)valid.Value.PasswordManagerSubscriptionUpdate.Seats;
|
||||
|
||||
@ -142,7 +142,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
{
|
||||
if (valid.Value.SecretsManagerSubscriptionUpdate.SeatsRequiredToAdd < 0)
|
||||
{
|
||||
var updateRevert = new SecretsManagerSubscriptionUpdate(organization, valid.Value.Organization.Plan, false)
|
||||
var updateRevert = new SecretsManagerSubscriptionUpdate(organization, valid.Value.InviteOrganization.Plan, false)
|
||||
{
|
||||
SmSeats = valid.Value.SecretsManagerSubscriptionUpdate.Seats
|
||||
};
|
||||
@ -180,7 +180,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
try
|
||||
{
|
||||
var ownerEmails = (await organizationUserRepository
|
||||
.GetManyByMinimumRoleAsync(valid.Value.Organization.OrganizationId, OrganizationUserType.Owner))
|
||||
.GetManyByMinimumRoleAsync(valid.Value.InviteOrganization.OrganizationId, OrganizationUserType.Owner))
|
||||
.Select(x => x.Email)
|
||||
.Distinct();
|
||||
|
||||
@ -200,7 +200,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
return;
|
||||
}
|
||||
|
||||
var subscriptionUpdate = new SecretsManagerSubscriptionUpdate(organization, valid.Value.Organization.Plan, true)
|
||||
var subscriptionUpdate = new SecretsManagerSubscriptionUpdate(organization, valid.Value.InviteOrganization.Plan, true)
|
||||
.AdjustSeats(valid.Value.SecretsManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
||||
|
||||
await updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(subscriptionUpdate);
|
||||
@ -213,7 +213,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
return;
|
||||
}
|
||||
|
||||
await paymentService.AdjustSeatsAsync(organization, valid.Value.Organization.Plan, valid.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
||||
await paymentService.AdjustSeatsAsync(organization, valid.Value.InviteOrganization.Plan, valid.Value.PasswordManagerSubscriptionUpdate.SeatsRequiredToAdd);
|
||||
|
||||
organization.Seats = (short?)valid.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal;
|
||||
|
||||
@ -223,8 +223,8 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
||||
await referenceEventService.RaiseEventAsync(
|
||||
new ReferenceEvent(ReferenceEventType.AdjustSeats, organization, currentContext)
|
||||
{
|
||||
PlanName = valid.Value.Organization.Plan.Name,
|
||||
PlanType = valid.Value.Organization.Plan.Type,
|
||||
PlanName = valid.Value.InviteOrganization.Plan.Name,
|
||||
PlanType = valid.Value.InviteOrganization.Plan.Type,
|
||||
Seats = valid.Value.PasswordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
||||
PreviousSeats = valid.Value.PasswordManagerSubscriptionUpdate.Seats
|
||||
});
|
||||
|
@ -5,24 +5,24 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse
|
||||
public class InviteOrganizationUsersRequest
|
||||
{
|
||||
public OrganizationUserInvite[] Invites { get; } = [];
|
||||
public OrganizationDto Organization { get; }
|
||||
public InviteOrganization InviteOrganization { get; }
|
||||
public Guid PerformedBy { get; }
|
||||
public DateTimeOffset PerformedAt { get; }
|
||||
|
||||
public InviteOrganizationUsersRequest(OrganizationUserInvite[] invites,
|
||||
OrganizationDto organization,
|
||||
InviteOrganization inviteOrganization,
|
||||
Guid performedBy,
|
||||
DateTimeOffset performedAt)
|
||||
{
|
||||
Invites = invites;
|
||||
Organization = organization;
|
||||
InviteOrganization = inviteOrganization;
|
||||
PerformedBy = performedBy;
|
||||
PerformedAt = performedAt;
|
||||
}
|
||||
|
||||
public InviteOrganizationUsersRequest(InviteScimOrganizationUserRequest request) :
|
||||
this([OrganizationUserInvite.Create(request, request.ExternalId)],
|
||||
request.Organization,
|
||||
request.InviteOrganization,
|
||||
Guid.Empty,
|
||||
request.PerformedAt)
|
||||
{ }
|
||||
|
@ -6,13 +6,13 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse
|
||||
|
||||
public record InviteScimOrganizationUserRequest : OrganizationUserSingleEmailInvite
|
||||
{
|
||||
public OrganizationDto Organization { get; private init; }
|
||||
public InviteOrganization InviteOrganization { get; private init; }
|
||||
public DateTimeOffset PerformedAt { get; private init; }
|
||||
public string ExternalId { get; private init; } = string.Empty;
|
||||
|
||||
public InviteScimOrganizationUserRequest(string email,
|
||||
bool hasSecretsManager,
|
||||
OrganizationDto organization,
|
||||
InviteOrganization inviteOrganization,
|
||||
DateTimeOffset performedAt,
|
||||
string externalId) : base(
|
||||
email: email,
|
||||
@ -21,7 +21,7 @@ public record InviteScimOrganizationUserRequest : OrganizationUserSingleEmailInv
|
||||
permissions: new Permissions(),
|
||||
accessSecretsManager: hasSecretsManager)
|
||||
{
|
||||
Organization = organization;
|
||||
InviteOrganization = inviteOrganization;
|
||||
PerformedAt = performedAt;
|
||||
ExternalId = externalId;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class InviteUserOrganizationValidationRequest
|
||||
public InviteUserOrganizationValidationRequest(InviteUserOrganizationValidationRequest request, PasswordManagerSubscriptionUpdate subscriptionUpdate, SecretsManagerSubscriptionUpdate smSubscriptionUpdate)
|
||||
{
|
||||
Invites = request.Invites;
|
||||
Organization = request.Organization;
|
||||
InviteOrganization = request.InviteOrganization;
|
||||
PerformedBy = request.PerformedBy;
|
||||
PerformedAt = request.PerformedAt;
|
||||
OccupiedPmSeats = request.OccupiedPmSeats;
|
||||
@ -20,7 +20,7 @@ public class InviteUserOrganizationValidationRequest
|
||||
}
|
||||
|
||||
public OrganizationUserInviteDto[] Invites { get; init; } = [];
|
||||
public OrganizationDto Organization { get; init; }
|
||||
public InviteOrganization InviteOrganization { get; init; }
|
||||
public Guid PerformedBy { get; init; }
|
||||
public DateTimeOffset PerformedAt { get; init; }
|
||||
public int OccupiedPmSeats { get; init; }
|
||||
|
@ -28,7 +28,7 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidEnvironment.ErrorMessageString);
|
||||
}
|
||||
|
||||
if (InvitingUserOrganizationValidation.Validate(request.Organization) is Invalid<OrganizationDto> organizationValidation)
|
||||
if (InvitingUserOrganizationValidation.Validate(request.InviteOrganization) is Invalid<InviteOrganization> organizationValidation)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(organizationValidation.ErrorMessageString);
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidSmSubscriptionUpdate.ErrorMessageString);
|
||||
}
|
||||
|
||||
var provider = await providerRepository.GetByOrganizationIdAsync(request.Organization.OrganizationId);
|
||||
var provider = await providerRepository.GetByOrganizationIdAsync(request.InviteOrganization.OrganizationId);
|
||||
|
||||
if (provider is not null &&
|
||||
InvitingUserOrganizationProviderValidation.Validate(ProviderDto.FromProviderEntity(provider)) is
|
||||
@ -58,9 +58,9 @@ public class InviteUsersValidation(
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidProviderValidation.ErrorMessageString);
|
||||
}
|
||||
|
||||
var paymentSubscription = await paymentService.GetSubscriptionAsync(await organizationRepository.GetByIdAsync(request.Organization.OrganizationId));
|
||||
var paymentSubscription = await paymentService.GetSubscriptionAsync(await organizationRepository.GetByIdAsync(request.InviteOrganization.OrganizationId));
|
||||
|
||||
if (InviteUserPaymentValidation.Validate(PaymentSubscriptionDto.FromSubscriptionInfo(paymentSubscription, request.Organization)) is
|
||||
if (InviteUserPaymentValidation.Validate(PaymentSubscriptionDto.FromSubscriptionInfo(paymentSubscription, request.InviteOrganization)) is
|
||||
Invalid<PaymentSubscriptionDto> invalidPaymentValidation)
|
||||
{
|
||||
return new Invalid<InviteUserOrganizationValidationRequest>(invalidPaymentValidation.ErrorMessageString);
|
||||
|
@ -5,23 +5,23 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse
|
||||
|
||||
public static class InvitingUserOrganizationValidation
|
||||
{
|
||||
public static ValidationResult<OrganizationDto> Validate(OrganizationDto organization)
|
||||
public static ValidationResult<InviteOrganization> Validate(InviteOrganization inviteOrganization)
|
||||
{
|
||||
if (organization.Seats is null)
|
||||
if (inviteOrganization.Seats is null)
|
||||
{
|
||||
return new Valid<OrganizationDto>(organization);
|
||||
return new Valid<InviteOrganization>(inviteOrganization);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(organization.GatewayCustomerId))
|
||||
if (string.IsNullOrWhiteSpace(inviteOrganization.GatewayCustomerId))
|
||||
{
|
||||
return new Invalid<OrganizationDto>(NoPaymentMethodFoundError);
|
||||
return new Invalid<InviteOrganization>(NoPaymentMethodFoundError);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
|
||||
if (string.IsNullOrWhiteSpace(inviteOrganization.GatewaySubscriptionId))
|
||||
{
|
||||
return new Invalid<OrganizationDto>(NoSubscriptionFoundError);
|
||||
return new Invalid<InviteOrganization>(NoSubscriptionFoundError);
|
||||
}
|
||||
|
||||
return new Valid<OrganizationDto>(organization);
|
||||
return new Valid<InviteOrganization>(inviteOrganization);
|
||||
}
|
||||
}
|
||||
|
@ -40,23 +40,23 @@ public class PasswordManagerSubscriptionUpdate
|
||||
PasswordManagerPlan = plan;
|
||||
}
|
||||
|
||||
public static PasswordManagerSubscriptionUpdate Create(OrganizationDto organizationDto, int occupiedSeats, int seatsToAdd)
|
||||
public static PasswordManagerSubscriptionUpdate Create(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd)
|
||||
{
|
||||
return new PasswordManagerSubscriptionUpdate(
|
||||
organizationDto.Seats,
|
||||
organizationDto.MaxAutoScaleSeats,
|
||||
inviteOrganization.Seats,
|
||||
inviteOrganization.MaxAutoScaleSeats,
|
||||
occupiedSeats,
|
||||
seatsToAdd,
|
||||
organizationDto.Plan.PasswordManager);
|
||||
inviteOrganization.Plan.PasswordManager);
|
||||
}
|
||||
|
||||
public static PasswordManagerSubscriptionUpdate Create(InviteUserOrganizationValidationRequest validationRequest)
|
||||
{
|
||||
return new PasswordManagerSubscriptionUpdate(
|
||||
validationRequest.Organization.Seats,
|
||||
validationRequest.Organization.MaxAutoScaleSeats,
|
||||
validationRequest.InviteOrganization.Seats,
|
||||
validationRequest.InviteOrganization.MaxAutoScaleSeats,
|
||||
validationRequest.OccupiedPmSeats,
|
||||
validationRequest.Invites.Length,
|
||||
validationRequest.Organization.Plan.PasswordManager);
|
||||
validationRequest.InviteOrganization.Plan.PasswordManager);
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ public class PaymentSubscriptionDto
|
||||
public ProductTierType ProductTierType { get; init; }
|
||||
public string SubscriptionStatus { get; init; }
|
||||
|
||||
public static PaymentSubscriptionDto FromSubscriptionInfo(SubscriptionInfo subscriptionInfo, OrganizationDto organizationDto) =>
|
||||
public static PaymentSubscriptionDto FromSubscriptionInfo(SubscriptionInfo subscriptionInfo, InviteOrganization inviteOrganization) =>
|
||||
new()
|
||||
{
|
||||
SubscriptionStatus = subscriptionInfo?.Subscription?.Status ?? string.Empty,
|
||||
ProductTierType = organizationDto.Plan.ProductTier
|
||||
ProductTierType = inviteOrganization.Plan.ProductTier
|
||||
};
|
||||
}
|
||||
|
@ -34,25 +34,25 @@ public class SecretsManagerSubscriptionUpdate
|
||||
SecretsManagerPlan = plan;
|
||||
}
|
||||
|
||||
public static SecretsManagerSubscriptionUpdate Create(OrganizationDto organizationDto, int occupiedSeats, int seatsToAdd, int passwordManagerSeatTotal)
|
||||
public static SecretsManagerSubscriptionUpdate Create(InviteOrganization inviteOrganization, int occupiedSeats, int seatsToAdd, int passwordManagerSeatTotal)
|
||||
{
|
||||
return new SecretsManagerSubscriptionUpdate(organizationDto.UseSecretsManager,
|
||||
organizationDto.SmSeats,
|
||||
organizationDto.SmMaxAutoScaleSeats,
|
||||
return new SecretsManagerSubscriptionUpdate(inviteOrganization.UseSecretsManager,
|
||||
inviteOrganization.SmSeats,
|
||||
inviteOrganization.SmMaxAutoScaleSeats,
|
||||
occupiedSeats,
|
||||
seatsToAdd,
|
||||
passwordManagerSeatTotal,
|
||||
organizationDto.Plan.SecretsManager);
|
||||
inviteOrganization.Plan.SecretsManager);
|
||||
}
|
||||
|
||||
public static SecretsManagerSubscriptionUpdate Create(InviteUserOrganizationValidationRequest refined, PasswordManagerSubscriptionUpdate passwordManagerSubscriptionUpdate)
|
||||
{
|
||||
return new SecretsManagerSubscriptionUpdate(refined.Organization.UseSecretsManager,
|
||||
refined.Organization.SmSeats,
|
||||
refined.Organization.SmMaxAutoScaleSeats,
|
||||
return new SecretsManagerSubscriptionUpdate(refined.InviteOrganization.UseSecretsManager,
|
||||
refined.InviteOrganization.SmSeats,
|
||||
refined.InviteOrganization.SmMaxAutoScaleSeats,
|
||||
refined.OccupiedSmSeats,
|
||||
refined.Invites.Count(x => x.AccessSecretsManager),
|
||||
passwordManagerSubscriptionUpdate.UpdatedSeatTotal,
|
||||
refined.Organization.Plan.SecretsManager);
|
||||
refined.InviteOrganization.Plan.SecretsManager);
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ public class GroupsControllerPutTests
|
||||
|
||||
// Arrange repositories
|
||||
sutProvider.GetDependency<IGroupRepository>().GetManyUserIdsByIdAsync(group.Id).Returns(currentGroupUsers ?? []);
|
||||
sutProvider.GetDependency<IGroupRepository>().GetByIdWithCollectionsAsync(group.Id)
|
||||
sutProvider.GetDependency<IGroupRepository>().GetByIdWithCollectionsAsync(group.Id)!
|
||||
.Returns(new Tuple<Group, ICollection<CollectionAccessSelection>>(group, currentCollectionAccess ?? []));
|
||||
if (savingUser != null)
|
||||
{
|
||||
|
@ -7,28 +7,28 @@ namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers.Invi
|
||||
public static class InviteUserOrganizationValidationRequestHelpers
|
||||
{
|
||||
public static InviteUserOrganizationValidationRequest GetInviteValidationRequestMock(InviteScimOrganizationUserRequest request,
|
||||
OrganizationDto organizationDto) =>
|
||||
InviteOrganization inviteOrganization) =>
|
||||
new()
|
||||
{
|
||||
Invites =
|
||||
[
|
||||
OrganizationUserInviteDto.Create(request.Email,
|
||||
OrganizationUserInvite.Create(request, request.ExternalId), organizationDto.OrganizationId)
|
||||
OrganizationUserInvite.Create(request, request.ExternalId), inviteOrganization.OrganizationId)
|
||||
],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = inviteOrganization,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = request.PerformedAt,
|
||||
OccupiedPmSeats = 0,
|
||||
OccupiedSmSeats = 0,
|
||||
PasswordManagerSubscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0),
|
||||
SecretsManagerSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(organizationDto, 0, 0, 0)
|
||||
PasswordManagerSubscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(inviteOrganization, 0, 0),
|
||||
SecretsManagerSubscriptionUpdate = SecretsManagerSubscriptionUpdate.Create(inviteOrganization, 0, 0, 0)
|
||||
};
|
||||
|
||||
public static InviteUserOrganizationValidationRequest WithPasswordManagerUpdate(this InviteUserOrganizationValidationRequest request, PasswordManagerSubscriptionUpdate passwordManagerSubscriptionUpdate) =>
|
||||
new()
|
||||
{
|
||||
Invites = request.Invites,
|
||||
Organization = request.Organization,
|
||||
InviteOrganization = request.InviteOrganization,
|
||||
PerformedBy = request.PerformedBy,
|
||||
PerformedAt = request.PerformedAt,
|
||||
OccupiedPmSeats = request.OccupiedPmSeats,
|
||||
@ -41,7 +41,7 @@ public static class InviteUserOrganizationValidationRequestHelpers
|
||||
new()
|
||||
{
|
||||
Invites = request.Invites,
|
||||
Organization = request.Organization,
|
||||
InviteOrganization = request.InviteOrganization,
|
||||
PerformedBy = request.PerformedBy,
|
||||
PerformedAt = request.PerformedAt,
|
||||
OccupiedPmSeats = request.OccupiedPmSeats,
|
||||
|
@ -38,7 +38,7 @@ public class InviteOrganizationUserCommandTests
|
||||
// Arrange
|
||||
user.Email = address.Address;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
true,
|
||||
@ -60,15 +60,15 @@ public class InviteOrganizationUserCommandTests
|
||||
// Assert
|
||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||
|
||||
sutProvider.GetDependency<IPaymentService>()
|
||||
await sutProvider.GetDependency<IPaymentService>()
|
||||
.DidNotReceiveWithAnyArgs()
|
||||
.AdjustSeatsAsync(Arg.Any<Organization>(), Arg.Any<Plan>(), Arg.Any<int>());
|
||||
|
||||
sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
await sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
.DidNotReceiveWithAnyArgs()
|
||||
.SendInvitesAsync(Arg.Any<SendInvitesRequest>());
|
||||
|
||||
sutProvider.GetDependency<IUpdateSecretsManagerSubscriptionCommand>()
|
||||
await sutProvider.GetDependency<IUpdateSecretsManagerSubscriptionCommand>()
|
||||
.DidNotReceiveWithAnyArgs()
|
||||
.UpdateSubscriptionAsync(Arg.Any<Core.Models.Business.SecretsManagerSubscriptionUpdate>());
|
||||
}
|
||||
@ -78,17 +78,17 @@ public class InviteOrganizationUserCommandTests
|
||||
public async Task InviteScimOrganizationUserAsync_WhenEmailDoesNotExistAndRequestIsValid_ThenUserIsSavedAndInviteIsSent(
|
||||
MailAddress address,
|
||||
Organization organization,
|
||||
OrganizationUser user,
|
||||
OrganizationUser orgUser,
|
||||
FakeTimeProvider timeProvider,
|
||||
string externalId,
|
||||
SutProvider<InviteOrganizationUsersCommand> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
user.Email = address.Address;
|
||||
orgUser.Email = address.Address;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
var request = new InviteScimOrganizationUserRequest(orgUser.Email,
|
||||
true,
|
||||
organizationDto,
|
||||
timeProvider.GetUtcNow(),
|
||||
@ -112,16 +112,16 @@ public class InviteOrganizationUserCommandTests
|
||||
// Assert
|
||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||
|
||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||
.Received(1)
|
||||
.CreateManyAsync(Arg.Is<IEnumerable<CreateOrganizationUser>>(users =>
|
||||
users.Any(user => user.OrganizationUser.Email == request.Email)));
|
||||
|
||||
sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
await sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
.Received(1)
|
||||
.SendInvitesAsync(Arg.Is<SendInvitesRequest>(invite =>
|
||||
invite.Organization == organization &&
|
||||
invite.Users.Count(x => x.Email == user.Email) == 1));
|
||||
invite.Users.Count(x => x.Email == orgUser.Email) == 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@ -139,7 +139,7 @@ public class InviteOrganizationUserCommandTests
|
||||
|
||||
user.Email = address.Address;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
true,
|
||||
@ -166,13 +166,13 @@ public class InviteOrganizationUserCommandTests
|
||||
Assert.IsType<Failure<ScimInviteOrganizationUsersResponse>>(result);
|
||||
var failure = result as Failure<ScimInviteOrganizationUsersResponse>;
|
||||
|
||||
Assert.Equal(errorMessage, failure.ErrorMessage);
|
||||
Assert.Equal(errorMessage, failure!.ErrorMessage);
|
||||
|
||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||
.DidNotReceive()
|
||||
.CreateManyAsync(Arg.Any<IEnumerable<CreateOrganizationUser>>());
|
||||
|
||||
sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
await sutProvider.GetDependency<ISendOrganizationInvitesCommand>()
|
||||
.DidNotReceive()
|
||||
.SendInvitesAsync(Arg.Any<SendInvitesRequest>());
|
||||
}
|
||||
@ -194,7 +194,7 @@ public class InviteOrganizationUserCommandTests
|
||||
organization.MaxAutoscaleSeats = 2;
|
||||
ownerDetails.Type = OrganizationUserType.Owner;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
true,
|
||||
@ -226,7 +226,9 @@ public class InviteOrganizationUserCommandTests
|
||||
// Assert
|
||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||
|
||||
sutProvider.GetDependency<IMailService>()
|
||||
Assert.NotNull(organizationDto.MaxAutoScaleSeats);
|
||||
|
||||
await sutProvider.GetDependency<IMailService>()
|
||||
.Received(1)
|
||||
.SendOrganizationMaxSeatLimitReachedEmailAsync(organization,
|
||||
organizationDto.MaxAutoScaleSeats.Value,
|
||||
@ -250,7 +252,7 @@ public class InviteOrganizationUserCommandTests
|
||||
organization.MaxAutoscaleSeats = 2;
|
||||
ownerDetails.Type = OrganizationUserType.Owner;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
true,
|
||||
@ -285,12 +287,12 @@ public class InviteOrganizationUserCommandTests
|
||||
// Assert
|
||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||
|
||||
sutProvider.GetDependency<IPaymentService>()
|
||||
await sutProvider.GetDependency<IPaymentService>()
|
||||
.AdjustSeatsAsync(organization, organizationDto.Plan, passwordManagerUpdate.SeatsRequiredToAdd);
|
||||
|
||||
orgRepository.Received(1).ReplaceAsync(Arg.Is<Organization>(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal));
|
||||
await orgRepository.Received(1).ReplaceAsync(Arg.Is<Organization>(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal));
|
||||
|
||||
sutProvider.GetDependency<IApplicationCacheService>()
|
||||
await sutProvider.GetDependency<IApplicationCacheService>()
|
||||
.Received(1)
|
||||
.UpsertOrganizationAbilityAsync(Arg.Is<Organization>(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal));
|
||||
}
|
||||
@ -313,7 +315,7 @@ public class InviteOrganizationUserCommandTests
|
||||
organization.MaxAutoscaleSeats = 2;
|
||||
ownerDetails.Type = OrganizationUserType.Owner;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var request = new InviteScimOrganizationUserRequest(user.Email,
|
||||
true,
|
||||
@ -352,7 +354,7 @@ public class InviteOrganizationUserCommandTests
|
||||
// Assert
|
||||
Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result);
|
||||
|
||||
sutProvider.GetDependency<IUpdateSecretsManagerSubscriptionCommand>()
|
||||
await sutProvider.GetDependency<IUpdateSecretsManagerSubscriptionCommand>()
|
||||
.Received(1)
|
||||
.UpdateSubscriptionAsync(Arg.Is<Core.Models.Business.SecretsManagerSubscriptionUpdate>(update =>
|
||||
update.SmSeats == secretsManagerSubscriptionUpdate.UpdatedSeatTotal));
|
||||
|
@ -12,9 +12,9 @@ public class InviteUserOrganizationValidationTests
|
||||
[BitAutoData]
|
||||
public void Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization)
|
||||
{
|
||||
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
|
||||
var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization));
|
||||
|
||||
Assert.IsType<Valid<OrganizationDto>>(result);
|
||||
Assert.IsType<Valid<InviteOrganization>>(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@ -24,9 +24,9 @@ public class InviteUserOrganizationValidationTests
|
||||
{
|
||||
organization.GatewayCustomerId = string.Empty;
|
||||
|
||||
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
|
||||
var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization));
|
||||
|
||||
Assert.IsType<Invalid<OrganizationDto>>(result);
|
||||
Assert.IsType<Invalid<InviteOrganization>>(result);
|
||||
Assert.Equal(InviteUserValidationErrorMessages.NoPaymentMethodFoundError, result.ErrorMessageString);
|
||||
}
|
||||
|
||||
@ -37,9 +37,9 @@ public class InviteUserOrganizationValidationTests
|
||||
{
|
||||
organization.GatewaySubscriptionId = string.Empty;
|
||||
|
||||
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
|
||||
var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization));
|
||||
|
||||
Assert.IsType<Invalid<OrganizationDto>>(result);
|
||||
Assert.IsType<Invalid<InviteOrganization>>(result);
|
||||
Assert.Equal(InviteUserValidationErrorMessages.NoSubscriptionFoundError, result.ErrorMessageString);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class InviteUserPaymentValidationTests
|
||||
var result = InviteUserPaymentValidation.Validate(new PaymentSubscriptionDto
|
||||
{
|
||||
SubscriptionStatus = StripeConstants.SubscriptionStatus.Active,
|
||||
ProductTierType = new OrganizationDto(organization).Plan.ProductTier
|
||||
ProductTierType = new InviteOrganization(organization).Plan.ProductTier
|
||||
});
|
||||
|
||||
Assert.IsType<Valid<PaymentSubscriptionDto>>(result);
|
||||
|
@ -17,7 +17,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
{
|
||||
organization.Seats = null;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
@ -35,7 +35,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
var seatsOccupiedByUsers = 4;
|
||||
var additionalSeats = 4;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
@ -54,7 +54,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
var seatsOccupiedByUsers = 4;
|
||||
var additionalSeats = 1;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
@ -73,7 +73,7 @@ public class PasswordManagerInviteUserValidationTests
|
||||
var additionalSeats = 4;
|
||||
organization.PlanType = PlanType.Free;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
|
||||
|
||||
|
@ -21,13 +21,13 @@ public class SecretsManagerInviteUserValidationTests
|
||||
{
|
||||
organization.UseSecretsManager = false;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = [new OrganizationUserInviteDto()],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = organizationDto,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = default,
|
||||
OccupiedPmSeats = 0,
|
||||
@ -48,7 +48,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
{
|
||||
organization.UseSecretsManager = false;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
var invite = OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true);
|
||||
@ -56,7 +56,7 @@ public class SecretsManagerInviteUserValidationTests
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = [OrganizationUserInviteDto.Create(invite.Emails.First(), invite, organizationDto.OrganizationId)],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = organizationDto,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = default,
|
||||
OccupiedPmSeats = 0,
|
||||
@ -79,13 +79,13 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.SmSeats = null;
|
||||
organization.UseSecretsManager = true;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = [new OrganizationUserInviteDto()],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = organizationDto,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = default,
|
||||
OccupiedPmSeats = 0,
|
||||
@ -109,13 +109,13 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.UseSecretsManager = true;
|
||||
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = [OrganizationUserInviteDto.Create("email@test.com", OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true), organization.Id)],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = organizationDto,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = default,
|
||||
OccupiedPmSeats = 0,
|
||||
@ -140,13 +140,13 @@ public class SecretsManagerInviteUserValidationTests
|
||||
organization.UseSecretsManager = true;
|
||||
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||
|
||||
var organizationDto = new OrganizationDto(organization);
|
||||
var organizationDto = new InviteOrganization(organization);
|
||||
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
|
||||
|
||||
var request = new InviteUserOrganizationValidationRequest
|
||||
{
|
||||
Invites = [OrganizationUserInviteDto.Create("email@test.com", OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true), organization.Id)],
|
||||
Organization = organizationDto,
|
||||
InviteOrganization = organizationDto,
|
||||
PerformedBy = Guid.Empty,
|
||||
PerformedAt = default,
|
||||
OccupiedPmSeats = 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user