mirror of
https://github.com/bitwarden/server.git
synced 2025-01-23 22:01:28 +01:00
Reference events for Send (#1165)
This commit is contained in:
parent
07427623b3
commit
2f7c2a64e0
@ -24,5 +24,9 @@ namespace Bit.Core.Enums
|
|||||||
InvitedUsers,
|
InvitedUsers,
|
||||||
[EnumMember(Value = "rebilled")]
|
[EnumMember(Value = "rebilled")]
|
||||||
Rebilled,
|
Rebilled,
|
||||||
|
[EnumMember(Value = "send-created")]
|
||||||
|
SendCreated,
|
||||||
|
[EnumMember(Value = "send-accessed")]
|
||||||
|
SendAccessed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,5 +45,12 @@ namespace Bit.Core.Models.Business
|
|||||||
public short? Seats { get; set; }
|
public short? Seats { get; set; }
|
||||||
|
|
||||||
public short? Storage { get; set; }
|
public short? Storage { get; set; }
|
||||||
|
|
||||||
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
public SendType? SendType { get; set; }
|
||||||
|
|
||||||
|
public int? MaxAccessCount { get; set; }
|
||||||
|
|
||||||
|
public bool? HasPassword { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
|||||||
using Bit.Core.Context;
|
using Bit.Core.Context;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
|
using Bit.Core.Models.Business;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Models.Table;
|
using Bit.Core.Models.Table;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
@ -24,6 +25,7 @@ namespace Bit.Core.Services
|
|||||||
private readonly ISendFileStorageService _sendFileStorageService;
|
private readonly ISendFileStorageService _sendFileStorageService;
|
||||||
private readonly IPasswordHasher<User> _passwordHasher;
|
private readonly IPasswordHasher<User> _passwordHasher;
|
||||||
private readonly IPushNotificationService _pushService;
|
private readonly IPushNotificationService _pushService;
|
||||||
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ namespace Bit.Core.Services
|
|||||||
ISendFileStorageService sendFileStorageService,
|
ISendFileStorageService sendFileStorageService,
|
||||||
IPasswordHasher<User> passwordHasher,
|
IPasswordHasher<User> passwordHasher,
|
||||||
IPushNotificationService pushService,
|
IPushNotificationService pushService,
|
||||||
|
IReferenceEventService referenceEventService,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IPolicyRepository policyRepository,
|
IPolicyRepository policyRepository,
|
||||||
ICurrentContext currentContext)
|
ICurrentContext currentContext)
|
||||||
@ -47,6 +50,7 @@ namespace Bit.Core.Services
|
|||||||
_sendFileStorageService = sendFileStorageService;
|
_sendFileStorageService = sendFileStorageService;
|
||||||
_passwordHasher = passwordHasher;
|
_passwordHasher = passwordHasher;
|
||||||
_pushService = pushService;
|
_pushService = pushService;
|
||||||
|
_referenceEventService = referenceEventService;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
}
|
}
|
||||||
@ -60,6 +64,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
await _sendRepository.CreateAsync(send);
|
await _sendRepository.CreateAsync(send);
|
||||||
await _pushService.PushSyncSendCreateAsync(send);
|
await _pushService.PushSyncSendCreateAsync(send);
|
||||||
|
await RaiseReferenceEventAsync(send, ReferenceEventType.SendCreated);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -178,9 +183,23 @@ namespace Bit.Core.Services
|
|||||||
// TODO: maybe move this to a simple ++ sproc?
|
// TODO: maybe move this to a simple ++ sproc?
|
||||||
send.AccessCount++;
|
send.AccessCount++;
|
||||||
await _sendRepository.ReplaceAsync(send);
|
await _sendRepository.ReplaceAsync(send);
|
||||||
|
await RaiseReferenceEventAsync(send, ReferenceEventType.SendAccessed);
|
||||||
return (send, false, false);
|
return (send, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task RaiseReferenceEventAsync(Send send, ReferenceEventType eventType)
|
||||||
|
{
|
||||||
|
await _referenceEventService.RaiseEventAsync(new ReferenceEvent
|
||||||
|
{
|
||||||
|
Id = send.UserId ?? default,
|
||||||
|
Type = eventType,
|
||||||
|
Source = ReferenceEventSource.User,
|
||||||
|
SendType = send.Type,
|
||||||
|
MaxAccessCount = send.MaxAccessCount,
|
||||||
|
HasPassword = !string.IsNullOrWhiteSpace(send.Password),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public string HashPassword(string password)
|
public string HashPassword(string password)
|
||||||
{
|
{
|
||||||
return _passwordHasher.HashPassword(new User(), password);
|
return _passwordHasher.HashPassword(new User(), password);
|
||||||
|
Loading…
Reference in New Issue
Block a user