From 425b404558595b4bc093e2d3770b25d5a5dc892a Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Tue, 7 Jan 2025 14:16:43 -0600 Subject: [PATCH] Added push notification for when Collection management settings have been changed. --- .../Services/Implementations/OrganizationService.cs | 5 +++++ src/Core/Enums/PushType.cs | 1 + src/Core/Models/PushNotification.cs | 7 +++++++ .../NotificationHubPushNotificationService.cs | 13 +++++++++++++ src/Core/Services/IPushNotificationService.cs | 1 + .../AzureQueuePushNotificationService.cs | 8 ++++++++ .../MultiServicePushNotificationService.cs | 6 ++++++ .../NotificationsApiPushNotificationService.cs | 9 +++++++++ .../Implementations/RelayPushNotificationService.cs | 13 +++++++++++++ .../NoopPushNotificationService.cs | 2 ++ src/Notifications/HubHelpers.cs | 7 +++++++ 11 files changed, 72 insertions(+) diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs index 1cf22b23adbc..979f51fd7236 100644 --- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs +++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs @@ -801,6 +801,11 @@ public async Task UpdateAsync(Organization organization, bool updateBilling = fa Description = organization.DisplayBusinessName() }); } + + if (eventType == EventType.Organization_CollectionManagement_Updated) + { + await _pushNotificationService.PushSyncOrganizationCollectionManagementSettingsAsync(organization); + } } public async Task UpdateTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type) diff --git a/src/Core/Enums/PushType.cs b/src/Core/Enums/PushType.cs index 2030b855e239..ee1b59990f03 100644 --- a/src/Core/Enums/PushType.cs +++ b/src/Core/Enums/PushType.cs @@ -26,4 +26,5 @@ public enum PushType : byte SyncOrganizations = 17, SyncOrganizationStatusChanged = 18, + SyncOrganizationCollectionSettingChanged = 19, } diff --git a/src/Core/Models/PushNotification.cs b/src/Core/Models/PushNotification.cs index 667080580ed1..9907abcb65c4 100644 --- a/src/Core/Models/PushNotification.cs +++ b/src/Core/Models/PushNotification.cs @@ -56,3 +56,10 @@ public class OrganizationStatusPushNotification public Guid OrganizationId { get; set; } public bool Enabled { get; set; } } + +public class OrganizationCollectionManagementPushNotification +{ + public Guid OrganizationId { get; init; } + public bool LimitCollectionCreation { get; init; } + public bool LimitCollectionDeletion { get; init; } +} diff --git a/src/Core/NotificationHub/NotificationHubPushNotificationService.cs b/src/Core/NotificationHub/NotificationHubPushNotificationService.cs index 7438e812e0ba..70b835a01c1a 100644 --- a/src/Core/NotificationHub/NotificationHubPushNotificationService.cs +++ b/src/Core/NotificationHub/NotificationHubPushNotificationService.cs @@ -238,6 +238,19 @@ public async Task PushSyncOrganizationStatusAsync(Organization organization) await SendPayloadToOrganizationAsync(organization.Id, PushType.SyncOrganizationStatusChanged, message, false); } + public async Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => + await SendPayloadToOrganizationAsync( + organization.Id, + PushType.SyncOrganizationCollectionSettingChanged, + new OrganizationCollectionManagementPushNotification + { + OrganizationId = organization.Id, + LimitCollectionCreation = organization.LimitCollectionCreation, + LimitCollectionDeletion = organization.LimitCollectionDeletion + }, + false + ); + private string GetContextIdentifier(bool excludeCurrentContext) { if (!excludeCurrentContext) diff --git a/src/Core/Services/IPushNotificationService.cs b/src/Core/Services/IPushNotificationService.cs index 6e2e47e27fa5..2f7e6a609052 100644 --- a/src/Core/Services/IPushNotificationService.cs +++ b/src/Core/Services/IPushNotificationService.cs @@ -29,4 +29,5 @@ public interface IPushNotificationService Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier, string deviceId = null); Task PushSyncOrganizationStatusAsync(Organization organization); + Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization); } diff --git a/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs b/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs index 3daadebf3aa8..4f615537d514 100644 --- a/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs +++ b/src/Core/Services/Implementations/AzureQueuePushNotificationService.cs @@ -233,4 +233,12 @@ public async Task PushSyncOrganizationStatusAsync(Organization organization) await SendMessageAsync(PushType.SyncOrganizationStatusChanged, message, false); } + public async Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => + await SendMessageAsync(PushType.SyncOrganizationCollectionSettingChanged, + new OrganizationCollectionManagementPushNotification + { + OrganizationId = organization.Id, + LimitCollectionCreation = organization.LimitCollectionCreation, + LimitCollectionDeletion = organization.LimitCollectionDeletion + }, false); } diff --git a/src/Core/Services/Implementations/MultiServicePushNotificationService.cs b/src/Core/Services/Implementations/MultiServicePushNotificationService.cs index 185a11adbb80..45d2b28104d1 100644 --- a/src/Core/Services/Implementations/MultiServicePushNotificationService.cs +++ b/src/Core/Services/Implementations/MultiServicePushNotificationService.cs @@ -151,6 +151,12 @@ public Task PushSyncOrganizationStatusAsync(Organization organization) return Task.FromResult(0); } + public Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) + { + PushToServices(s => s.PushSyncOrganizationCollectionManagementSettingsAsync(organization)); + return Task.CompletedTask; + } + private void PushToServices(Func pushFunc) { if (_services != null) diff --git a/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs b/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs index feec75fbe086..ae93bce2d2bb 100644 --- a/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs +++ b/src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs @@ -239,4 +239,13 @@ public async Task PushSyncOrganizationStatusAsync(Organization organization) await SendMessageAsync(PushType.SyncOrganizationStatusChanged, message, false); } + + public async Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => + await SendMessageAsync(PushType.SyncOrganizationCollectionSettingChanged, + new OrganizationCollectionManagementPushNotification + { + OrganizationId = organization.Id, + LimitCollectionCreation = organization.LimitCollectionCreation, + LimitCollectionDeletion = organization.LimitCollectionDeletion + }, false); } diff --git a/src/Core/Services/Implementations/RelayPushNotificationService.cs b/src/Core/Services/Implementations/RelayPushNotificationService.cs index d72529677901..fd276d4f47a8 100644 --- a/src/Core/Services/Implementations/RelayPushNotificationService.cs +++ b/src/Core/Services/Implementations/RelayPushNotificationService.cs @@ -263,4 +263,17 @@ public async Task PushSyncOrganizationStatusAsync(Organization organization) await SendPayloadToOrganizationAsync(organization.Id, PushType.SyncOrganizationStatusChanged, message, false); } + + public async Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => + await SendPayloadToOrganizationAsync( + organization.Id, + PushType.SyncOrganizationCollectionSettingChanged, + new OrganizationCollectionManagementPushNotification + { + OrganizationId = organization.Id, + LimitCollectionCreation = organization.LimitCollectionCreation, + LimitCollectionDeletion = organization.LimitCollectionDeletion + }, + false + ); } diff --git a/src/Core/Services/NoopImplementations/NoopPushNotificationService.cs b/src/Core/Services/NoopImplementations/NoopPushNotificationService.cs index b5e2616220d7..ad122d42d3f5 100644 --- a/src/Core/Services/NoopImplementations/NoopPushNotificationService.cs +++ b/src/Core/Services/NoopImplementations/NoopPushNotificationService.cs @@ -94,6 +94,8 @@ public Task PushSyncOrganizationStatusAsync(Organization organization) return Task.FromResult(0); } + public Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => Task.CompletedTask; + public Task PushAuthRequestAsync(AuthRequest authRequest) { return Task.FromResult(0); diff --git a/src/Notifications/HubHelpers.cs b/src/Notifications/HubHelpers.cs index ce2e6b24adce..6f49822dc906 100644 --- a/src/Notifications/HubHelpers.cs +++ b/src/Notifications/HubHelpers.cs @@ -92,6 +92,13 @@ await hubContext.Clients.User(authRequestNotification.Payload.UserId.ToString()) await hubContext.Clients.Group($"Organization_{orgStatusNotification.Payload.OrganizationId}") .SendAsync("ReceiveMessage", orgStatusNotification, cancellationToken); break; + case PushType.SyncOrganizationCollectionSettingChanged: + var organizationCollectionSettingsChangedNotification = + JsonSerializer.Deserialize>( + notificationJson, _deserializerOptions); + await hubContext.Clients.Group($"Organization_{organizationCollectionSettingsChangedNotification.Payload.OrganizationId}") + .SendAsync("ReceiveMessage", organizationCollectionSettingsChangedNotification, cancellationToken); + break; default: break; }