Files
server/src/Api/AdminConsole/Models/Request/PolicyRequestModel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
787 B
C#
Raw Normal View History

using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Bit.Core.Entities;
2021-12-14 15:05:07 +00:00
using Bit.Core.Enums;
2020-01-15 08:35:53 -05: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; }
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();
existingPolicy.Data = Data != null ? JsonSerializer.Serialize(Data) : null;
2020-01-15 08:35:53 -05:00
return existingPolicy;
}
}