2020-01-15 08:35:53 -05:00
|
|
|
|
using System;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-01-15 08:35:53 -05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using Bit.Core.Enums;
|
2020-01-15 08:35:53 -05:00
|
|
|
|
using Bit.Core.Models.Table;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
2021-12-14 15:05:07 +00:00
|
|
|
|
namespace Bit.Api.Models.Request
|
2020-01-15 08:35:53 -05:00
|
|
|
|
{
|
|
|
|
|
|
public class PolicyRequestModel
|
|
|
|
|
|
{
|
|
|
|
|
|
[Required]
|
2021-12-14 15:05:07 +00:00
|
|
|
|
public PolicyType? Type { get; set; }
|
2020-01-15 08:35:53 -05:00
|
|
|
|
[Required]
|
|
|
|
|
|
public bool? Enabled { get; set; }
|
|
|
|
|
|
public Dictionary<string, object> Data { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Policy ToPolicy(Guid orgId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ToPolicy(new Policy
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = Type.Value,
|
|
|
|
|
|
OrganizationId = orgId
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Policy ToPolicy(Policy existingPolicy)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingPolicy.Enabled = Enabled.GetValueOrDefault();
|
|
|
|
|
|
existingPolicy.Data = Data != null ? JsonConvert.SerializeObject(Data) : null;
|
|
|
|
|
|
return existingPolicy;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|