mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 21:18:13 -05:00
Cleaned up return.
This commit is contained in:
parent
0565755e4e
commit
5b87fa629e
@ -70,23 +70,27 @@ public class PostUserCommand(
|
|||||||
|
|
||||||
if (featureService.IsEnabled(FeatureFlagKeys.ScimInviteUserOptimization))
|
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);
|
invite, externalId);
|
||||||
var orgUser = await organizationUserRepository.GetDetailsByIdAsync(invitedOrgUser.Id);
|
var orgUser = await organizationUserRepository.GetDetailsByIdAsync(invitedOrgUser.Id);
|
||||||
|
|
||||||
return orgUser;
|
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);
|
var plan = await pricingClient.GetPlan(organization.PlanType);
|
||||||
|
|
||||||
if (plan == null)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,24 +102,20 @@ public class PostUserCommand(
|
|||||||
|
|
||||||
var result = await inviteOrganizationUsersCommand.InviteScimOrganizationUserAsync(request);
|
var result = await inviteOrganizationUsersCommand.InviteScimOrganizationUserAsync(request);
|
||||||
|
|
||||||
if (result is Failure<ScimInviteOrganizationUsersResponse> failure)
|
var invitedUserId = result switch
|
||||||
{
|
{
|
||||||
if (failure.ErrorMessages.Count != 0)
|
Success<ScimInviteOrganizationUsersResponse> success => success.Value.InvitedUser.OrganizationId,
|
||||||
{
|
Failure<ScimInviteOrganizationUsersResponse> { ErrorMessage: InviteOrganizationUsersCommand.NoUsersToInvite } => (Guid?)null,
|
||||||
throw new BadRequestException(failure.ErrorMessage);
|
Failure<ScimInviteOrganizationUsersResponse> failure when failure.ErrorMessages.Count != 0 => throw new BadRequestException(failure.ErrorMessage),
|
||||||
|
_ => throw new InvalidOperationException()
|
||||||
|
};
|
||||||
|
|
||||||
|
var organizationUser = invitedUserId.HasValue
|
||||||
|
? await organizationUserRepository.GetDetailsByIdAsync(invitedUserId.Value)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return organizationUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result is not Success<ScimInviteOrganizationUsersResponse> successfulResponse)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var invitedUser = await organizationUserRepository.GetDetailsByIdAsync(successfulResponse.Value.InvitedUser.Id);
|
|
||||||
|
|
||||||
return invitedUser;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -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 IssueNotifyingOwnersOfSeatLimitReached = "Error encountered notifying organization owners of seat limit reached.";
|
||||||
public const string FailedToInviteUsers = "Failed to invite user(s).";
|
public const string FailedToInviteUsers = "Failed to invite user(s).";
|
||||||
public const string NoUsersToInvite = "No users to invite.";
|
public const string NoUsersToInvite = "No users to invite.";
|
||||||
|
public const string InvalidResultType = "Invalid result type.";
|
||||||
|
|
||||||
public async Task<CommandResult<ScimInviteOrganizationUsersResponse>> InviteScimOrganizationUserAsync(OrganizationUserSingleEmailInvite request)
|
public async Task<CommandResult<ScimInviteOrganizationUsersResponse>> InviteScimOrganizationUserAsync(OrganizationUserSingleEmailInvite request)
|
||||||
{
|
{
|
||||||
@ -62,7 +63,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
|||||||
});
|
});
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new Failure<ScimInviteOrganizationUsersResponse>("WAHT");
|
return new Failure<ScimInviteOrganizationUsersResponse>(InvalidResultType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user