-
Notifications
You must be signed in to change notification settings - Fork 71
EPMRPP-109124 || Add AssignUserEvent for user assignment to projects #2461
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce event-driven notifications for user-to-project assignments by adding a new public constructor to AssignUserEvent that accepts User and Project parameters, marking event fields as final, and updating user invitation handlers to publish this event when creating project-user associations. Changes
Sequence DiagramsequenceDiagram
participant Handler as UserInvitationHandler
participant Event as AssignUserEvent
participant Publisher as Event Publisher
Handler->>Handler: assignProjects()
Handler->>Handler: Create & save ProjectUser
rect rgb(200, 220, 240)
Note over Handler,Publisher: NEW: Event-driven notification
Handler->>Event: new AssignUserEvent(user, project)
Event->>Event: Extract triggering user from SecurityContext
Event->>Event: Build UserActivityResource(user, project)
Event->>Publisher: Publish AssignUserEvent
end
Publisher->>Publisher: Process event listeners
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationServiceImpl.java (1)
215-217: Event publishing looks correct.The AssignUserEvent is properly created and published after the ProjectUser association is saved. This enables event-driven notifications for user-project assignments.
If you prefer more concise code, you could inline the variable:
- - AssignUserEvent assignUserEvent = new AssignUserEvent(user, projectEntity); - eventPublisher.publishEvent(assignUserEvent); + eventPublisher.publishEvent(new AssignUserEvent(user, projectEntity));src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandler.java (1)
244-245: Event publishing looks correct.The AssignUserEvent is properly created and published after the ProjectUser association is saved during invitation activation.
Consider inlining the variable for more concise code:
- AssignUserEvent assignUserEvent = new AssignUserEvent(createdUser, projectEntity); - eventPublisher.publishEvent(assignUserEvent); + eventPublisher.publishEvent(new AssignUserEvent(createdUser, projectEntity));src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java (1)
71-77: Consider caching the principal and verify null-safety.The new constructor implementation looks good overall, but there are a couple of minor concerns:
SecurityContextUtils.getPrincipal()is called twice (lines 72-73), which is unnecessary.- While unlikely in this flow, consider whether
project.getOrganizationId()could return null, which would assign null to a final field.Consider caching the principal:
public AssignUserEvent(User user, Project project) { - super(SecurityContextUtils.getPrincipal().getUserId(), - SecurityContextUtils.getPrincipal().getUsername()); + var principal = SecurityContextUtils.getPrincipal(); + super(principal.getUserId(), principal.getUsername()); this.isSystemEvent = false; this.userActivityResource = getUserActivityResource(user, project); this.orgId = project.getOrganizationId(); }Also, verify that
project.getOrganizationId()cannot return null in the contexts where this constructor is called.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java(3 hunks)src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandler.java(2 hunks)src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationServiceImpl.java(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationServiceImpl.java (1)
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java (1)
AssignUserEvent(37-111)
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandler.java (1)
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java (1)
AssignUserEvent(37-111)
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java (1)
src/main/java/com/epam/ta/reportportal/util/SecurityContextUtils.java (1)
SecurityContextUtils(28-54)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Call feature Docker build / Build and export to AWS ECR
- GitHub Check: Call Java Checks / Build check
🔇 Additional comments (7)
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationServiceImpl.java (1)
42-42: LGTM!Import is necessary for the new event-driven notification functionality.
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandler.java (1)
41-41: LGTM!Import is necessary for the new event-driven notification functionality.
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java (5)
29-32: LGTM!Imports are necessary for the new constructor functionality.
34-36: LGTM!Updated class documentation clearly describes the event's purpose.
40-40: Good practice: marking fields as final.Making these fields final improves immutability and makes the intent clearer.
Also applies to: 44-44
47-55: LGTM!Documentation for the existing constructor is clear and complete.
103-109: Verify: Is using login for fullName intentional?Line 107 sets the
fullNamefield ofUserActivityResourcetouser.getLogin()rather thanuser.getFullName(). This seems unusual and may not match the semantic meaning of the field.Please verify this is intentional. If the field should contain the user's full name, apply this diff:
private UserActivityResource getUserActivityResource(User user, Project project) { UserActivityResource userActivityResource = new UserActivityResource(); userActivityResource.setId(user.getId()); userActivityResource.setDefaultProjectId(project.getId()); - userActivityResource.setFullName(user.getLogin()); + userActivityResource.setFullName(user.getFullName()); return userActivityResource; }
Summary by CodeRabbit
Release Notes