1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-16 01:51:21 +01:00

Added push notification for when Collection management settings have been changed. (#5230)

This commit is contained in:
Jared McCannon 2025-01-09 10:32:33 -06:00 committed by GitHub
parent e754ae4729
commit ced4870309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 72 additions and 0 deletions

View File

@ -802,6 +802,11 @@ public class OrganizationService : IOrganizationService
Description = organization.DisplayBusinessName()
});
}
if (eventType == EventType.Organization_CollectionManagement_Updated)
{
await _pushNotificationService.PushSyncOrganizationCollectionManagementSettingsAsync(organization);
}
}
public async Task UpdateTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type)

View File

@ -26,4 +26,5 @@ public enum PushType : byte
SyncOrganizations = 17,
SyncOrganizationStatusChanged = 18,
SyncOrganizationCollectionSettingChanged = 19,
}

View File

@ -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; }
}

View File

@ -238,6 +238,19 @@ public class NotificationHubPushNotificationService : IPushNotificationService
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)

View File

@ -233,4 +233,12 @@ public class AzureQueuePushNotificationService : IPushNotificationService
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);
}

View File

@ -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);
}

View File

@ -151,6 +151,12 @@ public class MultiServicePushNotificationService : IPushNotificationService
return Task.FromResult(0);
}
public Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization)
{
PushToServices(s => s.PushSyncOrganizationCollectionManagementSettingsAsync(organization));
return Task.CompletedTask;
}
private void PushToServices(Func<IPushNotificationService, Task> pushFunc)
{
if (_services != null)

View File

@ -94,6 +94,8 @@ public class NoopPushNotificationService : IPushNotificationService
return Task.FromResult(0);
}
public Task PushSyncOrganizationCollectionManagementSettingsAsync(Organization organization) => Task.CompletedTask;
public Task PushAuthRequestAsync(AuthRequest authRequest)
{
return Task.FromResult(0);

View File

@ -241,4 +241,13 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
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);
}

View File

@ -264,4 +264,17 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
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
);
}

View File

@ -92,6 +92,13 @@ public static class HubHelpers
await hubContext.Clients.Group($"Organization_{orgStatusNotification.Payload.OrganizationId}")
.SendAsync("ReceiveMessage", orgStatusNotification, cancellationToken);
break;
case PushType.SyncOrganizationCollectionSettingChanged:
var organizationCollectionSettingsChangedNotification =
JsonSerializer.Deserialize<PushNotificationData<OrganizationStatusPushNotification>>(
notificationJson, _deserializerOptions);
await hubContext.Clients.Group($"Organization_{organizationCollectionSettingsChangedNotification.Payload.OrganizationId}")
.SendAsync("ReceiveMessage", organizationCollectionSettingsChangedNotification, cancellationToken);
break;
default:
break;
}