diff --git a/bitwarden_license/src/Scim/Models/ScimUserRequestModel.cs b/bitwarden_license/src/Scim/Models/ScimUserRequestModel.cs index d22c21144d..80d6c1b044 100644 --- a/bitwarden_license/src/Scim/Models/ScimUserRequestModel.cs +++ b/bitwarden_license/src/Scim/Models/ScimUserRequestModel.cs @@ -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()); diff --git a/bitwarden_license/src/Scim/Users/PostUserCommand.cs b/bitwarden_license/src/Scim/Users/PostUserCommand.cs index d62de90d4f..57233b69e7 100644 --- a/bitwarden_license/src/Scim/Users/PostUserCommand.cs +++ b/bitwarden_license/src/Scim/Users/PostUserCommand.cs @@ -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); diff --git a/src/Core/AdminConsole/Models/Business/OrganizationDto.cs b/src/Core/AdminConsole/Models/Business/InviteOrganization.cs similarity index 80% rename from src/Core/AdminConsole/Models/Business/OrganizationDto.cs rename to src/Core/AdminConsole/Models/Business/InviteOrganization.cs index 14f2cfee32..f292b8c063 100644 --- a/src/Core/AdminConsole/Models/Business/OrganizationDto.cs +++ b/src/Core/AdminConsole/Models/Business/InviteOrganization.cs @@ -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)) { } } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs index 98e4357cb6..a086220069 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs @@ -59,13 +59,13 @@ public class InviteOrganizationUsersCommand(IEventService eventService, private async Task>> InviteOrganizationUsersAsync(InviteOrganizationUsersRequest request) { var existingEmails = new HashSet(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 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 }); diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteOrganizationUsersRequest.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteOrganizationUsersRequest.cs index e5ad432753..013ff1a0be 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteOrganizationUsersRequest.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteOrganizationUsersRequest.cs @@ -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) { } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteScimOrganizationUserRequest.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteScimOrganizationUserRequest.cs index 1fb690ed47..382a464630 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteScimOrganizationUserRequest.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteScimOrganizationUserRequest.cs @@ -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; } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteUserOrganizationValidationRequest.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteUserOrganizationValidationRequest.cs index 451c36e9b9..6b6bea35c2 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteUserOrganizationValidationRequest.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/InviteUserOrganizationValidationRequest.cs @@ -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; } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs index dea54e0c7a..76811d60f4 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteOrganizationUserValidation.cs @@ -28,7 +28,7 @@ public class InviteUsersValidation( return new Invalid(invalidEnvironment.ErrorMessageString); } - if (InvitingUserOrganizationValidation.Validate(request.Organization) is Invalid organizationValidation) + if (InvitingUserOrganizationValidation.Validate(request.InviteOrganization) is Invalid organizationValidation) { return new Invalid(organizationValidation.ErrorMessageString); } @@ -49,7 +49,7 @@ public class InviteUsersValidation( return new Invalid(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(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 invalidPaymentValidation) { return new Invalid(invalidPaymentValidation.ErrorMessageString); diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InvitingUserOrganizationValidation.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InvitingUserOrganizationValidation.cs index 9277741475..949c9b8ad0 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InvitingUserOrganizationValidation.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InvitingUserOrganizationValidation.cs @@ -5,23 +5,23 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUse public static class InvitingUserOrganizationValidation { - public static ValidationResult Validate(OrganizationDto organization) + public static ValidationResult Validate(InviteOrganization inviteOrganization) { - if (organization.Seats is null) + if (inviteOrganization.Seats is null) { - return new Valid(organization); + return new Valid(inviteOrganization); } - if (string.IsNullOrWhiteSpace(organization.GatewayCustomerId)) + if (string.IsNullOrWhiteSpace(inviteOrganization.GatewayCustomerId)) { - return new Invalid(NoPaymentMethodFoundError); + return new Invalid(NoPaymentMethodFoundError); } - if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId)) + if (string.IsNullOrWhiteSpace(inviteOrganization.GatewaySubscriptionId)) { - return new Invalid(NoSubscriptionFoundError); + return new Invalid(NoSubscriptionFoundError); } - return new Valid(organization); + return new Valid(inviteOrganization); } } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PasswordManagerSubscriptionUpdate.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PasswordManagerSubscriptionUpdate.cs index 838d9fb895..c5c0a4a501 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PasswordManagerSubscriptionUpdate.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PasswordManagerSubscriptionUpdate.cs @@ -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); } } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs index c4fd03031a..b9b5aa54b2 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/PaymentSubscriptionDto.cs @@ -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 }; } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/SecretsManagerSubscriptionUpdate.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/SecretsManagerSubscriptionUpdate.cs index 773585ea06..a8602af5cc 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/SecretsManagerSubscriptionUpdate.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/Models/SecretsManagerSubscriptionUpdate.cs @@ -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); } } diff --git a/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs b/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs index 0e260e73e6..f3c4605cf8 100644 --- a/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs +++ b/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs @@ -303,7 +303,7 @@ public class GroupsControllerPutTests // Arrange repositories sutProvider.GetDependency().GetManyUserIdsByIdAsync(group.Id).Returns(currentGroupUsers ?? []); - sutProvider.GetDependency().GetByIdWithCollectionsAsync(group.Id) + sutProvider.GetDependency().GetByIdWithCollectionsAsync(group.Id)! .Returns(new Tuple>(group, currentCollectionAccess ?? [])); if (savingUser != null) { diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Helpers/InviteUserOrganizationValidationRequestHelpers.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Helpers/InviteUserOrganizationValidationRequestHelpers.cs index 188bb93f52..a08cf8980f 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Helpers/InviteUserOrganizationValidationRequestHelpers.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Helpers/InviteUserOrganizationValidationRequestHelpers.cs @@ -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, diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs index d13b587134..9cefc3bd23 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs @@ -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>(result); - sutProvider.GetDependency() + await sutProvider.GetDependency() .DidNotReceiveWithAnyArgs() .AdjustSeatsAsync(Arg.Any(), Arg.Any(), Arg.Any()); - sutProvider.GetDependency() + await sutProvider.GetDependency() .DidNotReceiveWithAnyArgs() .SendInvitesAsync(Arg.Any()); - sutProvider.GetDependency() + await sutProvider.GetDependency() .DidNotReceiveWithAnyArgs() .UpdateSubscriptionAsync(Arg.Any()); } @@ -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 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>(result); - sutProvider.GetDependency() + await sutProvider.GetDependency() .Received(1) .CreateManyAsync(Arg.Is>(users => users.Any(user => user.OrganizationUser.Email == request.Email))); - sutProvider.GetDependency() + await sutProvider.GetDependency() .Received(1) .SendInvitesAsync(Arg.Is(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>(result); var failure = result as Failure; - Assert.Equal(errorMessage, failure.ErrorMessage); + Assert.Equal(errorMessage, failure!.ErrorMessage); - sutProvider.GetDependency() + await sutProvider.GetDependency() .DidNotReceive() .CreateManyAsync(Arg.Any>()); - sutProvider.GetDependency() + await sutProvider.GetDependency() .DidNotReceive() .SendInvitesAsync(Arg.Any()); } @@ -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>(result); - sutProvider.GetDependency() + Assert.NotNull(organizationDto.MaxAutoScaleSeats); + + await sutProvider.GetDependency() .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>(result); - sutProvider.GetDependency() + await sutProvider.GetDependency() .AdjustSeatsAsync(organization, organizationDto.Plan, passwordManagerUpdate.SeatsRequiredToAdd); - orgRepository.Received(1).ReplaceAsync(Arg.Is(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal)); + await orgRepository.Received(1).ReplaceAsync(Arg.Is(x => x.Seats == passwordManagerUpdate.UpdatedSeatTotal)); - sutProvider.GetDependency() + await sutProvider.GetDependency() .Received(1) .UpsertOrganizationAbilityAsync(Arg.Is(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>(result); - sutProvider.GetDependency() + await sutProvider.GetDependency() .Received(1) .UpdateSubscriptionAsync(Arg.Is(update => update.SmSeats == secretsManagerSubscriptionUpdate.UpdatedSeatTotal)); diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs index 4016c58446..c519821205 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs @@ -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>(result); + Assert.IsType>(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>(result); + Assert.IsType>(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>(result); + Assert.IsType>(result); Assert.Equal(InviteUserValidationErrorMessages.NoSubscriptionFoundError, result.ErrorMessageString); } } diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs index 871ae2af4b..0fc2a57b63 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs @@ -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>(result); diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs index ccb0b0325e..f0030f25e7 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs @@ -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); diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs index df3d6a4836..60efa88077 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs @@ -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,