1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

[EC-635] Extract organizationService.UpdateLicenseAsync to a command (#2408)

* move UpdateLicenseAsync from service to command
* create new SelfHostedOrganizationDetails view model and move license validation logic there
* move occupied seat count logic to database level
This commit is contained in:
Thomas Rittson
2023-02-24 07:54:19 +10:00
committed by GitHub
parent 7d0bba3a29
commit 4643f5960e
30 changed files with 967 additions and 239 deletions

View File

@ -1,9 +1,10 @@
using AutoMapper;
using Bit.Core.Enums;
using Bit.Core.Models.Data.Organizations;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Organization = Bit.Infrastructure.EntityFramework.Models.Organization;
namespace Bit.Infrastructure.EntityFramework.Repositories;
@ -139,4 +140,40 @@ public class OrganizationRepository : Repository<Core.Entities.Organization, Org
await dbContext.SaveChangesAsync();
}
}
public async Task<Core.Entities.Organization> GetByLicenseKeyAsync(string licenseKey)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var organization = await GetDbSet(dbContext)
.FirstOrDefaultAsync(o => o.LicenseKey == licenseKey);
return organization;
}
}
public async Task<SelfHostedOrganizationDetails> GetSelfHostedOrganizationDetailsById(Guid id)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var organization = await GetDbSet(dbContext).FindAsync(id);
if (organization == null)
{
return null;
}
var selfHostOrganization = Mapper.Map<SelfHostedOrganizationDetails>(organization);
selfHostOrganization.OccupiedSeatCount =
organization.OrganizationUsers.Count(ou => ou.Status >= OrganizationUserStatusType.Invited);
selfHostOrganization.CollectionCount = organization.Collections?.Count ?? 0;
selfHostOrganization.GroupCount = organization?.Groups.Count ?? 0;
selfHostOrganization.SsoConfig = organization.SsoConfigs.SingleOrDefault();
selfHostOrganization.ScimConnections = organization.Connections.Where(c => c.Type == OrganizationConnectionType.Scim);
return selfHostOrganization;
}
}
}