Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-14461] Return ProfileOrganizationResponse from subscription update #5103

Merged
Merged
36 changes: 27 additions & 9 deletions src/Api/Billing/Controllers/OrganizationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

[HttpPost("{id}/sm-subscription")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PostSmSubscription(Guid id, [FromBody] SecretsManagerSubscriptionUpdateRequestModel model)
public async Task<ProfileOrganizationResponseModel> PostSmSubscription(Guid id, [FromBody] SecretsManagerSubscriptionUpdateRequestModel model)
{
if (!await currentContext.EditSubscription(id))
{
Expand All @@ -168,17 +168,26 @@
var organizationUpdate = model.ToSecretsManagerSubscriptionUpdate(organization);

await updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(organizationUpdate);

var userId = userService.GetProperUserId(User)!.Value;

Check warning on line 172 in src/Api/Billing/Controllers/OrganizationsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationsController.cs#L172

Added line #L172 was not covered by tests

return await GetProfileOrganizationResponseModelAsync(id, userId);

Check warning on line 174 in src/Api/Billing/Controllers/OrganizationsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationsController.cs#L174

Added line #L174 was not covered by tests
}

[HttpPost("{id:guid}/subscription")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PostSubscription(Guid id, [FromBody] OrganizationSubscriptionUpdateRequestModel model)
public async Task<ProfileOrganizationResponseModel> PostSubscription(Guid id, [FromBody] OrganizationSubscriptionUpdateRequestModel model)
{
if (!await currentContext.EditSubscription(id))
{
throw new NotFoundException();
}

await organizationService.UpdateSubscription(id, model.SeatAdjustment, model.MaxAutoscaleSeats);

var userId = userService.GetProperUserId(User)!.Value;

Check warning on line 188 in src/Api/Billing/Controllers/OrganizationsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationsController.cs#L188

Added line #L188 was not covered by tests

return await GetProfileOrganizationResponseModelAsync(id, userId);

Check warning on line 190 in src/Api/Billing/Controllers/OrganizationsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationsController.cs#L190

Added line #L190 was not covered by tests
}

[HttpPost("{id:guid}/subscribe-secrets-manager")]
Expand All @@ -203,13 +212,7 @@

await TryGrantOwnerAccessToSecretsManagerAsync(organization.Id, userId);

var organizationDetails = await organizationUserRepository.GetDetailsByUserAsync(userId, organization.Id,
OrganizationUserStatusType.Confirmed);

var organizationManagingActiveUser = await userService.GetOrganizationsManagingUserAsync(userId);
var organizationIdsManagingActiveUser = organizationManagingActiveUser.Select(o => o.Id);

return new ProfileOrganizationResponseModel(organizationDetails, organizationIdsManagingActiveUser);
return await GetProfileOrganizationResponseModelAsync(organization.Id, userId);
}

[HttpPost("{id:guid}/seat")]
Expand Down Expand Up @@ -391,4 +394,19 @@
await organizationInstallationRepository.ReplaceAsync(organizationInstallation);
}
}

private async Task<ProfileOrganizationResponseModel> GetProfileOrganizationResponseModelAsync(
Guid organizationId,
Guid userId)
{
var organizationUserDetails = await organizationUserRepository.GetDetailsByUserAsync(
userId,
organizationId,
OrganizationUserStatusType.Confirmed);

var organizationIdsManagingActiveUser = (await userService.GetOrganizationsManagingUserAsync(userId))
.Select(o => o.Id);

return new ProfileOrganizationResponseModel(organizationUserDetails, organizationIdsManagingActiveUser);
}
}
Loading