mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
policy events
This commit is contained in:
@ -44,5 +44,9 @@
|
||||
Organization_Updated = 1600,
|
||||
Organization_PurgedVault = 1601,
|
||||
// Organization_ClientExportedVault = 1602,
|
||||
|
||||
Policy_Created = 1700,
|
||||
Policy_Updated = 1701,
|
||||
Policy_Deleted = 1702,
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
ItemId = ev.CipherId;
|
||||
CollectionId = ev.CollectionId;
|
||||
GroupId = ev.GroupId;
|
||||
PolicyId = ev.PolicyId;
|
||||
MemberId = ev.OrganizationUserId;
|
||||
ActingUserId = ev.ActingUserId;
|
||||
Date = ev.Date;
|
||||
@ -55,6 +56,11 @@ namespace Bit.Core.Models.Api.Public
|
||||
/// <example>f29a2515-91d2-4452-b49b-5e8040e6b0f4</example>
|
||||
public Guid? GroupId { get; set; }
|
||||
/// <summary>
|
||||
/// The unique identifier of the related policy that the event describes.
|
||||
/// </summary>
|
||||
/// <example>f29a2515-91d2-4452-b49b-5e8040e6b0f4</example>
|
||||
public Guid? PolicyId { get; set; }
|
||||
/// <summary>
|
||||
/// The unique identifier of the related member that the event describes.
|
||||
/// </summary>
|
||||
/// <example>e68b8629-85eb-4929-92c0-b84464976ba4</example>
|
||||
|
@ -20,6 +20,7 @@ namespace Bit.Core.Models.Api
|
||||
CipherId = ev.CipherId;
|
||||
CollectionId = ev.CollectionId;
|
||||
GroupId = ev.GroupId;
|
||||
PolicyId = ev.PolicyId;
|
||||
OrganizationUserId = ev.OrganizationUserId;
|
||||
ActingUserId = ev.ActingUserId;
|
||||
Date = ev.Date;
|
||||
@ -33,6 +34,7 @@ namespace Bit.Core.Models.Api
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public Guid? ActingUserId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
@ -21,6 +21,7 @@ namespace Bit.Core.Models.Data
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public Guid? ActingUserId { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
|
@ -18,6 +18,7 @@ namespace Bit.Core.Models.Data
|
||||
OrganizationId = e.OrganizationId;
|
||||
CipherId = e.CipherId;
|
||||
CollectionId = e.CollectionId;
|
||||
PolicyId = e.PolicyId;
|
||||
GroupId = e.GroupId;
|
||||
OrganizationUserId = e.OrganizationUserId;
|
||||
DeviceType = e.DeviceType;
|
||||
@ -31,6 +32,7 @@ namespace Bit.Core.Models.Data
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
|
@ -11,6 +11,7 @@ namespace Bit.Core.Models.Data
|
||||
Guid? CipherId { get; set; }
|
||||
Guid? CollectionId { get; set; }
|
||||
Guid? GroupId { get; set; }
|
||||
Guid? PolicyId { get; set; }
|
||||
Guid? OrganizationUserId { get; set; }
|
||||
Guid? ActingUserId { get; set; }
|
||||
DeviceType? DeviceType { get; set; }
|
||||
|
@ -17,6 +17,7 @@ namespace Bit.Core.Models.Table
|
||||
OrganizationId = e.OrganizationId;
|
||||
CipherId = e.CipherId;
|
||||
CollectionId = e.CollectionId;
|
||||
PolicyId = e.PolicyId;
|
||||
GroupId = e.GroupId;
|
||||
OrganizationUserId = e.OrganizationUserId;
|
||||
DeviceType = e.DeviceType;
|
||||
@ -31,6 +32,7 @@ namespace Bit.Core.Models.Table
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
|
@ -153,6 +153,8 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
eventsTable.Columns.Add(cipherIdColumn);
|
||||
var collectionIdColumn = new DataColumn(nameof(e.CollectionId), typeof(Guid));
|
||||
eventsTable.Columns.Add(collectionIdColumn);
|
||||
var policyIdColumn = new DataColumn(nameof(e.PolicyId), typeof(Guid));
|
||||
eventsTable.Columns.Add(policyIdColumn);
|
||||
var groupIdColumn = new DataColumn(nameof(e.GroupId), typeof(Guid));
|
||||
eventsTable.Columns.Add(groupIdColumn);
|
||||
var organizationUserIdColumn = new DataColumn(nameof(e.OrganizationUserId), typeof(Guid));
|
||||
@ -182,6 +184,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
row[organizationIdColumn] = ev.OrganizationId.HasValue ? (object)ev.OrganizationId.Value : DBNull.Value;
|
||||
row[cipherIdColumn] = ev.CipherId.HasValue ? (object)ev.CipherId.Value : DBNull.Value;
|
||||
row[collectionIdColumn] = ev.CollectionId.HasValue ? (object)ev.CollectionId.Value : DBNull.Value;
|
||||
row[policyIdColumn] = ev.PolicyId.HasValue ? (object)ev.PolicyId.Value : DBNull.Value;
|
||||
row[groupIdColumn] = ev.GroupId.HasValue ? (object)ev.GroupId.Value : DBNull.Value;
|
||||
row[organizationUserIdColumn] = ev.OrganizationUserId.HasValue ?
|
||||
(object)ev.OrganizationUserId.Value : DBNull.Value;
|
||||
|
@ -13,6 +13,7 @@ namespace Bit.Core.Services
|
||||
Task LogCipherEventsAsync(IEnumerable<Tuple<Cipher, EventType, DateTime?>> events);
|
||||
Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null);
|
||||
Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null);
|
||||
Task LogPolicyEventAsync(Policy policy, EventType type, DateTime? date = null);
|
||||
Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type, DateTime? date = null);
|
||||
Task LogOrganizationEventAsync(Organization organization, EventType type, DateTime? date = null);
|
||||
}
|
||||
|
@ -156,6 +156,25 @@ namespace Bit.Core.Services
|
||||
await _eventWriteService.CreateAsync(e);
|
||||
}
|
||||
|
||||
public async Task LogPolicyEventAsync(Policy policy, EventType type, DateTime? date = null)
|
||||
{
|
||||
var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
|
||||
if(!CanUseEvents(orgAbilities, policy.OrganizationId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var e = new EventMessage(_currentContext)
|
||||
{
|
||||
OrganizationId = policy.OrganizationId,
|
||||
PolicyId = policy.Id,
|
||||
Type = type,
|
||||
ActingUserId = _currentContext?.UserId,
|
||||
Date = date.GetValueOrDefault(DateTime.UtcNow)
|
||||
};
|
||||
await _eventWriteService.CreateAsync(e);
|
||||
}
|
||||
|
||||
public async Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type,
|
||||
DateTime? date = null)
|
||||
{
|
||||
|
@ -3,8 +3,6 @@ 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
|
||||
{
|
||||
@ -46,20 +44,20 @@ namespace Bit.Core.Services
|
||||
{
|
||||
policy.CreationDate = policy.RevisionDate = DateTime.UtcNow;
|
||||
await _policyRepository.CreateAsync(policy);
|
||||
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Created);
|
||||
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Created);
|
||||
}
|
||||
else
|
||||
{
|
||||
policy.RevisionDate = DateTime.UtcNow;
|
||||
await _policyRepository.ReplaceAsync(policy);
|
||||
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Updated);
|
||||
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Updated);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Policy policy)
|
||||
{
|
||||
await _policyRepository.DeleteAsync(policy);
|
||||
//await _eventService.LogGroupEventAsync(policy, Enums.EventType.Group_Deleted);
|
||||
await _eventService.LogPolicyEventAsync(policy, Enums.EventType.Policy_Deleted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,11 @@ namespace Bit.Core.Services
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task LogPolicyEventAsync(Policy policy, EventType type, DateTime? date = null)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
|
Reference in New Issue
Block a user