mirror of
https://github.com/bitwarden/server.git
synced 2024-11-26 12:55:17 +01:00
stub out policy models and repos
This commit is contained in:
parent
4e4644e17d
commit
9caaab0537
8
src/Core/Enums/PolicyType.cs
Normal file
8
src/Core/Enums/PolicyType.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Bit.Core.Enums
|
||||||
|
{
|
||||||
|
public enum PolicyType : byte
|
||||||
|
{
|
||||||
|
TwoStepLogin = 0,
|
||||||
|
MasterPassword = 1
|
||||||
|
}
|
||||||
|
}
|
22
src/Core/Models/Table/Policy.cs
Normal file
22
src/Core/Models/Table/Policy.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Table
|
||||||
|
{
|
||||||
|
public class Policy : ITableObject<Guid>
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid OrganizationId { get; set; }
|
||||||
|
public PolicyType Type { get; set; }
|
||||||
|
public string Data { get; set; }
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||||
|
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public void SetNewId()
|
||||||
|
{
|
||||||
|
Id = CoreHelpers.GenerateComb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/Core/Repositories/IPolicyRepository.cs
Normal file
12
src/Core/Repositories/IPolicyRepository.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories
|
||||||
|
{
|
||||||
|
public interface IPolicyRepository : IRepository<Policy, Guid>
|
||||||
|
{
|
||||||
|
Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||||
|
}
|
||||||
|
}
|
35
src/Core/Repositories/SqlServer/PolicyRepository.cs
Normal file
35
src/Core/Repositories/SqlServer/PolicyRepository.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories.SqlServer
|
||||||
|
{
|
||||||
|
public class PolicyRepository : Repository<Policy, Guid>, IPolicyRepository
|
||||||
|
{
|
||||||
|
public PolicyRepository(GlobalSettings globalSettings)
|
||||||
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public PolicyRepository(string connectionString, string readOnlyConnectionString)
|
||||||
|
: base(connectionString, readOnlyConnectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public async Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||||
|
{
|
||||||
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
var results = await connection.QueryAsync<Policy>(
|
||||||
|
$"[{Schema}].[{Table}_ReadByOrganizationId]",
|
||||||
|
new { OrganizationId = organizationId },
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return results.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user