mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
policy service
This commit is contained in:
parent
0d540e0040
commit
937bb4359f
11
src/Core/Services/IPolicyService.cs
Normal file
11
src/Core/Services/IPolicyService.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
|
||||||
|
namespace Bit.Core.Services
|
||||||
|
{
|
||||||
|
public interface IPolicyService
|
||||||
|
{
|
||||||
|
Task SaveAsync(Policy policy);
|
||||||
|
Task DeleteAsync(Policy policy);
|
||||||
|
}
|
||||||
|
}
|
65
src/Core/Services/Implementations/PolicyService.cs
Normal file
65
src/Core/Services/Implementations/PolicyService.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bit.Core.Exceptions;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using Bit.Core.Repositories;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
|
namespace Bit.Core.Services
|
||||||
|
{
|
||||||
|
public class PolicyService : IPolicyService
|
||||||
|
{
|
||||||
|
private readonly IEventService _eventService;
|
||||||
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
|
private readonly IPolicyRepository _policyRepository;
|
||||||
|
|
||||||
|
public PolicyService(
|
||||||
|
IEventService eventService,
|
||||||
|
IOrganizationRepository organizationRepository,
|
||||||
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
|
IPolicyRepository policyRepository)
|
||||||
|
{
|
||||||
|
_eventService = eventService;
|
||||||
|
_organizationRepository = organizationRepository;
|
||||||
|
_organizationUserRepository = organizationUserRepository;
|
||||||
|
_policyRepository = policyRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveAsync(Policy policy)
|
||||||
|
{
|
||||||
|
var org = await _organizationRepository.GetByIdAsync(policy.OrganizationId);
|
||||||
|
if(org == null)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Organization not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(!org.UseGroups)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("This organization cannot use policies.");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(policy.Id == default(Guid))
|
||||||
|
{
|
||||||
|
policy.CreationDate = policy.RevisionDate = DateTime.UtcNow;
|
||||||
|
await _policyRepository.CreateAsync(policy);
|
||||||
|
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Created);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
policy.RevisionDate = DateTime.UtcNow;
|
||||||
|
await _policyRepository.ReplaceAsync(policy);
|
||||||
|
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Updated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(Policy policy)
|
||||||
|
{
|
||||||
|
await _policyRepository.DeleteAsync(policy);
|
||||||
|
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Deleted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user