mirror of
https://github.com/bitwarden/server
synced 2025-12-16 00:03:54 +00:00
[AC-1200] Admin Console code ownership - move OrganizationFeatures (#3369)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
||||
|
||||
public class CountNewSmSeatsRequiredQuery : ICountNewSmSeatsRequiredQuery
|
||||
{
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
|
||||
public CountNewSmSeatsRequiredQuery(IOrganizationUserRepository organizationUserRepository,
|
||||
IOrganizationRepository organizationRepository)
|
||||
{
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_organizationRepository = organizationRepository;
|
||||
}
|
||||
|
||||
public async Task<int> CountNewSmSeatsRequiredAsync(Guid organizationId, int usersToAdd)
|
||||
{
|
||||
if (usersToAdd == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||
if (organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!organization.UseSecretsManager)
|
||||
{
|
||||
throw new BadRequestException("Organization does not use Secrets Manager");
|
||||
}
|
||||
|
||||
if (!organization.SmSeats.HasValue || organization.SecretsManagerBeta)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var occupiedSmSeats =
|
||||
await _organizationUserRepository.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id);
|
||||
|
||||
var availableSmSeats = organization.SmSeats.Value - occupiedSmSeats;
|
||||
|
||||
if (availableSmSeats >= usersToAdd)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return usersToAdd - availableSmSeats;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user