mirror of
https://github.com/bitwarden/server
synced 2026-01-02 16:43:25 +00:00
Merge branch 'master' into feature/billing-obfuscation
This commit is contained in:
@@ -38,6 +38,7 @@ public static class DapperServiceCollectionExtensions
|
||||
services.AddSingleton<ITaxRateRepository, TaxRateRepository>();
|
||||
services.AddSingleton<ITransactionRepository, TransactionRepository>();
|
||||
services.AddSingleton<IUserRepository, UserRepository>();
|
||||
services.AddSingleton<IOrganizationDomainRepository, OrganizationDomainRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Data;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data.Organizations;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
public class OrganizationDomainRepository : Repository<OrganizationDomain, Guid>, IOrganizationDomainRepository
|
||||
{
|
||||
public OrganizationDomainRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public OrganizationDomainRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<ICollection<OrganizationDomain>> GetClaimedDomainsByDomainNameAsync(string domainName)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationDomain>(
|
||||
$"[{Schema}].[OrganizationDomain_ReadByClaimedDomain]",
|
||||
new { DomainName = domainName },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<OrganizationDomain>> GetDomainsByOrganizationIdAsync(Guid orgId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationDomain>(
|
||||
$"[{Schema}].[OrganizationDomain_ReadByOrganizationId]",
|
||||
new { OrganizationId = orgId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<OrganizationDomain>> GetManyByNextRunDateAsync(DateTime date)
|
||||
{
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
var results = await connection.QueryAsync<OrganizationDomain>(
|
||||
$"[{Schema}].[OrganizationDomain_ReadByNextRunDate]",
|
||||
new { Date = date }, commandType: CommandType.StoredProcedure
|
||||
);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
public async Task<OrganizationDomainSsoDetailsData> GetOrganizationDomainSsoDetailsAsync(string email)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection
|
||||
.QueryAsync<OrganizationDomainSsoDetailsData>(
|
||||
$"[{Schema}].[OrganizationDomainSsoDetails_ReadByEmail]",
|
||||
new { Email = email },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationDomain> GetDomainByOrgIdAndDomainNameAsync(Guid orgId, string domainName)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection
|
||||
.QueryAsync<OrganizationDomain>(
|
||||
$"[{Schema}].[OrganizationDomain_ReadDomainByOrgIdAndDomainName]",
|
||||
new { OrganizationId = orgId, DomainName = domainName },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<OrganizationDomain>> GetExpiredOrganizationDomainsAsync()
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection
|
||||
.QueryAsync<OrganizationDomain>(
|
||||
$"[{Schema}].[OrganizationDomain_ReadIfExpired]",
|
||||
null,
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteExpiredAsync(int expirationPeriod)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
return await connection.ExecuteAsync(
|
||||
$"[{Schema}].[OrganizationDomain_DeleteIfExpired]",
|
||||
new { ExpirationPeriod = expirationPeriod },
|
||||
commandType: CommandType.StoredProcedure) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -42,4 +42,13 @@ public class ApiKeyRepository : Repository<ApiKey, Guid>, IApiKeyRepository
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
public async Task DeleteManyAsync(IEnumerable<ApiKey> objs)
|
||||
{
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
await connection.QueryAsync<ApiKey>(
|
||||
$"[{Schema}].[ApiKey_DeleteByIds]",
|
||||
new { Ids = objs.Select(obj => obj.Id).ToGuidIdArrayTVP() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@
|
||||
},
|
||||
"Azure.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.24.0",
|
||||
"contentHash": "+/qI1j2oU1S4/nvxb2k/wDsol00iGf1AyJX5g3epV7eOpQEP/2xcgh/cxgKMeFgn3U2fmgSiBnQZdkV+l5y0Uw==",
|
||||
"resolved": "1.25.0",
|
||||
"contentHash": "X8Dd4sAggS84KScWIjEbFAdt2U1KDolQopTPoHVubG2y3CM54f9l6asVrP5Uy384NWXjsspPYaJgz5xHc+KvTA==",
|
||||
"dependencies": {
|
||||
"Microsoft.Bcl.AsyncInterfaces": "1.1.1",
|
||||
"System.Diagnostics.DiagnosticSource": "4.6.0",
|
||||
@@ -89,28 +89,28 @@
|
||||
},
|
||||
"Azure.Storage.Blobs": {
|
||||
"type": "Transitive",
|
||||
"resolved": "12.11.0",
|
||||
"contentHash": "50eRjIhY7Q1JN7kT2MSawDKCcwSb7uRZUkz00P/BLjSg47gm2hxUYsnJPyvzCHntYMbOWzrvaVQTwYwXabaR5Q==",
|
||||
"resolved": "12.14.1",
|
||||
"contentHash": "DvRBWUDMB2LjdRbsBNtz/LiVIYk56hqzSooxx4uq4rCdLj2M+7Vvoa1r+W35Dz6ZXL6p+SNcgEae3oZ+CkPfow==",
|
||||
"dependencies": {
|
||||
"Azure.Storage.Common": "12.10.0",
|
||||
"Azure.Storage.Common": "12.13.0",
|
||||
"System.Text.Json": "4.7.2"
|
||||
}
|
||||
},
|
||||
"Azure.Storage.Common": {
|
||||
"type": "Transitive",
|
||||
"resolved": "12.10.0",
|
||||
"contentHash": "vYkHGzUkdZTace/cDPZLG+Mh/EoPqQuGxDIBOau9D+XWoDPmuUFGk325aXplkFE4JFGpSwoytNYzk/qBCaiHqg==",
|
||||
"resolved": "12.13.0",
|
||||
"contentHash": "jDv8xJWeZY2Er9zA6QO25BiGolxg87rItt9CwAp7L/V9EPJeaz8oJydaNL9Wj0+3ncceoMgdiyEv66OF8YUwWQ==",
|
||||
"dependencies": {
|
||||
"Azure.Core": "1.22.0",
|
||||
"Azure.Core": "1.25.0",
|
||||
"System.IO.Hashing": "6.0.0"
|
||||
}
|
||||
},
|
||||
"Azure.Storage.Queues": {
|
||||
"type": "Transitive",
|
||||
"resolved": "12.9.0",
|
||||
"contentHash": "jDiyHtsCUCrWNvZW7SjJnJb46UhpdgQrWCbL8aWpapDHlq9LvbvxYpfLh4dfKAz09QiTznLMIU3i+md9+7GzqQ==",
|
||||
"resolved": "12.12.0",
|
||||
"contentHash": "PwrfymLYFmmOt6A0vMiDVhBV7RoOAKftzzvrbSM3W9cJKpkxAg57AhM7/wbNb3P8Uq0B73lBurkFiFzWK9PXHg==",
|
||||
"dependencies": {
|
||||
"Azure.Storage.Common": "12.10.0",
|
||||
"Azure.Storage.Common": "12.13.0",
|
||||
"System.Memory.Data": "1.0.2",
|
||||
"System.Text.Json": "4.7.2"
|
||||
}
|
||||
@@ -132,6 +132,14 @@
|
||||
"System.Xml.XPath.XmlDocument": "4.3.0"
|
||||
}
|
||||
},
|
||||
"DnsClient": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.7.0",
|
||||
"contentHash": "2hrXR83b5g6/ZMJOA36hXp4t56yb7G1mF3Hg6IkrHxvtyaoXRn2WVdgDPN3V8+GugOlUBbTWXgPaka4dXw1QIg==",
|
||||
"dependencies": {
|
||||
"Microsoft.Win32.Registry": "5.0.0"
|
||||
}
|
||||
},
|
||||
"Fido2": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.1",
|
||||
@@ -2555,10 +2563,11 @@
|
||||
"AspNetCoreRateLimit": "[4.0.2, )",
|
||||
"AspNetCoreRateLimit.Redis": "[1.0.1, )",
|
||||
"Azure.Extensions.AspNetCore.DataProtection.Blobs": "[1.2.1, )",
|
||||
"Azure.Storage.Blobs": "[12.11.0, )",
|
||||
"Azure.Storage.Queues": "[12.9.0, )",
|
||||
"Azure.Storage.Blobs": "[12.14.1, )",
|
||||
"Azure.Storage.Queues": "[12.12.0, )",
|
||||
"BitPay.Light": "[1.0.1907, )",
|
||||
"Braintree": "[5.12.0, )",
|
||||
"DnsClient": "[1.7.0, )",
|
||||
"Fido2.AspNet": "[3.0.1, )",
|
||||
"Handlebars.Net": "[2.1.2, )",
|
||||
"IdentityServer4": "[4.1.2, )",
|
||||
|
||||
Reference in New Issue
Block a user