1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-01 23:31:41 +01:00

only 1 policy event

This commit is contained in:
Kyle Spearrin 2020-01-20 09:02:41 -05:00
parent f3f1ac57d2
commit 9266546d60
3 changed files with 6 additions and 19 deletions

View File

@ -45,8 +45,6 @@
Organization_PurgedVault = 1601,
// Organization_ClientExportedVault = 1602,
Policy_Created = 1700,
Policy_Updated = 1701,
Policy_Deleted = 1702,
Policy_Updated = 1700,
}
}

View File

@ -6,6 +6,5 @@ namespace Bit.Core.Services
public interface IPolicyService
{
Task SaveAsync(Policy policy);
Task DeleteAsync(Policy policy);
}
}

View File

@ -38,24 +38,14 @@ namespace Bit.Core.Services
throw new BadRequestException("This organization cannot use policies.");
}
var now = DateTime.UtcNow;
if(policy.Id == default(Guid))
{
policy.CreationDate = policy.RevisionDate = DateTime.UtcNow;
await _policyRepository.CreateAsync(policy);
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Created);
policy.CreationDate = now;
}
else
{
policy.RevisionDate = DateTime.UtcNow;
await _policyRepository.ReplaceAsync(policy);
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Updated);
}
}
public async Task DeleteAsync(Policy policy)
{
await _policyRepository.DeleteAsync(policy);
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Deleted);
policy.RevisionDate = DateTime.UtcNow;
await _policyRepository.UpsertAsync(policy);
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Updated);
}
}
}