forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V15: Notification Hub (umbraco#17776)
* Initial stab at how this could look * Authorization PoC wip * Add connection manager * Add DI to its own class * Use enum instead of string * Use groups * Refactor group management into its own service * Update a users groups when it's saved * Add saved events * Wire up deleted notifications * Ensure update date and create date is the same * Cleanup * Minor cleanup * Remove unusued usings * Move route to constant * Add docstrings to server event router * Fix and suppress warnings * Refactor to authorizer pattern * Update EventType * Remove unused enums * Add trashed events * Notify current user that they've been updated * Add broadcast We don't need it, but seems like a thing that a server event router should be able to do. * Add ServerEventRouterTests * Add ServerEventUserManagerTests * Use TimeProvider * Remove principal null check * Don't assign event type * Minor cleanup * Rename AuthorizedEventSources * Change permission for relations * Exctract event authorization into its own service * Add some tests * Update name * Add forgotten file * Rmember to add to DI
- Loading branch information
1 parent
7932eb9
commit aaad9c0
Showing
51 changed files
with
1,709 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/Umbraco.Cms.Api.Management/DependencyInjection/ServerEventExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Umbraco.Cms.Api.Management.ServerEvents; | ||
using Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
using Umbraco.Cms.Core.DependencyInjection; | ||
using Umbraco.Cms.Core.Notifications; | ||
using Umbraco.Cms.Core.ServerEvents; | ||
|
||
namespace Umbraco.Cms.Api.Management.DependencyInjection; | ||
|
||
internal static class ServerEventExtensions | ||
{ | ||
internal static IUmbracoBuilder AddServerEvents(this IUmbracoBuilder builder) | ||
{ | ||
builder.Services.AddSingleton<IUserConnectionManager, UserConnectionManager>(); | ||
builder.Services.AddSingleton<IServerEventRouter, ServerEventRouter>(); | ||
builder.Services.AddSingleton<IServerEventUserManager, ServerEventUserManager>(); | ||
builder.Services.AddSingleton<IServerEventAuthorizationService, ServerEventAuthorizationService>(); | ||
builder.AddNotificationAsyncHandler<UserSavedNotification, UserConnectionRefresher>(); | ||
|
||
builder | ||
.AddEvents() | ||
.AddAuthorizers(); | ||
|
||
return builder; | ||
} | ||
|
||
private static IUmbracoBuilder AddEvents(this IUmbracoBuilder builder) | ||
{ | ||
builder.AddNotificationAsyncHandler<ContentSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<ContentTypeSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MediaSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MediaTypeSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberTypeSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberGroupSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DataTypeSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<LanguageSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<ScriptSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<StylesheetSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<TemplateSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DictionaryItemSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DomainSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<PartialViewSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<PublicAccessEntrySavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<RelationSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<RelationTypeSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<UserGroupSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<UserSavedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<WebhookSavedNotification, ServerEventSender>(); | ||
|
||
builder.AddNotificationAsyncHandler<ContentDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<ContentTypeDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MediaDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MediaTypeDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberTypeDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MemberGroupDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DataTypeDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<LanguageDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<ScriptDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<StylesheetDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<TemplateDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DictionaryItemDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<DomainDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<PartialViewDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<PublicAccessEntryDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<RelationDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<RelationTypeDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<UserGroupDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<UserDeletedNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<WebhookDeletedNotification, ServerEventSender>(); | ||
|
||
builder.AddNotificationAsyncHandler<ContentMovedToRecycleBinNotification, ServerEventSender>(); | ||
builder.AddNotificationAsyncHandler<MediaMovedToRecycleBinNotification, ServerEventSender>(); | ||
|
||
return builder; | ||
} | ||
|
||
private static IUmbracoBuilder AddAuthorizers(this IUmbracoBuilder builder) | ||
{ | ||
builder.EventSourceAuthorizers() | ||
.Append<DocumentEventAuthorizer>() | ||
.Append<DocumentTypeEventAuthorizer>() | ||
.Append<MediaEventAuthorizer>() | ||
.Append<MediaTypeEventAuthorizer>() | ||
.Append<MemberEventAuthorizer>() | ||
.Append<MemberGroupEventAuthorizer>() | ||
.Append<MemberTypeEventAuthorizer>() | ||
.Append<DataTypeEventAuthorizer>() | ||
.Append<LanguageEventAuthorizer>() | ||
.Append<ScriptEventAuthorizer>() | ||
.Append<StylesheetEventAuthorizer>() | ||
.Append<TemplateEventAuthorizer>() | ||
.Append<DictionaryItemEventAuthorizer>() | ||
.Append<DomainEventAuthorizer>() | ||
.Append<PartialViewEventAuthorizer>() | ||
.Append<PublicAccessEntryEventAuthorizer>() | ||
.Append<RelationEventAuthorizer>() | ||
.Append<RelationTypeEventAuthorizer>() | ||
.Append<UserGroupEventAuthorizer>() | ||
.Append<UserEventAuthorizer>() | ||
.Append<WebhookEventAuthorizer>(); | ||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/DataTypeEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class DataTypeEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public DataTypeEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.DataType]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessDataTypes; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/DictionaryItemEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class DictionaryItemEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public DictionaryItemEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.DictionaryItem]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessDictionary; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/DocumentEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class DocumentEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public DocumentEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.Document]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessDocuments; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/DocumentTypeEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class DocumentTypeEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public DocumentTypeEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.DocumentType]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessDocumentTypes; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/DomainEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class DomainEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public DomainEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.Domain]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessDocuments; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/LanguageEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class LanguageEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public LanguageEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.Language]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessLanguages; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/MediaEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class MediaEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public MediaEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.Media]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessMediaOrMediaTypes; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/MediaTypeEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class MediaTypeEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public MediaTypeEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.MediaType]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessMediaTypes; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/MemberEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class MemberEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public MemberEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.Member]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessMembersOrMemberTypes; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/MemberGroupEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class MemberGroupEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public MemberGroupEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.MemberGroup]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessMemberGroups; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/ServerEvents/Authorizers/MemberTypeEventAuthorizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.ServerEvents.Authorizers; | ||
|
||
public class MemberTypeEventAuthorizer : EventSourcePolicyAuthorizer | ||
{ | ||
public MemberTypeEventAuthorizer(IAuthorizationService authorizationService) : base(authorizationService) | ||
{ | ||
} | ||
|
||
public override IEnumerable<string> AuthorizableEventSources => [Constants.ServerEvents.EventSource.MemberType]; | ||
|
||
protected override string Policy => AuthorizationPolicies.TreeAccessMemberTypes; | ||
} |
Oops, something went wrong.