Skip to content

chore: Dynamically fetch system generated users via DB query #40323

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

Merged
merged 4 commits into from
Apr 22, 2025

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Apr 21, 2025

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

/test Settings

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14586059630
Commit: 12091dc
Cypress dashboard.
Tags: @tag.Settings
Spec:


Tue, 22 Apr 2025 03:49:21 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Improved retrieval of system-generated user emails to support dynamic, real-time updates.
  • Bug Fixes
    • Enhanced accuracy in identifying and excluding system-generated users.
  • Tests
    • Added integration tests to verify correct behavior when fetching system-generated user emails.
  • Chores
    • Introduced a new immutable data structure for handling email information.

Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

A new immutable Java record, EmailOnly, was introduced to encapsulate email addresses. The getSystemGeneratedUserEmails method in the custom user repository was refactored from a synchronous set-based approach to a reactive Flux-based stream, with corresponding updates to its implementation and usage. Tests were added to verify the new reactive behavior, ensuring correct retrieval of system-generated user emails from the repository.

Changes

Files/Paths Change Summary
.../projections/EmailOnly.java Added new Java record EmailOnly with a single non-null String email field.
.../repositories/ce/CustomUserRepositoryCE.java Updated method signature: getSystemGeneratedUserEmails() now returns Flux<String> instead of Set<String>.
.../repositories/ce/CustomUserRepositoryCEImpl.java Refactored getSystemGeneratedUserEmails to return a reactive stream, updated related logic for dynamic querying and filtering based on isSystemGenerated field.
.../repositories/ce/CustomUserRepositoryCEImplTest.java Added new integration test class for verifying the reactive retrieval of system-generated user emails and user existence checks.

Sequence Diagram(s)

sequenceDiagram
    participant Test as CustomUserRepositoryCEImplTest
    participant Repo as CustomUserRepositoryCEImpl
    participant DB as Database

    Test->>Repo: getSystemGeneratedUserEmails(organizationId)
    Repo->>DB: Query users where isSystemGenerated = true and organizationId matches
    DB-->>Repo: Return matching user emails
    Repo-->>Test: Flux<String> of system-generated emails
Loading

Poem

📨
A record for email, concise and neat,
Now streams of addresses, reactive and fleet!
Tests ensure the logic is sound,
System users’ emails easily found.
With Flux in the flow and records in tow,
The codebase continues to grow!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4b741db and 12091dc.

📒 Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImplTest.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImplTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCE.java
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: server-spotless / spotless-check
  • GitHub Check: server-unit-tests / server-unit-tests
🔇 Additional comments (6)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImpl.java (6)

8-8: New import supports email projection pattern

Adding the EmailOnly projection import aligns with best practices for retrieving only the data fields needed, improving query efficiency.


13-13: Appropriate reactive import for method refactoring

The addition of the Flux import properly supports the method signature change in getSystemGeneratedUserEmails.


16-16: Good use of static import

Using static import for notExists improves code readability in the query criteria.


28-30: Updated comment accurately reflects implementation change

The comment now correctly describes the filtering approach used in the method implementation.


38-39: Improved query logic for handling system-generated users

The updated implementation correctly handles both cases:

  1. Documents where isSystemGenerated doesn't exist
  2. Documents where isSystemGenerated is explicitly false

This maintains backward compatibility while providing a more direct filtering approach.


47-53: Effective refactoring to reactive DB query

The change from returning a static set to a reactive database query is a significant improvement:

  1. Makes the code more maintainable by removing hardcoded values
  2. Follows reactive programming principles with Flux
  3. Uses appropriate projection to retrieve only needed fields
  4. Correctly filters by organization ID for proper data isolation

This change will make it easier to manage system-generated users going forward.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Apr 21, 2025
@abhvsn abhvsn added the ok-to-test Required label for CI label Apr 21, 2025
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)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImpl.java (1)

34-39: Consider performance optimization for isUsersEmpty

The current implementation makes two sequential database queries - first collecting all system-generated emails, then querying for non-system users. This could be inefficient with a large number of system users.

Consider a single query approach:

@Override
public Mono<Boolean> isUsersEmpty() {
-   return getSystemGeneratedUserEmails().collectList().flatMap(systemGeneratedUserEmails -> queryBuilder()
-           .criteria(Bridge.notIn(User.Fields.email, systemGeneratedUserEmails))
-           .limit(1)
-           .all(IdOnly.class)
-           .count()
-           .map(count -> count == 0));
+   return queryBuilder()
+           .criteria(Bridge.equal(User.Fields.isSystemGenerated, false))
+           .limit(1)
+           .all(IdOnly.class)
+           .count()
+           .map(count -> count == 0);
}
app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImplTest.java (2)

26-26: Consider making constant private

The PREDEFINED_SYSTEM_USERS constant is only used internally in this test class.

-   private static final Set<String> PREDEFINED_SYSTEM_USERS = Set.of("anonymousUser");
+   private static final Set<String> PREDEFINED_SYSTEM_USERS = Set.of("anonymousUser");

40-71: Comprehensive test for system user emails

This test covers the case when both system and non-system users exist, with proper assertions.

Consider using non-blocking approaches for test setup/teardown:

-   User savedSystemUser = userRepository.save(systemUser).block();
+   User savedSystemUser = userRepository.save(systemUser)
+           .doOnNext(savedUsers::add)
+           .block();
-   savedUsers.add(savedSystemUser);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c580cfd and 58c4c78.

📒 Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/projections/EmailOnly.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImplTest.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (8)
app/server/appsmith-server/src/main/java/com/appsmith/server/projections/EmailOnly.java (1)

1-5: Well-designed record for email projection

This is a clean implementation of a Java record for email projection with proper null-safety using @NonNull. Records provide an excellent way to handle database projections with minimal boilerplate.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCE.java (2)

6-6: Appropriate import for reactive Flux

Added import for Reactor's Flux class to support the updated method signature.


15-15: Good migration to reactive return type

Changing from Set<String> to Flux<String> aligns with the repository's reactive pattern, enabling non-blocking database operations.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImpl.java (3)

8-8: Required import for EmailOnly projection

Import added for the new EmailOnly projection class.


13-13: Flux import for reactive streams

Import added for Reactor's Flux class to support the reactive implementation.


43-48: Good implementation of reactive database query

The implementation correctly fetches system-generated users dynamically from the database instead of using hardcoded values. The use of projection and method reference mapping is efficient and follows reactive best practices.

app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/CustomUserRepositoryCEImplTest.java (2)

28-38: Proper test setup and teardown

The setup and cleanup methods are well-implemented to ensure test isolation.


73-93: Well-structured negative test case

This test properly verifies that only predefined system users are returned when no additional system users exist.

@abhvsn abhvsn requested a review from nsarupr April 21, 2025 08:25
@abhvsn abhvsn merged commit 988537f into release Apr 22, 2025
43 checks passed
@abhvsn abhvsn deleted the fix/remove-appsmith-bot-users-from-seat-count branch April 22, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants