Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-10600] Push notification with full notification center content #5086

Merged
merged 27 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a93d52a
PM-10600: Notification push notification
mzieniukbw Oct 21, 2024
00a9829
PM-10600: Sending to specific client types for relay push notifications
mzieniukbw Oct 22, 2024
2a07904
PM-10600: Sending to specific client types for other clients
mzieniukbw Oct 22, 2024
8ea69e8
PM-10600: Send push notification on notification creation
mzieniukbw Oct 22, 2024
28d5df9
PM-10600: Explicit group names
mzieniukbw Oct 22, 2024
61e1053
PM-10600: Id typos
mzieniukbw Oct 22, 2024
41b45e5
PM-10600: Revert global push notifications
mzieniukbw Oct 22, 2024
cc2d2c3
PM-10600: Added DeviceType claim
mzieniukbw Oct 22, 2024
5b46b56
PM-10600: Sent to organization typo
mzieniukbw Oct 22, 2024
b9ecf86
PM-10600: UT coverage
mzieniukbw Oct 22, 2024
ed810ea
PM-10600: Small refactor, UTs coverage
mzieniukbw Oct 22, 2024
5c09ca8
PM-10600: UTs coverage
mzieniukbw Oct 23, 2024
a88be80
PM-10600: Startup fix
mzieniukbw Oct 23, 2024
99ca476
PM-10600: Test fix
mzieniukbw Oct 23, 2024
07ec392
PM-10600: Required attribute, organization group for push notificatioโ€ฆ
mzieniukbw Oct 24, 2024
f1fd047
PM-10600: UT coverage
mzieniukbw Oct 24, 2024
66f3500
PM-10600: Fix Mobile devices not registering to organization push notโ€ฆ
mzieniukbw Nov 5, 2024
83aa75f
PM-10600: Unit Test coverage for NotificationHubPushRegistrationService
mzieniukbw Nov 5, 2024
7bdfd92
PM-10600: Unit Tests fix to NotificationHubPushRegistrationService afโ€ฆ
mzieniukbw Nov 20, 2024
41b1d64
PM-10600: Organization push notifications not sending to mobile devicโ€ฆ
mzieniukbw Nov 20, 2024
e9e33c0
PM-10600: Fix self-hosted organization notification not being receiveโ€ฆ
mzieniukbw Nov 20, 2024
3bc6025
PM-10600: Broken NotificationsController integration test
mzieniukbw Dec 18, 2024
246ca91
PM-10600: Merge conflicts fix
mzieniukbw Jan 13, 2025
abdd064
Merge branch 'main' into km/pm-10600
mzieniukbw Jan 15, 2025
4a7b99d
merge conflict fix
mzieniukbw Jan 15, 2025
02e45c3
PM-10600: Push notification with full notification center content.
mzieniukbw Nov 26, 2024
7e019d1
Merge branch 'main' into km/pm-10600-full-notification-content
mzieniukbw Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Core/Models/PushNotification.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
๏ปฟusing Bit.Core.Enums;
using Bit.Core.NotificationCenter.Enums;

namespace Bit.Core.Models;

Expand Down Expand Up @@ -45,14 +46,21 @@ public class SyncSendPushNotification
public DateTime RevisionDate { get; set; }
}

public class SyncNotificationPushNotification
#nullable enable
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; }
}
#nullable disable

public class AuthRequestPushNotification
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.Us

var newNotification = await _notificationRepository.CreateAsync(notification);

await _pushNotificationService.PushSyncNotificationAsync(newNotification);
await _pushNotificationService.PushNotificationAsync(newNotification);

return newNotification;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Core/NotificationCenter/Entities/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
public Guid? TaskId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,19 @@ public async Task PushAuthRequestResponseAsync(AuthRequest authRequest)
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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ public async Task PushSyncSendDeleteAsync(Send send)
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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IPushNotificationService
Task PushSyncSendCreateAsync(Send send);
Task PushSyncSendUpdateAsync(Send send);
Task PushSyncSendDeleteAsync(Send send);
Task PushSyncNotificationAsync(Notification notification);
Task PushNotificationAsync(Notification notification);
Task PushAuthRequestAsync(AuthRequest authRequest);
Task PushAuthRequestResponseAsync(AuthRequest authRequest);
Task PushSyncOrganizationStatusAsync(Organization organization);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization o
return Task.CompletedTask;
}

