From 9266546d60b2ecb2738e20418a5cd1959fc620da Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 20 Jan 2020 09:02:41 -0500 Subject: [PATCH] only 1 policy event --- src/Core/Enums/EventType.cs | 4 +--- src/Core/Services/IPolicyService.cs | 1 - .../Services/Implementations/PolicyService.cs | 20 +++++-------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Core/Enums/EventType.cs b/src/Core/Enums/EventType.cs index cba879d938..51e06ea962 100644 --- a/src/Core/Enums/EventType.cs +++ b/src/Core/Enums/EventType.cs @@ -45,8 +45,6 @@ Organization_PurgedVault = 1601, // Organization_ClientExportedVault = 1602, - Policy_Created = 1700, - Policy_Updated = 1701, - Policy_Deleted = 1702, + Policy_Updated = 1700, } } diff --git a/src/Core/Services/IPolicyService.cs b/src/Core/Services/IPolicyService.cs index daf3caeaf0..c4375d312e 100644 --- a/src/Core/Services/IPolicyService.cs +++ b/src/Core/Services/IPolicyService.cs @@ -6,6 +6,5 @@ namespace Bit.Core.Services public interface IPolicyService { Task SaveAsync(Policy policy); - Task DeleteAsync(Policy policy); } } diff --git a/src/Core/Services/Implementations/PolicyService.cs b/src/Core/Services/Implementations/PolicyService.cs index ba7986a90a..e62d42cc51 100644 --- a/src/Core/Services/Implementations/PolicyService.cs +++ b/src/Core/Services/Implementations/PolicyService.cs @@ -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); } } }