mirror of
https://github.com/bitwarden/server
synced 2026-02-09 05:00:32 +00:00
Add xml doc, incorporate shim data model
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using Bit.Core.AdminConsole.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
||||
|
||||
public class PolicyData
|
||||
{
|
||||
public Guid OrganizationId { get; init; }
|
||||
public PolicyType Type { get; init; }
|
||||
public bool Enabled { get; init; }
|
||||
public string? Data { get; init; }
|
||||
|
||||
public T GetDataModel<T>() where T : IPolicyDataModel, new()
|
||||
{
|
||||
return CoreHelpers.LoadClassFromJsonData<T>(Data);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,18 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Enums;
|
||||
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Policies;
|
||||
|
||||
public interface IPolicyQuery
|
||||
{
|
||||
Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType policyType);
|
||||
/// <summary>
|
||||
/// Retrieves a summary view of an organization's usage of a policy specified by the <paramref name="policyType"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This query is the entrypoint for consumers interested in understanding how a particular <see cref="PolicyType"/>
|
||||
/// has been applied to an organization; the resultant <see cref="PolicyData"/> is not indicative of explicit
|
||||
/// policy configuration.
|
||||
/// </remarks>
|
||||
Task<PolicyData> RunAsync(Guid organizationId, PolicyType policyType);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Enums;
|
||||
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Policies.Implementations;
|
||||
|
||||
public class PolicyQuery(IPolicyRepository policyRepository) : IPolicyQuery
|
||||
{
|
||||
public async Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType policyType)
|
||||
=> await policyRepository.GetByOrganizationIdTypeAsync(organizationId, policyType)
|
||||
?? new Policy { OrganizationId = organizationId, Type = policyType };
|
||||
public async Task<PolicyData> RunAsync(Guid organizationId, PolicyType policyType)
|
||||
{
|
||||
var dbPolicy = await policyRepository.GetByOrganizationIdTypeAsync(organizationId, policyType);
|
||||
return new PolicyData
|
||||
{
|
||||
OrganizationId = dbPolicy?.OrganizationId ?? organizationId,
|
||||
Data = dbPolicy?.Data,
|
||||
Type = dbPolicy?.Type ?? policyType,
|
||||
Enabled = dbPolicy?.Enabled ?? false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user