mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 09:32:48 -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:
@ -94,4 +94,44 @@ public class OrganizationRepository : Repository<Organization, Guid>, IOrganizat
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Organization> GetByLicenseKeyAsync(string licenseKey)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var result = await connection.QueryAsync<Organization>(
|
||||
"[dbo].[Organization_ReadByLicenseKey]",
|
||||
new { LicenseKey = licenseKey },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return result.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SelfHostedOrganizationDetails> GetSelfHostedOrganizationDetailsById(Guid id)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var result = await connection.QueryMultipleAsync(
|
||||
"[dbo].[Organization_ReadSelfHostedDetailsById]",
|
||||
new { Id = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var selfHostOrganization = await result.ReadSingleOrDefaultAsync<SelfHostedOrganizationDetails>();
|
||||
if (selfHostOrganization == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
selfHostOrganization.OccupiedSeatCount = await result.ReadSingleAsync<int>();
|
||||
selfHostOrganization.CollectionCount = await result.ReadSingleAsync<int>();
|
||||
selfHostOrganization.GroupCount = await result.ReadSingleAsync<int>();
|
||||
selfHostOrganization.OrganizationUsers = await result.ReadAsync<OrganizationUser>();
|
||||
selfHostOrganization.Policies = await result.ReadAsync<Policy>();
|
||||
selfHostOrganization.SsoConfig = await result.ReadFirstOrDefaultAsync<SsoConfig>();
|
||||
selfHostOrganization.ScimConnections = await result.ReadAsync<OrganizationConnection>();
|
||||
|
||||
return selfHostOrganization;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,19 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetOccupiedSeatCountByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var result = await connection.ExecuteScalarAsync<int>(
|
||||
"[dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId]",
|
||||
new { OrganizationId = organizationId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails,
|
||||
bool onlyRegisteredUsers)
|
||||
{
|
||||
|
Reference in New Issue
Block a user