2022-06-29 19:46:41 -04:00
|
|
|
|
using System.Data;
|
2023-11-23 07:07:37 +10:00
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Enums;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Repositories;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2023-11-23 07:07:37 +10:00
|
|
|
|
using Bit.Infrastructure.Dapper.Repositories;
|
2021-12-16 15:35:09 +01:00
|
|
|
|
using Dapper;
|
2023-01-10 15:58:41 -05:00
|
|
|
|
using Microsoft.Data.SqlClient;
|
2020-01-06 14:27:16 -05:00
|
|
|
|
|
2024-08-15 20:47:21 -04:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
2023-11-23 07:07:37 +10:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.AdminConsole.Repositories;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
public class PolicyRepository : Repository<Policy, Guid>, IPolicyRepository
|
2020-01-06 14:27:16 -05:00
|
|
|
|
{
|
|
|
|
|
|
public PolicyRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public PolicyRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
2022-06-08 08:44:28 -05:00
|
|
|
|
|
2024-08-15 20:47:21 -04:00
|
|
|
|
public async Task<Policy?> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2020-01-20 08:53:09 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Policy>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadByOrganizationIdType]",
|
|
|
|
|
|
new { OrganizationId = organizationId, Type = (byte)type },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2020-01-06 14:27:16 -05:00
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2020-01-06 14:27:16 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Policy>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadByOrganizationId]",
|
|
|
|
|
|
new { OrganizationId = organizationId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2020-01-28 15:33:32 -05:00
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<Policy>> GetManyByUserIdAsync(Guid userId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2020-01-28 15:33:32 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Policy>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadByUserId]",
|
|
|
|
|
|
new { UserId = userId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2020-01-06 14:27:16 -05:00
|
|
|
|
}
|