2022-06-29 19:46:41 -04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-12-21 12:10:01 -05:00
|
|
|
|
using System.Text.Json;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using Bit.Core.Enums;
|
2020-01-15 08:35:53 -05:00
|
|
|
|
|
2023-10-19 01:27:56 +10:00
|
|
|
|
namespace Bit.Api.AdminConsole.Models.Request;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2021-12-14 15:05:07 +00:00
|
|
|
|
public class PolicyRequestModel
|
2020-01-15 08:35:53 -05:00
|
|
|
|
{
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
public PolicyType? Type { get; set; }
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
public bool? Enabled { get; set; }
|
|
|
|
|
|
public Dictionary<string, object> Data { get; set; }
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2020-01-15 08:35:53 -05:00
|
|
|
|
public Policy ToPolicy(Guid orgId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-01-15 08:35:53 -05:00
|
|
|
|
return ToPolicy(new Policy
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = Type.Value,
|
|
|
|
|
|
OrganizationId = orgId
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Policy ToPolicy(Policy existingPolicy)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingPolicy.Enabled = Enabled.GetValueOrDefault();
|
2021-12-21 12:10:01 -05:00
|
|
|
|
existingPolicy.Data = Data != null ? JsonSerializer.Serialize(Data) : null;
|
2020-01-15 08:35:53 -05:00
|
|
|
|
return existingPolicy;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|