mirror of
https://github.com/bitwarden/server.git
synced 2025-12-11 13:53:48 -06:00
* PM-18939 refactoring send service to 'cqrs' * PM-18939 fixing import issue with sendValidationService * PM-18939 fixing code based on PR comments * PM-18339 reverting to previous code in test * PM-18939 adding XMLdocs to services * PM-18939 reverting send validation methods * PM-18939 updating code to match main * PM-18939 reverting validateUserCanSaveAsync to match main * PM-18939 fill our param and return sections of XMLdocs * PM-18939 updating XMLdocs based on PR comments * Update src/Core/Tools/SendFeatures/Commands/Interfaces/IAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Commands/Interfaces/INonAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Commands/Interfaces/INonAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Services/Interfaces/ISendStorageService.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * PM-18939 adding commits to change tuple to enum type * PM-18939 resetting stream position to 0 when uploading file * PM-18939 updating XMLdocs based on PR comments * PM-18939 updating XMLdocs * PM-18939 removing circular dependency * PM-18939 fixing based on comments * PM-18939 updating method name and documentation --------- Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Bit.Core.Exceptions;
|
|
using Bit.Core.Platform.Push;
|
|
using Bit.Core.Tools.Entities;
|
|
using Bit.Core.Tools.Enums;
|
|
using Bit.Core.Tools.Models.Data;
|
|
using Bit.Core.Tools.Repositories;
|
|
using Bit.Core.Tools.SendFeatures.Commands.Interfaces;
|
|
using Bit.Core.Tools.Services;
|
|
|
|
namespace Bit.Core.Tools.SendFeatures.Commands;
|
|
|
|
public class AnonymousSendCommand : IAnonymousSendCommand
|
|
{
|
|
private readonly ISendRepository _sendRepository;
|
|
private readonly ISendFileStorageService _sendFileStorageService;
|
|
private readonly IPushNotificationService _pushNotificationService;
|
|
private readonly ISendAuthorizationService _sendAuthorizationService;
|
|
|
|
public AnonymousSendCommand(
|
|
ISendRepository sendRepository,
|
|
ISendFileStorageService sendFileStorageService,
|
|
IPushNotificationService pushNotificationService,
|
|
ISendAuthorizationService sendAuthorizationService
|
|
)
|
|
{
|
|
_sendRepository = sendRepository;
|
|
_sendFileStorageService = sendFileStorageService;
|
|
_pushNotificationService = pushNotificationService;
|
|
_sendAuthorizationService = sendAuthorizationService;
|
|
}
|
|
|
|
// Response: Send, password required, password invalid
|
|
public async Task<(string, SendAccessResult)> GetSendFileDownloadUrlAsync(Send send, string fileId, string password)
|
|
{
|
|
if (send.Type != SendType.File)
|
|
{
|
|
throw new BadRequestException("Can only get a download URL for a file type of Send");
|
|
}
|
|
|
|
var result = _sendAuthorizationService.SendCanBeAccessed(send, password);
|
|
|
|
if (!result.Equals(SendAccessResult.Granted))
|
|
{
|
|
return (null, result);
|
|
}
|
|
|
|
send.AccessCount++;
|
|
await _sendRepository.ReplaceAsync(send);
|
|
await _pushNotificationService.PushSyncSendUpdateAsync(send);
|
|
return (await _sendFileStorageService.GetSendFileDownloadUrlAsync(send, fileId), result);
|
|
}
|
|
}
|