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

Cleaned up return.

This commit is contained in:
jrmccannon 2025-03-19 12:15:16 -05:00
parent 0565755e4e
commit 5b87fa629e
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
2 changed files with 22 additions and 21 deletions

View File

@ -70,23 +70,27 @@ public class PostUserCommand(
if (featureService.IsEnabled(FeatureFlagKeys.ScimInviteUserOptimization))
{
return await InviteScimOrganizationUserAsync(model, organization, scimProvider, hasStandaloneSecretsManager);
return await InviteScimOrganizationUserAsync(model, organization, scimProvider,
hasStandaloneSecretsManager);
}
var invitedOrgUser = await organizationService.InviteUserAsync(organizationId, invitingUserId: null, EventSystemUser.SCIM,
var invitedOrgUser = await organizationService.InviteUserAsync(organizationId, invitingUserId: null,
EventSystemUser.SCIM,
invite, externalId);
var orgUser = await organizationUserRepository.GetDetailsByIdAsync(invitedOrgUser.Id);
return orgUser;
}
private async Task<OrganizationUserUserDetails?> InviteScimOrganizationUserAsync(ScimUserRequestModel model, Organization organization, ScimProviderType scimProvider, bool hasStandaloneSecretsManager)
private async Task<OrganizationUserUserDetails?> InviteScimOrganizationUserAsync(ScimUserRequestModel model,
Organization organization, ScimProviderType scimProvider, bool hasStandaloneSecretsManager)
{
var plan = await pricingClient.GetPlan(organization.PlanType);
if (plan == null)
{
logger.LogError("Plan {planType} not found for organization {organizationId}", organization.PlanType, organization.Id);
logger.LogError("Plan {planType} not found for organization {organizationId}", organization.PlanType,
organization.Id);
return null;
}
@ -98,24 +102,20 @@ public class PostUserCommand(
var result = await inviteOrganizationUsersCommand.InviteScimOrganizationUserAsync(request);
if (result is Failure<ScimInviteOrganizationUsersResponse> failure)
var invitedUserId = result switch
{
if (failure.ErrorMessages.Count != 0)
{
throw new BadRequestException(failure.ErrorMessage);
}
Success<ScimInviteOrganizationUsersResponse> success => success.Value.InvitedUser.OrganizationId,
Failure<ScimInviteOrganizationUsersResponse> { ErrorMessage: InviteOrganizationUsersCommand.NoUsersToInvite } => (Guid?)null,
Failure<ScimInviteOrganizationUsersResponse> failure when failure.ErrorMessages.Count != 0 => throw new BadRequestException(failure.ErrorMessage),
_ => throw new InvalidOperationException()
};
return null;
}
if (result is not Success<ScimInviteOrganizationUsersResponse> successfulResponse)
{
return null;
}
var invitedUser = await organizationUserRepository.GetDetailsByIdAsync(successfulResponse.Value.InvitedUser.Id);
return invitedUser;
var organizationUser = invitedUserId.HasValue
? await organizationUserRepository.GetDetailsByIdAsync(invitedUserId.Value)
: null;
return organizationUser;
}
}

View File

@ -37,6 +37,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
public const string IssueNotifyingOwnersOfSeatLimitReached = "Error encountered notifying organization owners of seat limit reached.";
public const string FailedToInviteUsers = "Failed to invite user(s).";
public const string NoUsersToInvite = "No users to invite.";
public const string InvalidResultType = "Invalid result type.";
public async Task<CommandResult<ScimInviteOrganizationUsersResponse>> InviteScimOrganizationUserAsync(OrganizationUserSingleEmailInvite request)
{
@ -62,7 +63,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
});
default:
return new Failure<ScimInviteOrganizationUsersResponse>("WAHT");
return new Failure<ScimInviteOrganizationUsersResponse>(InvalidResultType);
}
}