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:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user