Skip to content

Conversation

@grabsefx
Copy link
Contributor

@grabsefx grabsefx commented Oct 31, 2025

Summary by CodeRabbit

Release Notes

  • Refactor
    • Enhanced event tracking when assigning users to projects, ensuring activity is consistently recorded across all user assignment operations.

@grabsefx grabsefx requested a review from pbortnik as a code owner October 31, 2025 13:35
@grabsefx grabsefx self-assigned this Oct 31, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Walkthrough

The 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

Cohort / File(s) Summary
Event Enhancement
src/main/java/com/epam/ta/reportportal/core/events/activity/AssignUserEvent.java
Added public constructor accepting User and Project parameters; marked userActivityResource and orgId fields as final; added private helper method getUserActivityResource() to construct UserActivityResource; added imports for Project, User, and SecurityContextUtils
Event Publishing
src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandler.java, src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationServiceImpl.java
Added AssignUserEvent import and event publishing logic after ProjectUser creation/persistence in assignProjects method; events are published with created user and project entity

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • New constructor logic is straightforward with clear responsibility
  • Event publishing follows consistent pattern across both handler files
  • Field finalization is a simple alignment change
  • Consider verifying that SecurityContext is properly accessible in the new constructor context

Suggested reviewers

  • pbortnik

Poem

🐰 A rabbit hops with glee today,
Events now guide users their way,
When projects assign without delay,
Our final fields here come to stay,
A cleaner flow, hip-hip-hooray!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add AssignUserEvent for user assignment to projects" directly reflects the primary behavioral changes in the pull request. The changes extend the AssignUserEvent class with a new constructor and introduce event publishing in two user-project assignment flows (UserInvitationHandler and UserInvitationServiceImpl). The title accurately captures that the PR implements event-driven functionality for user assignment to projects. While it doesn't enumerate every implementation detail (such as the new constructor signature or final field changes), the title is specific enough and directly related to the main change, allowing a developer scanning the history to understand the core purpose of the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch EPMRPP-109124

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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:

  1. SecurityContextUtils.getPrincipal() is called twice (lines 72-73), which is unnecessary.
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d061ad and 41d9e2b.

📒 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 fullName field of UserActivityResource to user.getLogin() rather than user.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;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant