mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
PM-10600: Send push notification on notification creation
This commit is contained in:
@ -4,6 +4,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
|||||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||||
using Bit.Core.NotificationCenter.Entities;
|
using Bit.Core.NotificationCenter.Entities;
|
||||||
using Bit.Core.NotificationCenter.Repositories;
|
using Bit.Core.NotificationCenter.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
@ -14,14 +15,17 @@ public class CreateNotificationCommand : ICreateNotificationCommand
|
|||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
private readonly IAuthorizationService _authorizationService;
|
private readonly IAuthorizationService _authorizationService;
|
||||||
private readonly INotificationRepository _notificationRepository;
|
private readonly INotificationRepository _notificationRepository;
|
||||||
|
private readonly IPushNotificationService _pushNotificationService;
|
||||||
|
|
||||||
public CreateNotificationCommand(ICurrentContext currentContext,
|
public CreateNotificationCommand(ICurrentContext currentContext,
|
||||||
IAuthorizationService authorizationService,
|
IAuthorizationService authorizationService,
|
||||||
INotificationRepository notificationRepository)
|
INotificationRepository notificationRepository,
|
||||||
|
IPushNotificationService pushNotificationService)
|
||||||
{
|
{
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
_authorizationService = authorizationService;
|
_authorizationService = authorizationService;
|
||||||
_notificationRepository = notificationRepository;
|
_notificationRepository = notificationRepository;
|
||||||
|
_pushNotificationService = pushNotificationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Notification> CreateAsync(Notification notification)
|
public async Task<Notification> CreateAsync(Notification notification)
|
||||||
@ -31,6 +35,10 @@ public class CreateNotificationCommand : ICreateNotificationCommand
|
|||||||
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User, notification,
|
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User, notification,
|
||||||
NotificationOperations.Create);
|
NotificationOperations.Create);
|
||||||
|
|
||||||
return await _notificationRepository.CreateAsync(notification);
|
var newNotification = await _notificationRepository.CreateAsync(notification);
|
||||||
|
|
||||||
|
await _pushNotificationService.PushSyncNotificationAsync(newNotification);
|
||||||
|
|
||||||
|
return newNotification;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
|||||||
using Bit.Core.NotificationCenter.Commands;
|
using Bit.Core.NotificationCenter.Commands;
|
||||||
using Bit.Core.NotificationCenter.Entities;
|
using Bit.Core.NotificationCenter.Entities;
|
||||||
using Bit.Core.NotificationCenter.Repositories;
|
using Bit.Core.NotificationCenter.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Test.NotificationCenter.AutoFixture;
|
using Bit.Core.Test.NotificationCenter.AutoFixture;
|
||||||
using Bit.Test.Common.AutoFixture;
|
using Bit.Test.Common.AutoFixture;
|
||||||
using Bit.Test.Common.AutoFixture.Attributes;
|
using Bit.Test.Common.AutoFixture.Attributes;
|
||||||
@ -55,5 +56,8 @@ public class CreateNotificationCommandTest
|
|||||||
Assert.Equal(notification, newNotification);
|
Assert.Equal(notification, newNotification);
|
||||||
Assert.Equal(DateTime.UtcNow, notification.CreationDate, TimeSpan.FromMinutes(1));
|
Assert.Equal(DateTime.UtcNow, notification.CreationDate, TimeSpan.FromMinutes(1));
|
||||||
Assert.Equal(notification.CreationDate, notification.RevisionDate);
|
Assert.Equal(notification.CreationDate, notification.RevisionDate);
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(1)
|
||||||
|
.PushSyncNotificationAsync(newNotification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user