public Task PushSyncNotificationAsync(Notification notification)
public Task PushNotificationAsync(Notification notification)
{
PushToServices((s) => s.PushSyncNotificationAsync(notification));
PushToServices((s) => s.PushNotificationAsync(notification));
return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@
return Task.FromResult(0);
}

public Task PushSyncNotificationAsync(Notification notification) => Task.CompletedTask;
public Task PushNotificationAsync(Notification notification) => Task.CompletedTask;

Check warning on line 116 in src/Core/Platform/Push/Services/NoopPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/NoopPushNotificationService.cs#L116

Added line #L116 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,19 @@
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

Check warning on line 189 in src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs#L189

Added line #L189 was not covered by tests
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,

Check warning on line 194 in src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs#L192-L194

Added lines #L192 - L194 were not covered by tests
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,

Check warning on line 199 in src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/NotificationsApiPushNotificationService.cs#L197-L199

Added lines #L197 - L199 were not covered by tests
RevisionDate = notification.RevisionDate
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,19 @@
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

Check warning on line 196 in src/Core/Platform/Push/Services/RelayPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/RelayPushNotificationService.cs#L196

Added line #L196 was not covered by tests
{
Id = notification.Id,
Priority = notification.Priority,
Global = notification.Global,
ClientType = notification.ClientType,

Check warning on line 201 in src/Core/Platform/Push/Services/RelayPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/RelayPushNotificationService.cs#L199-L201

Added lines #L199 - L201 were not covered by tests
UserId = notification.UserId,
OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType,
Title = notification.Title,
Body = notification.Body,
CreationDate = notification.CreationDate,

Check warning on line 206 in src/Core/Platform/Push/Services/RelayPushNotificationService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Platform/Push/Services/RelayPushNotificationService.cs#L204-L206

Added lines #L204 - L206 were not covered by tests
RevisionDate = notification.RevisionDate
};

Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/HubHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
break;
case PushType.SyncNotification:
var syncNotification =
JsonSerializer.Deserialize<PushNotificationData<SyncNotificationPushNotification>>(
JsonSerializer.Deserialize<PushNotificationData<NotificationPushNotification>>(

Check warning on line 108 in src/Notifications/HubHelpers.cs

View check run for this annotation

Codecov / codecov/patch

src/Notifications/HubHelpers.cs#L108

Added line #L108 was not covered by tests
notificationJson, _deserializerOptions);
if (syncNotification.Payload.UserId.HasValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public async Task CreateAsync_Authorized_NotificationCreated(
Assert.Equal(notification.CreationDate, notification.RevisionDate);
await sutProvider.GetDependency<IPushNotificationService>()
.Received(1)
.PushSyncNotificationAsync(newNotification);
.PushNotificationAsync(newNotification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class NotificationHubPushNotificationServiceTests
[Theory]
[BitAutoData]
[NotificationCustomize]
public async void PushSyncNotificationAsync_Global_NotSent(
public async void PushNotificationAsync_Global_NotSent(
mzieniukbw marked this conversation as resolved.
Show resolved Hide resolved
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
{
await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await sutProvider.GetDependency<INotificationHubPool>()
.Received(0)
Expand All @@ -39,7 +39,7 @@ await sutProvider.GetDependency<IInstallationDeviceRepository>()
[BitAutoData(false)]
[BitAutoData(true)]
[NotificationCustomize(false)]
public async void PushSyncNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
public async void PushNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification)
{
Expand All @@ -51,7 +51,7 @@ public async void PushSyncNotificationAsync_UserIdProvidedClientTypeAll_SentToUs
notification.ClientType = ClientType.All;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);

await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
$"(template:payload_userId:{notification.UserId})");
Expand All @@ -70,7 +70,7 @@ await sutProvider.GetDependency<IInstallationDeviceRepository>()
[BitAutoData(true, ClientType.Web)]
[BitAutoData(true, ClientType.Mobile)]
[NotificationCustomize(false)]
public async void PushSyncNotificationAsync_UserIdProvidedClientTypeNotAll_SentToUser(bool organizationIdNull,
public async void PushNotificationAsync_UserIdProvidedClientTypeNotAll_SentToUser(bool organizationIdNull,
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification)
{
Expand All @@ -82,7 +82,7 @@ public async void PushSyncNotificationAsync_UserIdProvidedClientTypeNotAll_SentT
notification.ClientType = clientType;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);

await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
Expand All @@ -94,14 +94,14 @@ await sutProvider.GetDependency<IInstallationDeviceRepository>()
[Theory]
[BitAutoData]
[NotificationCustomize(false)]
public async void PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
public async void PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
{
notification.UserId = null;
notification.ClientType = ClientType.All;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);

await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
$"(template:payload && organizationId:{notification.OrganizationId})");
Expand All @@ -116,7 +116,7 @@ await sutProvider.GetDependency<IInstallationDeviceRepository>()
[BitAutoData(ClientType.Web)]
[BitAutoData(ClientType.Mobile)]
[NotificationCustomize(false)]
public async void PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
public async void PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification)
{
Expand All @@ -125,7 +125,7 @@ public async void PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClie

var expectedSyncNotification = ToSyncNotificationPushNotification(notification);

await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
Expand Down Expand Up @@ -206,13 +206,18 @@ await sutProvider.GetDependency<IInstallationDeviceRepository>()
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
}

private static SyncNotificationPushNotification ToSyncNotificationPushNotification(Notification notification) =>
private static NotificationPushNotification ToSyncNotificationPushNotification(Notification notification) =>
new()
{
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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class AzureQueuePushNotificationServiceTests
[BitAutoData]
[NotificationCustomize]
[CurrentContextCustomize]
public async void PushSyncNotificationAsync_Notification_Sent(
public async void PushNotificationAsync_Notification_Sent(
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
ICurrentContext currentContext)
{
currentContext.DeviceIdentifier.Returns(deviceIdentifier.ToString());
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
.GetService(Arg.Any<Type>()).Returns(currentContext);

await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await sutProvider.GetDependency<QueueClient>().Received(1)
.SendMessageAsync(Arg.Is<string>(message =>
Expand All @@ -43,23 +43,29 @@ await sutProvider.GetDependency<QueueClient>().Received(1)
private static bool MatchMessage<T>(PushType pushType, string message, IEquatable<T> expectedPayloadEquatable,
string contextId)
{
var pushNotificationData =
JsonSerializer.Deserialize<PushNotificationData<T>>(message);
var pushNotificationData = JsonSerializer.Deserialize<PushNotificationData<T>>(message);
return pushNotificationData != null &&
pushNotificationData.Type == pushType &&
expectedPayloadEquatable.Equals(pushNotificationData.Payload) &&
pushNotificationData.ContextId == contextId;
}

private class SyncNotificationEquals(Notification notification) : IEquatable<SyncNotificationPushNotification>
private class SyncNotificationEquals(Notification notification) : IEquatable<NotificationPushNotification>
{
public bool Equals(SyncNotificationPushNotification? other)
public bool Equals(NotificationPushNotification? other)
{
return other != null &&
other.Id == notification.Id &&
other.Priority == notification.Priority &&
other.Global == notification.Global &&
other.ClientType == notification.ClientType &&
other.UserId.HasValue == notification.UserId.HasValue &&
other.UserId == notification.UserId &&
other.OrganizationId.HasValue == notification.OrganizationId.HasValue &&
other.OrganizationId == notification.OrganizationId &&
other.ClientType == notification.ClientType &&
other.Title == notification.Title &&
other.Body == notification.Body &&
other.CreationDate == notification.CreationDate &&
other.RevisionDate == notification.RevisionDate;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class MultiServicePushNotificationServiceTests
[Theory]
[BitAutoData]
[NotificationCustomize]
public async Task PushSyncNotificationAsync_Notification_Sent(
public async Task PushNotificationAsync_Notification_Sent(
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
{
await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.Sut.PushNotificationAsync(notification);

await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First()
.Received(1)
.PushSyncNotificationAsync(notification);
.PushNotificationAsync(notification);
}

[Theory]
Expand Down
Loading