1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Moved FromOrganization mapper method to a constructor

This commit is contained in:
jrmccannon 2025-03-05 15:04:50 -06:00
parent 611ad8c343
commit c7cc9527f4
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
7 changed files with 37 additions and 33 deletions

View File

@ -62,7 +62,7 @@ public class PostUserCommand(
return await InviteScimOrganizationUserAsync(model.ToRequest(
scimProvider: scimProvider,
hasSecretsManager: hasStandaloneSecretsManager,
organization: OrganizationDto.FromOrganization(organization),
organization: new OrganizationDto(organization),
performedAt: timeProvider.GetUtcNow()));
}

View File

@ -16,17 +16,21 @@ public record OrganizationDto
public string GatewaySubscriptionId { get; init; }
public bool UseSecretsManager { get; init; }
public static OrganizationDto FromOrganization(Organization organization) =>
new()
{
OrganizationId = organization.Id,
Seats = organization.Seats,
MaxAutoScaleSeats = organization.MaxAutoscaleSeats,
SmSeats = organization.SmSeats,
SmMaxAutoScaleSeats = organization.MaxAutoscaleSmSeats,
Plan = StaticStore.GetPlan(organization.PlanType),
GatewayCustomerId = organization.GatewayCustomerId,
GatewaySubscriptionId = organization.GatewaySubscriptionId,
UseSecretsManager = organization.UseSecretsManager
};
public OrganizationDto()
{
}
public OrganizationDto(Organization organization)
{
OrganizationId = organization.Id;
Seats = organization.Seats;
MaxAutoScaleSeats = organization.MaxAutoscaleSeats;
SmSeats = organization.SmSeats;
SmMaxAutoScaleSeats = organization.MaxAutoscaleSmSeats;
Plan = StaticStore.GetPlan(organization.PlanType);
GatewayCustomerId = organization.GatewayCustomerId;
GatewaySubscriptionId = organization.GatewaySubscriptionId;
UseSecretsManager = organization.UseSecretsManager;
}
}

View File

@ -38,7 +38,7 @@ public class InviteOrganizationUserCommandTests
// Arrange
user.Email = address.Address;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,
@ -86,7 +86,7 @@ public class InviteOrganizationUserCommandTests
// Arrange
user.Email = address.Address;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,
@ -139,7 +139,7 @@ public class InviteOrganizationUserCommandTests
user.Email = address.Address;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,
@ -194,7 +194,7 @@ public class InviteOrganizationUserCommandTests
organization.MaxAutoscaleSeats = 2;
ownerDetails.Type = OrganizationUserType.Owner;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,
@ -250,7 +250,7 @@ public class InviteOrganizationUserCommandTests
organization.MaxAutoscaleSeats = 2;
ownerDetails.Type = OrganizationUserType.Owner;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,
@ -313,7 +313,7 @@ public class InviteOrganizationUserCommandTests
organization.MaxAutoscaleSeats = 2;
ownerDetails.Type = OrganizationUserType.Owner;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var request = new InviteScimOrganizationUserRequest(user.Email,
true,

View File

@ -12,7 +12,7 @@ public class InviteUserOrganizationValidationTests
[BitAutoData]
public void Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization)
{
var result = InvitingUserOrganizationValidation.Validate(OrganizationDto.FromOrganization(organization));
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
Assert.IsType<Valid<OrganizationDto>>(result);
}
@ -24,7 +24,7 @@ public class InviteUserOrganizationValidationTests
{
organization.GatewayCustomerId = string.Empty;
var result = InvitingUserOrganizationValidation.Validate(OrganizationDto.FromOrganization(organization));
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
Assert.IsType<Invalid<OrganizationDto>>(result);
Assert.Equal(InviteUserValidationErrorMessages.NoPaymentMethodFoundError, result.ErrorMessageString);
@ -37,7 +37,7 @@ public class InviteUserOrganizationValidationTests
{
organization.GatewaySubscriptionId = string.Empty;
var result = InvitingUserOrganizationValidation.Validate(OrganizationDto.FromOrganization(organization));
var result = InvitingUserOrganizationValidation.Validate(new OrganizationDto(organization));
Assert.IsType<Invalid<OrganizationDto>>(result);
Assert.Equal(InviteUserValidationErrorMessages.NoSubscriptionFoundError, result.ErrorMessageString);

View File

@ -20,7 +20,7 @@ public class InviteUserPaymentValidationTests
var result = InviteUserPaymentValidation.Validate(new PaymentSubscriptionDto
{
SubscriptionStatus = StripeConstants.SubscriptionStatus.Active,
ProductTierType = OrganizationDto.FromOrganization(organization).Plan.ProductTier
ProductTierType = new OrganizationDto(organization).Plan.ProductTier
});
Assert.IsType<Valid<PaymentSubscriptionDto>>(result);

View File

@ -17,7 +17,7 @@ public class PasswordManagerInviteUserValidationTests
{
organization.Seats = null;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
@ -35,7 +35,7 @@ public class PasswordManagerInviteUserValidationTests
var seatsOccupiedByUsers = 4;
var additionalSeats = 4;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
@ -54,7 +54,7 @@ public class PasswordManagerInviteUserValidationTests
var seatsOccupiedByUsers = 4;
var additionalSeats = 1;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);
@ -73,7 +73,7 @@ public class PasswordManagerInviteUserValidationTests
var additionalSeats = 4;
organization.PlanType = PlanType.Free;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, seatsOccupiedByUsers, additionalSeats);

View File

@ -21,7 +21,7 @@ public class SecretsManagerInviteUserValidationTests
{
organization.UseSecretsManager = false;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
@ -48,7 +48,7 @@ public class SecretsManagerInviteUserValidationTests
{
organization.UseSecretsManager = false;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
var invite = OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true);
@ -79,7 +79,7 @@ public class SecretsManagerInviteUserValidationTests
organization.SmSeats = null;
organization.UseSecretsManager = true;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
@ -109,7 +109,7 @@ public class SecretsManagerInviteUserValidationTests
organization.UseSecretsManager = true;
organization.PlanType = PlanType.EnterpriseAnnually;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest
@ -140,7 +140,7 @@ public class SecretsManagerInviteUserValidationTests
organization.UseSecretsManager = true;
organization.PlanType = PlanType.EnterpriseAnnually;
var organizationDto = OrganizationDto.FromOrganization(organization);
var organizationDto = new OrganizationDto(organization);
var subscriptionUpdate = PasswordManagerSubscriptionUpdate.Create(organizationDto, 0, 0);
var request = new InviteUserOrganizationValidationRequest