1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00
Files
bitwarden/src/Core/NotificationCenter/Commands/UpdateNotificationCommand.cs
Maciej Zieniuk 28ff53c293 Merge branch 'km/pm-10600-full-notification-content' into km/pm-10564
# Conflicts:
#	src/Core/Models/PushNotification.cs
#	src/Core/Services/IPushNotificationService.cs
#	src/Core/Services/NoopImplementations/NoopPushNotificationService.cs
#	test/Core.Test/NotificationCenter/Commands/CreateNotificationCommandTest.cs
#	test/Core.Test/NotificationHub/NotificationHubPushNotificationServiceTests.cs
#	test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs
2024-11-26 16:18:05 +00:00

54 lines
2.0 KiB
C#

#nullable enable
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.NotificationCenter.Authorization;
using Bit.Core.NotificationCenter.Commands.Interfaces;
using Bit.Core.NotificationCenter.Entities;
using Bit.Core.NotificationCenter.Repositories;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
namespace Bit.Core.NotificationCenter.Commands;
public class UpdateNotificationCommand : IUpdateNotificationCommand
{
private readonly ICurrentContext _currentContext;
private readonly IAuthorizationService _authorizationService;
private readonly INotificationRepository _notificationRepository;
private readonly IPushNotificationService _pushNotificationService;
public UpdateNotificationCommand(ICurrentContext currentContext,
IAuthorizationService authorizationService,
INotificationRepository notificationRepository,
IPushNotificationService pushNotificationService)
{
_currentContext = currentContext;
_authorizationService = authorizationService;
_notificationRepository = notificationRepository;
_pushNotificationService = pushNotificationService;
}
public async Task UpdateAsync(Notification notificationToUpdate)
{
var notification = await _notificationRepository.GetByIdAsync(notificationToUpdate.Id);
if (notification == null)
{
throw new NotFoundException();
}
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User,
notification, NotificationOperations.Update);
notification.Priority = notificationToUpdate.Priority;
notification.ClientType = notificationToUpdate.ClientType;
notification.Title = notificationToUpdate.Title;
notification.Body = notificationToUpdate.Body;
notification.RevisionDate = DateTime.UtcNow;
await _notificationRepository.ReplaceAsync(notification);
await _pushNotificationService.PushNotificationAsync(notification);
}
}