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

Fixed comment. Fixed multiple enumeration. Changed variable name.

This commit is contained in:
jrmccannon 2025-03-25 12:59:41 -05:00
parent 9b8a15193d
commit e6c3a56c0f
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
2 changed files with 12 additions and 10 deletions

View File

@ -7,7 +7,7 @@ public static class ErrorMapper
{ {
/// <summary> /// <summary>
/// Maps the Error<T> to a Bit.Exception class. /// Maps the ErrorT to a Bit.Exception class.
/// </summary> /// </summary>
/// <param name="error"></param> /// <param name="error"></param>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
@ -20,18 +20,18 @@ public static class ErrorMapper
}; };
/// <summary> /// <summary>
/// This maps the Error<T> object to the Bit.Exception class. /// This maps the ErrorT object to the Bit.Exception class.
/// ///
/// This should be replaced by an IActionResult mapper when possible. /// This should be replaced by an IActionResult mapper when possible.
/// </summary> /// </summary>
/// <param name="errors"></param> /// <param name="errors"></param>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <returns></returns> /// <returns></returns>
public static Exception MapToBitException<T>(IEnumerable<Error<T>> errors) => public static Exception MapToBitException<T>(ICollection<Error<T>> errors) =>
errors switch errors switch
{ {
not null when errors.Count() == 1 => MapToBitException(errors.First()), not null when errors.Count == 1 => MapToBitException(errors.First()),
not null when errors.Count() > 1 => new BadRequestException(string.Join(' ', errors.Select(e => e.Message))), not null when errors.Count > 1 => new BadRequestException(string.Join(' ', errors.Select(e => e.Message))),
_ => new BadRequestException() _ => new BadRequestException()
}; };
} }

View File

@ -115,7 +115,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
var validatedRequest = validationResult as Valid<InviteUserOrganizationValidationRequest>; var validatedRequest = validationResult as Valid<InviteUserOrganizationValidationRequest>;
var organizationUserCollection = invitesToSend var organizationUserToInviteEntities = invitesToSend
.Select(MapToDataModel(request.PerformedAt)) .Select(MapToDataModel(request.PerformedAt))
.ToArray(); .ToArray();
@ -123,7 +123,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
try try
{ {
await organizationUserRepository.CreateManyAsync(organizationUserCollection); await organizationUserRepository.CreateManyAsync(organizationUserToInviteEntities);
await AdjustPasswordManagerSeatsAsync(validatedRequest, organization); await AdjustPasswordManagerSeatsAsync(validatedRequest, organization);
@ -131,7 +131,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
await SendAdditionalEmailsAsync(validatedRequest, organization); await SendAdditionalEmailsAsync(validatedRequest, organization);
await SendInvitesAsync(organizationUserCollection, organization); await SendInvitesAsync(organizationUserToInviteEntities, organization);
await PublishReferenceEventAsync(validatedRequest, organization); await PublishReferenceEventAsync(validatedRequest, organization);
} }
@ -139,7 +139,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
{ {
logger.LogError(ex, FailedToInviteUsers); logger.LogError(ex, FailedToInviteUsers);
await organizationUserRepository.DeleteManyAsync(organizationUserCollection.Select(x => x.OrganizationUser.Id)); await organizationUserRepository.DeleteManyAsync(organizationUserToInviteEntities.Select(x => x.OrganizationUser.Id));
await RevertSecretsManagerChangesAsync(validatedRequest, organization); await RevertSecretsManagerChangesAsync(validatedRequest, organization);
@ -148,7 +148,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
return new Failure<IEnumerable<OrganizationUser>>(FailedToInviteUsers); return new Failure<IEnumerable<OrganizationUser>>(FailedToInviteUsers);
} }
return new Success<IEnumerable<OrganizationUser>>(organizationUserCollection.Select(x => x.OrganizationUser)); return new Success<IEnumerable<OrganizationUser>>(organizationUserToInviteEntities.Select(x => x.OrganizationUser));
} }
private async Task RevertPasswordManagerChangesAsync(Valid<InviteUserOrganizationValidationRequest> validatedResult, Organization organization) private async Task RevertPasswordManagerChangesAsync(Valid<InviteUserOrganizationValidationRequest> validatedResult, Organization organization)
@ -209,6 +209,8 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
try try
{ {
// TODO include provider org emails
var ownerEmails = (await organizationUserRepository var ownerEmails = (await organizationUserRepository
.GetManyByMinimumRoleAsync(validatedResult.Value.InviteOrganization.OrganizationId, OrganizationUserType.Owner)) .GetManyByMinimumRoleAsync(validatedResult.Value.InviteOrganization.OrganizationId, OrganizationUserType.Owner))
.Select(x => x.Email) .Select(x => x.Email)