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

QA-689/BEEEP-public-api-GET-subscription-details #5041

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Api/Billing/Public/Controllers/OrganizationController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
๏ปฟusing System.Net;
using Bit.Api.Billing.Public.Models;
using Bit.Api.Models.Public.Response;
using Bit.Core.Context;
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
Expand Down Expand Up @@ -35,6 +36,49 @@
_logger = logger;
}

/// <summary>
/// Retrieves the subscription details for the current organization.
/// </summary>
/// <returns>
/// Returns an object containing the subscription details if successful.
/// </returns>
[HttpGet("subscription")]
[SelfHosted(NotSelfHostedOnly = true)]
[ProducesResponseType(typeof(OrganizationSubscriptionDetailsResponseModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetSubscriptionAsync()
amorask-bitwarden marked this conversation as resolved.
Show resolved Hide resolved
{

Check warning on line 50 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L50

Added line #L50 was not covered by tests
try
{
var organizationId = _currentContext.OrganizationId.Value;
var organization = await _organizationRepository.GetByIdAsync(organizationId);

Check warning on line 54 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L52-L54

Added lines #L52 - L54 were not covered by tests

var subscriptionDetails = new OrganizationSubscriptionDetailsResponseModel
{
PasswordManager = new PasswordManagerSubscriptionDetails
{
Seats = organization.Seats,
MaxAutoScaleSeats = organization.MaxAutoscaleSeats,
Storage = organization.MaxStorageGb
},
SecretsManager = new SecretsManagerSubscriptionDetails
{
Seats = organization.SmSeats,
MaxAutoScaleSeats = organization.MaxAutoscaleSmSeats,
ServiceAccounts = organization.SmServiceAccounts,
MaxAutoScaleServiceAccounts = organization.MaxAutoscaleSmServiceAccounts
}
};

Check warning on line 71 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L56-L71

Added lines #L56 - L71 were not covered by tests

return Ok(subscriptionDetails);

Check warning on line 73 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L73

Added line #L73 was not covered by tests
}
catch (Exception ex)
{
_logger.LogError(ex, "Unhandled error while retrieving the subscription details");
return StatusCode(500, new { Message = "An error occurred while retrieving the subscription details." });

Check warning on line 78 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L75-L78

Added lines #L75 - L78 were not covered by tests
}
}

Check warning on line 80 in src/Api/Billing/Public/Controllers/OrganizationController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Controllers/OrganizationController.cs#L80

Added line #L80 was not covered by tests

/// <summary>
/// Update the organization's current subscription for Password Manager and/or Secrets Manager.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
๏ปฟusing System.ComponentModel.DataAnnotations;

namespace Bit.Api.Billing.Public.Models;

public class OrganizationSubscriptionDetailsResponseModel : IValidatableObject
{
public PasswordManagerSubscriptionDetails PasswordManager { get; set; }
public SecretsManagerSubscriptionDetails SecretsManager { get; set; }

Check warning on line 8 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L7-L8

Added lines #L7 - L8 were not covered by tests
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{

Check warning on line 10 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L10

Added line #L10 was not covered by tests
if (PasswordManager == null && SecretsManager == null)
{
yield return new ValidationResult("At least one of PasswordManager or SecretsManager must be provided.");
}

Check warning on line 14 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L12-L14

Added lines #L12 - L14 were not covered by tests

yield return ValidationResult.Success;
}

Check warning on line 17 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L16-L17

Added lines #L16 - L17 were not covered by tests
}
public class PasswordManagerSubscriptionDetails
{
public int? Seats { get; set; }
public int? MaxAutoScaleSeats { get; set; }
public short? Storage { get; set; }

Check warning on line 23 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L21-L23

Added lines #L21 - L23 were not covered by tests
}

public class SecretsManagerSubscriptionDetails
{
public int? Seats { get; set; }
public int? MaxAutoScaleSeats { get; set; }
public int? ServiceAccounts { get; set; }
public int? MaxAutoScaleServiceAccounts { get; set; }

Check warning on line 31 in src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Public/Models/Response/OrganizationSubscriptionDetailsResponseModel.cs#L28-L31

Added lines #L28 - L31 were not covered by tests
}
Loading