1
0
mirror of https://github.com/bitwarden/server synced 2026-02-25 00:52:57 +00:00

gate add/edit endpoints behind premium membership and add test coverage (#7043)

This commit is contained in:
John Harrington
2026-02-20 07:48:18 -07:00
committed by GitHub
parent 708ea66393
commit a961626957
2 changed files with 97 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ using Bit.Api.Utilities;
using Bit.Core;
using Bit.Core.Auth.Identity;
using Bit.Core.Auth.UserFeatures.SendAccess;
using Bit.Core.Billing.Premium.Queries;
using Bit.Core.Exceptions;
using Bit.Core.Platform.Push;
using Bit.Core.Services;
@@ -36,6 +37,7 @@ public class SendsController : Controller
private readonly ILogger<SendsController> _logger;
private readonly IFeatureService _featureService;
private readonly IPushNotificationService _pushNotificationService;
private readonly IHasPremiumAccessQuery _hasPremiumAccessQuery;
public SendsController(
ISendRepository sendRepository,
@@ -47,7 +49,9 @@ public class SendsController : Controller
ISendFileStorageService sendFileStorageService,
ILogger<SendsController> logger,
IFeatureService featureService,
IPushNotificationService pushNotificationService)
IPushNotificationService pushNotificationService,
IHasPremiumAccessQuery hasPremiumAccessQuery
)
{
_sendRepository = sendRepository;
_userService = userService;
@@ -59,6 +63,7 @@ public class SendsController : Controller
_logger = logger;
_featureService = featureService;
_pushNotificationService = pushNotificationService;
_hasPremiumAccessQuery = hasPremiumAccessQuery;
}
#region Anonymous endpoints
@@ -306,6 +311,13 @@ public class SendsController : Controller
{
model.ValidateCreation();
var userId = _userService.GetProperUserId(User) ?? throw new InvalidOperationException("User ID not found");
var hasPremium = await _hasPremiumAccessQuery.HasPremiumAccessAsync(userId);
if (!hasPremium && !string.IsNullOrWhiteSpace(model.Emails))
{
throw new BadRequestException("Email verified Sends require a premium membership");
}
var send = model.ToSend(userId, _sendAuthorizationService);
await _nonAnonymousSendCommand.SaveSendAsync(send);
return new SendResponseModel(send);
@@ -332,6 +344,13 @@ public class SendsController : Controller
model.ValidateCreation();
var userId = _userService.GetProperUserId(User) ?? throw new InvalidOperationException("User ID not found");
var hasPremium = await _hasPremiumAccessQuery.HasPremiumAccessAsync(userId);
if (!hasPremium && !string.IsNullOrWhiteSpace(model.Emails))
{
throw new BadRequestException("Email verified Sends require a premium membership");
}
var (send, data) = model.ToSend(userId, model.File.FileName, _sendAuthorizationService);
var uploadUrl = await _nonAnonymousSendCommand.SaveFileSendAsync(send, data, model.FileLength.Value);
return new SendFileUploadDataResponseModel
@@ -397,6 +416,13 @@ public class SendsController : Controller
{
model.ValidateEdit();
var userId = _userService.GetProperUserId(User) ?? throw new InvalidOperationException("User ID not found");
var hasPremium = await _hasPremiumAccessQuery.HasPremiumAccessAsync(userId);
if (!hasPremium && !string.IsNullOrWhiteSpace(model.Emails))
{
throw new BadRequestException("Email verified Sends require a premium membership");
}
var send = await _sendRepository.GetByIdAsync(new Guid(id));
if (send == null || send.UserId != userId)
{