1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-08 06:28:14 -05:00

Split endpoints for FF 'AC-1607_present-user-offboarding-survey' (#3814)

This commit is contained in:
Alex Morask 2024-02-16 13:37:54 -05:00 committed by GitHub
parent d187487cb7
commit b866353d2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 60 deletions

View File

@ -464,20 +464,14 @@ public class OrganizationsController : Controller
await _organizationService.VerifyBankAsync(orgIdGuid, model.Amount1.Value, model.Amount2.Value); await _organizationService.VerifyBankAsync(orgIdGuid, model.Amount1.Value, model.Amount2.Value);
} }
[HttpPost("{id}/cancel")] [HttpPost("{id}/churn")]
[SelfHosted(NotSelfHostedOnly = true)] public async Task PostChurn(Guid id, [FromBody] SubscriptionCancellationRequestModel request)
public async Task PostCancel(Guid id, [FromBody] SubscriptionCancellationRequestModel request)
{ {
if (!await _currentContext.EditSubscription(id)) if (!await _currentContext.EditSubscription(id))
{ {
throw new NotFoundException(); throw new NotFoundException();
} }
var presentUserWithOffboardingSurvey =
_featureService.IsEnabled(FeatureFlagKeys.AC1607_PresentUsersWithOffboardingSurvey);
if (presentUserWithOffboardingSurvey)
{
var organization = await _organizationRepository.GetByIdAsync(id); var organization = await _organizationRepository.GetByIdAsync(id);
if (organization == null) if (organization == null)
@ -504,10 +498,18 @@ public class OrganizationsController : Controller
EndOfPeriod = organization.IsExpired() EndOfPeriod = organization.IsExpired()
}); });
} }
else
[HttpPost("{id}/cancel")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PostCancel(string id)
{ {
await _organizationService.CancelSubscriptionAsync(id); var orgIdGuid = new Guid(id);
if (!await _currentContext.EditSubscription(orgIdGuid))
{
throw new NotFoundException();
} }
await _organizationService.CancelSubscriptionAsync(orgIdGuid);
} }
[HttpPost("{id}/reinstate")] [HttpPost("{id}/reinstate")]

View File

@ -821,9 +821,8 @@ public class AccountsController : Controller
await _userService.UpdateLicenseAsync(user, license); await _userService.UpdateLicenseAsync(user, license);
} }
[HttpPost("cancel-premium")] [HttpPost("churn-premium")]
[SelfHosted(NotSelfHostedOnly = true)] public async Task PostChurn([FromBody] SubscriptionCancellationRequestModel request)
public async Task PostCancel([FromBody] SubscriptionCancellationRequestModel request)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
@ -832,11 +831,6 @@ public class AccountsController : Controller
throw new UnauthorizedAccessException(); throw new UnauthorizedAccessException();
} }
var presentUserWithOffboardingSurvey =
_featureService.IsEnabled(FeatureFlagKeys.AC1607_PresentUsersWithOffboardingSurvey);
if (presentUserWithOffboardingSurvey)
{
var subscription = await _getSubscriptionQuery.GetSubscription(user); var subscription = await _getSubscriptionQuery.GetSubscription(user);
await _cancelSubscriptionCommand.CancelSubscription(subscription, await _cancelSubscriptionCommand.CancelSubscription(subscription,
@ -856,10 +850,18 @@ public class AccountsController : Controller
EndOfPeriod = user.IsExpired() EndOfPeriod = user.IsExpired()
}); });
} }
else
[HttpPost("cancel-premium")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PostCancel()
{ {
await _userService.CancelPremiumAsync(user); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null)
{
throw new UnauthorizedAccessException();
} }
await _userService.CancelPremiumAsync(user);
} }
[HttpPost("reinstate-premium")] [HttpPost("reinstate-premium")]