mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 17:42:49 -05:00

* [AC-621] Added possibility of adding users through SCIM to an Organization without a confirmed Owner * [AC-621] Passing EventSystemUser argument for HasConfirmedOwnersExceptAsync in user delete actions by SCIM * [AC-624] Removed EventSystemUser parameter from IOrganizationService.HasConfirmedOwnersExceptAsync * [AC-621] Added IProviderUserRepository.GetManyOrganizationDetailsByOrganizationAsync * [AC-621] Updated OrganizationService.HasConfirmedOwnersExceptAsync to use IProviderUserRepository.GetManyOrganizationDetailsByOrganizationAsync to check for any confirmed provider users * [AC-621] Removed unused EventSystemUser parameters * [AC-621] Refactored ProviderUserRepository.GetManyByOrganizationAsync to return ProviderUser objects * [AC-621] Removed default parameter value for Status
177 lines
6.6 KiB
C#
177 lines
6.6 KiB
C#
using System.Data;
|
|
using Bit.Core.Entities.Provider;
|
|
using Bit.Core.Enums.Provider;
|
|
using Bit.Core.Models.Data;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Settings;
|
|
using Dapper;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
|
|
|
public class ProviderUserRepository : Repository<ProviderUser, Guid>, IProviderUserRepository
|
|
{
|
|
public ProviderUserRepository(GlobalSettings globalSettings)
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
{ }
|
|
|
|
public ProviderUserRepository(string connectionString, string readOnlyConnectionString)
|
|
: base(connectionString, readOnlyConnectionString)
|
|
{ }
|
|
|
|
public async Task<int> GetCountByProviderAsync(Guid providerId, string email, bool onlyRegisteredUsers)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var result = await connection.ExecuteScalarAsync<int>(
|
|
"[dbo].[ProviderUser_ReadCountByProviderIdEmail]",
|
|
new { ProviderId = providerId, Email = email, OnlyUsers = onlyRegisteredUsers },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUser>> GetManyAsync(IEnumerable<Guid> ids)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUser>(
|
|
"[dbo].[ProviderUser_ReadByIds]",
|
|
new { Ids = ids.ToGuidIdArrayTVP() },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUser>> GetManyByUserAsync(Guid userId)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUser>(
|
|
"[dbo].[ProviderUser_ReadByUserId]",
|
|
new { UserId = userId },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<ProviderUser> GetByProviderUserAsync(Guid providerId, Guid userId)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUser>(
|
|
"[dbo].[ProviderUser_ReadByProviderIdUserId]",
|
|
new { ProviderId = providerId, UserId = userId },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.SingleOrDefault();
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUser>> GetManyByProviderAsync(Guid providerId, ProviderUserType? type)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUser>(
|
|
"[dbo].[ProviderUser_ReadByProviderId]",
|
|
new { ProviderId = providerId, Type = type },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUserUserDetails>> GetManyDetailsByProviderAsync(Guid providerId, ProviderUserStatusType? status)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUserUserDetails>(
|
|
"[dbo].[ProviderUserUserDetails_ReadByProviderId]",
|
|
new { ProviderId = providerId, Status = status },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUserProviderDetails>> GetManyDetailsByUserAsync(Guid userId,
|
|
ProviderUserStatusType? status = null)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUserProviderDetails>(
|
|
"[dbo].[ProviderUserProviderDetails_ReadByUserIdStatus]",
|
|
new { UserId = userId, Status = status },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<ProviderUserOrganizationDetails>> GetManyOrganizationDetailsByUserAsync(Guid userId,
|
|
ProviderUserStatusType? status = null)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUserOrganizationDetails>(
|
|
"[dbo].[ProviderUserProviderOrganizationDetails_ReadByUserIdStatus]",
|
|
new { UserId = userId, Status = status },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task DeleteManyAsync(IEnumerable<Guid> providerUserIds)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
await connection.ExecuteAsync("[dbo].[ProviderUser_DeleteByIds]",
|
|
new { Ids = providerUserIds.ToGuidIdArrayTVP() }, commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<ProviderUserPublicKey>> GetManyPublicKeysByProviderUserAsync(
|
|
Guid providerId, IEnumerable<Guid> Ids)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUserPublicKey>(
|
|
"[dbo].[User_ReadPublicKeysByProviderUserIds]",
|
|
new { ProviderId = providerId, ProviderUserIds = Ids.ToGuidIdArrayTVP() },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<int> GetCountByOnlyOwnerAsync(Guid userId)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.ExecuteScalarAsync<int>(
|
|
"[dbo].[ProviderUser_ReadCountByOnlyOwner]",
|
|
new { UserId = userId },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results;
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<ProviderUser>> GetManyByOrganizationAsync(Guid organizationId, ProviderUserStatusType? status = null)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<ProviderUser>(
|
|
"[dbo].[ProviderUser_ReadByOrganizationIdStatus]",
|
|
new { OrganizationId = organizationId, Status = status },
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
}
|