1
0
mirror of https://github.com/bitwarden/server synced 2025-12-29 14:43:39 +00:00

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
This commit is contained in:
Maciej Zieniuk
2024-11-26 16:04:43 +00:00
23 changed files with 213 additions and 156 deletions

View File

@@ -1,5 +1,6 @@
#nullable enable
using Bit.Core.Enums;
using Bit.Core.NotificationCenter.Enums;
namespace Bit.Core.Models;
@@ -46,12 +47,17 @@ public class SyncSendPushNotification
public DateTime RevisionDate { get; set; }
}
public class SyncNotificationPushNotification
public class NotificationPushNotification
{
public Guid Id { get; set; }
public Priority Priority { get; set; }
public bool Global { get; set; }
public ClientType ClientType { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public ClientType ClientType { get; set; }
public string? Title { get; set; }
public string? Body { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public DateTime? ReadDate { get; set; }
public DateTime? DeletedDate { get; set; }

View File

@@ -37,7 +37,7 @@ public class CreateNotificationCommand : ICreateNotificationCommand
var newNotification = await _notificationRepository.CreateAsync(notification);
await _pushNotificationService.PushSyncNotificationAsync(newNotification);
await _pushNotificationService.PushNotificationAsync(newNotification);
return newNotification;
}

View File

@@ -48,7 +48,7 @@ public class CreateNotificationStatusCommand : ICreateNotificationStatusCommand
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
await _pushNotificationService.PushSyncNotificationStatusAsync(notification, newNotificationStatus);
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
return newNotificationStatus;
}

View File

@@ -65,7 +65,7 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
await _pushNotificationService.PushSyncNotificationStatusAsync(notification, newNotificationStatus);
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
}
else
{
@@ -76,7 +76,7 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
await _notificationStatusRepository.UpdateAsync(notificationStatus);
await _pushNotificationService.PushSyncNotificationStatusAsync(notification, notificationStatus);
await _pushNotificationService.PushNotificationStatusAsync(notification, notificationStatus);
}
}
}

View File

@@ -65,7 +65,7 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
await _pushNotificationService.PushSyncNotificationStatusAsync(notification, newNotificationStatus);
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
}
else
{
@@ -76,7 +76,7 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
await _notificationStatusRepository.UpdateAsync(notificationStatus);
await _pushNotificationService.PushSyncNotificationStatusAsync(notification, notificationStatus);
await _pushNotificationService.PushNotificationStatusAsync(notification, notificationStatus);
}
}
}

View File

@@ -48,6 +48,6 @@ public class UpdateNotificationCommand : IUpdateNotificationCommand
await _notificationRepository.ReplaceAsync(notification);
await _pushNotificationService.PushSyncNotificationAsync(notification);
await _pushNotificationService.PushNotificationAsync(notification);
}
}

View File

@@ -15,9 +15,8 @@ public class Notification : ITableObject<Guid>
public ClientType ClientType { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
[MaxLength(256)]
public string? Title { get; set; }
public string? Body { get; set; }
[MaxLength(256)] public string? Title { get; set; }
[MaxLength(3000)] public string? Body { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }

View File

@@ -182,14 +182,19 @@ public class NotificationHubPushNotificationService : IPushNotificationService
await PushAuthRequestAsync(authRequest, PushType.AuthRequestResponse);
}
public async Task PushSyncNotificationAsync(Notification notification)
public async Task PushNotificationAsync(Notification notification)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate
};
@@ -205,14 +210,19 @@ public class NotificationHubPushNotificationService : IPushNotificationService
}
}
public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus.DeletedDate

View File

@@ -24,8 +24,8 @@ public interface IPushNotificationService
Task PushSyncSendCreateAsync(Send send);
Task PushSyncSendUpdateAsync(Send send);
Task PushSyncSendDeleteAsync(Send send);
Task PushSyncNotificationAsync(Notification notification);
Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus);
Task PushNotificationAsync(Notification notification);
Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus);
Task PushAuthRequestAsync(AuthRequest authRequest);
Task PushAuthRequestResponseAsync(AuthRequest authRequest);

View File

@@ -165,28 +165,38 @@ public class AzureQueuePushNotificationService : IPushNotificationService
await PushSendAsync(send, PushType.SyncSendDelete);
}
public async Task PushSyncNotificationAsync(Notification notification)
public async Task PushNotificationAsync(Notification notification)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate
};
await SendMessageAsync(PushType.SyncNotification, message, true);
}
public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus.DeletedDate

View File

@@ -146,15 +146,15 @@ public class MultiServicePushNotificationService : IPushNotificationService
return Task.FromResult(0);
}
public Task PushSyncNotificationAsync(Notification notification)
public Task PushNotificationAsync(Notification notification)
{
PushToServices((s) => s.PushSyncNotificationAsync(notification));
PushToServices((s) => s.PushNotificationAsync(notification));
return Task.CompletedTask;
}
public Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
public Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{
PushToServices((s) => s.PushSyncNotificationStatusAsync(notification, notificationStatus));
PushToServices((s) => s.PushNotificationStatusAsync(notification, notificationStatus));
return Task.CompletedTask;
}

View File

@@ -172,28 +172,38 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
await PushSendAsync(send, PushType.SyncSendDelete);
}
public async Task PushSyncNotificationAsync(Notification notification)
public async Task PushNotificationAsync(Notification notification)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate
};
await SendMessageAsync(PushType.SyncNotification, message, true);
}
public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus.DeletedDate

View File

@@ -190,14 +190,19 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
await SendPayloadToUserAsync(authRequest.UserId, type, message, true);
}
public async Task PushSyncNotificationAsync(Notification notification)
public async Task PushNotificationAsync(Notification notification)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate
};
@@ -213,14 +218,19 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
}
}
public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{
var message = new SyncNotificationPushNotification
var message = new NotificationPushNotification
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,
RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus.DeletedDate

View File

@@ -106,7 +106,7 @@ public class NoopPushNotificationService : IPushNotificationService
return Task.FromResult(0);
}
public Task PushSyncNotificationAsync(Notification notification) => Task.CompletedTask;
public Task PushNotificationAsync(Notification notification) => Task.CompletedTask;
public Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus) => Task.CompletedTask;
public Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus) => Task.CompletedTask;
}