From 13a53caf43394f6ecb31cbb618eee90838606c66 Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 11:27:56 +0800 Subject: [PATCH 1/6] Implement PermissionEventBase for permission management context propagation --- .../PermissionEventBase.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Aevatar.PermissionManagement/PermissionEventBase.cs diff --git a/src/Aevatar.PermissionManagement/PermissionEventBase.cs b/src/Aevatar.PermissionManagement/PermissionEventBase.cs new file mode 100644 index 00000000..3c4d233b --- /dev/null +++ b/src/Aevatar.PermissionManagement/PermissionEventBase.cs @@ -0,0 +1,49 @@ +using Aevatar.Core.Abstractions; + +namespace Aevatar.PermissionManagement; + +/// +/// Base class for permission-related events that carry user context information. +/// This class provides a foundation for events that need to propagate user context +/// throughout the permission management system. +/// +[GenerateSerializer] +public abstract class PermissionEventBase : EventBase +{ + /// + /// Gets or sets the user context associated with this permission event. + /// This context contains user identification, roles, and other security-related information. + /// + [Id(2)] public UserContext? UserContext { get; set; } + + /// + /// Initializes a new instance of the PermissionEventBase class. + /// + protected PermissionEventBase() + { + } + + /// + /// Initializes a new instance of the PermissionEventBase class with the specified user context. + /// + /// The user context to associate with this event. + protected PermissionEventBase(UserContext? userContext) + { + UserContext = userContext; + } + + /// + /// Gets a value indicating whether this event has a valid user context. + /// + public bool HasUserContext => UserContext != null; + + /// + /// Gets the user ID from the user context, or null if no context is available. + /// + public Guid? UserId => UserContext?.UserId; + + /// + /// Gets the user roles from the user context, or an empty array if no context is available. + /// + public string[] UserRoles => UserContext?.Roles ?? Array.Empty(); +} \ No newline at end of file From bdbef38b9f7329a7eb1d339df9c8af1171b6e954 Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 11:29:10 +0800 Subject: [PATCH 2/6] Update project tracker with PermissionEventBase completion status --- ai/project_tracker.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ai/project_tracker.md b/ai/project_tracker.md index a4fa4ada..22584516 100644 --- a/ai/project_tracker.md +++ b/ai/project_tracker.md @@ -15,6 +15,7 @@ This document tracks the remaining tasks and their status for the Aevatar Framew | Feature | Status | Description | Unit Tests | Regression Tests | Integration Tests | Documentation | Dev Machine | |---------|--------|-------------|------------|------------------|-------------------|---------------|------------| +| PermissionEventBase | ✅ Completed | Implement PermissionEventBase class inheriting from EventBase with UserContext for permission management events | ✓ | ✗ | ✗ | ✓ | c6:c4:e5:e8:c6:4c | | ExceptionCatchAndPublish | 🚧 In Progress | Implement mechanism to catch GAgent EventHandler exceptions and publish them to Orleans Stream | ✗ | ✗ | ✗ | ✗ | 62:84:7a:e8:0f:65 | | Kafka Stream optimization | Not Started | Optimize Kafka streams for better performance and lower resource usage | ✗ | ✗ | ✗ | ✗ | | | End to end gagent streaming | Not Started | Implement complete end-to-end streaming for gagent | ✗ | ✗ | ✗ | ✗ | | @@ -92,7 +93,7 @@ This document tracks the remaining tasks and their status for the Aevatar Framew - *To be determined* ## Completed Tasks -- *None recorded yet* +- **PermissionEventBase** (2024-01-XX): Implemented abstract base class for permission-related events with UserContext propagation. Includes comprehensive documentation and follows Orleans serialization patterns. ## Notes - Update this tracker regularly as tasks progress From 45de7bb884450a2a6f63a9d7b339a713efe2241e Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 11:32:26 +0800 Subject: [PATCH 3/6] Simplify PermissionEventBase by removing redundant helper methods and excessive documentation --- .../PermissionEventBase.cs | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/Aevatar.PermissionManagement/PermissionEventBase.cs b/src/Aevatar.PermissionManagement/PermissionEventBase.cs index 3c4d233b..30cb7de3 100644 --- a/src/Aevatar.PermissionManagement/PermissionEventBase.cs +++ b/src/Aevatar.PermissionManagement/PermissionEventBase.cs @@ -2,48 +2,8 @@ namespace Aevatar.PermissionManagement; -/// -/// Base class for permission-related events that carry user context information. -/// This class provides a foundation for events that need to propagate user context -/// throughout the permission management system. -/// [GenerateSerializer] public abstract class PermissionEventBase : EventBase { - /// - /// Gets or sets the user context associated with this permission event. - /// This context contains user identification, roles, and other security-related information. - /// [Id(2)] public UserContext? UserContext { get; set; } - - /// - /// Initializes a new instance of the PermissionEventBase class. - /// - protected PermissionEventBase() - { - } - - /// - /// Initializes a new instance of the PermissionEventBase class with the specified user context. - /// - /// The user context to associate with this event. - protected PermissionEventBase(UserContext? userContext) - { - UserContext = userContext; - } - - /// - /// Gets a value indicating whether this event has a valid user context. - /// - public bool HasUserContext => UserContext != null; - - /// - /// Gets the user ID from the user context, or null if no context is available. - /// - public Guid? UserId => UserContext?.UserId; - - /// - /// Gets the user roles from the user context, or an empty array if no context is available. - /// - public string[] UserRoles => UserContext?.Roles ?? Array.Empty(); -} \ No newline at end of file +} \ No newline at end of file From 45924840408bd92e9fbe7e478672df6e7432d025 Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 14:14:28 +0800 Subject: [PATCH 4/6] refactor: optimize serialization ID in PermissionEventBase --- src/Aevatar.PermissionManagement/PermissionEventBase.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Aevatar.PermissionManagement/PermissionEventBase.cs b/src/Aevatar.PermissionManagement/PermissionEventBase.cs index 30cb7de3..7581fcca 100644 --- a/src/Aevatar.PermissionManagement/PermissionEventBase.cs +++ b/src/Aevatar.PermissionManagement/PermissionEventBase.cs @@ -2,8 +2,13 @@ namespace Aevatar.PermissionManagement; +public interface IPermissionEvent +{ + UserContext? UserContext { get; set; } +} + [GenerateSerializer] -public abstract class PermissionEventBase : EventBase +public abstract class PermissionEventBase : EventBase, IPermissionEvent { - [Id(2)] public UserContext? UserContext { get; set; } + [Id(0)] public UserContext? UserContext { get; set; } } \ No newline at end of file From 4c5501ace0d9f764c2eef30d1b68b9aa2077d322 Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 14:18:54 +0800 Subject: [PATCH 5/6] feat: initialize UserContext in PermissionEventBase constructor --- src/Aevatar.PermissionManagement/PermissionEventBase.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Aevatar.PermissionManagement/PermissionEventBase.cs b/src/Aevatar.PermissionManagement/PermissionEventBase.cs index 7581fcca..dafab56e 100644 --- a/src/Aevatar.PermissionManagement/PermissionEventBase.cs +++ b/src/Aevatar.PermissionManagement/PermissionEventBase.cs @@ -10,5 +10,10 @@ public interface IPermissionEvent [GenerateSerializer] public abstract class PermissionEventBase : EventBase, IPermissionEvent { + protected PermissionEventBase() + { + UserContext = new UserContext(); + } + [Id(0)] public UserContext? UserContext { get; set; } } \ No newline at end of file From 96f5cccbc122d32cd4ab7ae6e53f0ef3927a6544 Mon Sep 17 00:00:00 2001 From: t0wnsend Date: Thu, 19 Jun 2025 14:19:51 +0800 Subject: [PATCH 6/6] refactor: simplify UserContext initialization using property initializer --- src/Aevatar.PermissionManagement/PermissionEventBase.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Aevatar.PermissionManagement/PermissionEventBase.cs b/src/Aevatar.PermissionManagement/PermissionEventBase.cs index dafab56e..da9e7de3 100644 --- a/src/Aevatar.PermissionManagement/PermissionEventBase.cs +++ b/src/Aevatar.PermissionManagement/PermissionEventBase.cs @@ -10,10 +10,5 @@ public interface IPermissionEvent [GenerateSerializer] public abstract class PermissionEventBase : EventBase, IPermissionEvent { - protected PermissionEventBase() - { - UserContext = new UserContext(); - } - - [Id(0)] public UserContext? UserContext { get; set; } + [Id(0)] public UserContext? UserContext { get; set; } = new(); } \ No newline at end of file