mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
refactor policy apis
This commit is contained in:
@ -13,7 +13,6 @@ namespace Bit.Core.Models.Api.Public
|
||||
/// <summary>
|
||||
/// Data for the policy.
|
||||
/// </summary>
|
||||
[StringLength(300)]
|
||||
public Dictionary<string, object> Data { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class PolicyCreateRequestModel : PolicyUpdateRequestModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of policy.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Enums.PolicyType? Type { get; set; }
|
||||
|
||||
public Policy ToPolicy(Guid orgId)
|
||||
{
|
||||
return ToPolicy(new Policy
|
||||
{
|
||||
OrganizationId = orgId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,19 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class PolicyUpdateRequestModel : PolicyBaseModel
|
||||
{
|
||||
public Policy ToPolicy(Guid orgId)
|
||||
{
|
||||
return ToPolicy(new Policy
|
||||
{
|
||||
OrganizationId = orgId
|
||||
});
|
||||
}
|
||||
|
||||
public virtual Policy ToPolicy(Policy existingPolicy)
|
||||
{
|
||||
existingPolicy.Enabled = Enabled.GetValueOrDefault();
|
||||
|
@ -2,11 +2,13 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IPolicyRepository : IRepository<Policy, Guid>
|
||||
{
|
||||
Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type);
|
||||
Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using System.Linq;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
@ -18,6 +19,18 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public PolicyRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
public async Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Policy>(
|
||||
$"[{Schema}].[{Table}_ReadByOrganizationIdType]",
|
||||
new { OrganizationId = organizationId, Type = (byte)type },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
|
Reference in New Issue
Block a user