1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

Reference event service implementation (#811)

* Reference event service implementation

* Fix IReferenceable implementation of Id

* add structure to event body
This commit is contained in:
Chad Scharf
2020-07-07 12:01:34 -04:00
committed by GitHub
parent b4524fbcb6
commit 7af50172e0
12 changed files with 248 additions and 3 deletions

View File

@ -0,0 +1,47 @@
using System;
using Bit.Core.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace Bit.Core.Models.Business
{
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class ReferenceEvent
{
public ReferenceEvent() { }
public ReferenceEvent(ReferenceEventType type, IReferenceable source)
{
Type = type;
if (source != null)
{
Source = source.IsUser() ? ReferenceEventSource.User : ReferenceEventSource.Organization;
Id = source.Id;
ReferenceId = source.ReferenceId;
}
}
[JsonConverter(typeof(StringEnumConverter))]
public ReferenceEventType Type { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public ReferenceEventSource Source { get; set; }
public Guid Id { get; set; }
public string ReferenceId { get; set; }
public DateTime EventDate { get; set; } = DateTime.UtcNow;
public bool? EndOfPeriod { get; set; }
public string PlanName { get; set; }
public PlanType? PlanType { get; set; }
public short? Seats { get; set; }
public short? Storage { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace Bit.Core.Models
{
public interface IReferenceable
{
Guid Id { get; set; }
string ReferenceId { get; set; }
bool IsUser();
}
}

View File

@ -7,7 +7,7 @@ using System.Linq;
namespace Bit.Core.Models.Table
{
public class Organization : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable
public class Organization : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable, IReferenceable
{
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Identity;
namespace Bit.Core.Models.Table
{
public class User : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable, ITwoFactorProvidersUser
public class User : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable, ITwoFactorProvidersUser, IReferenceable
{
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;