Skip to content
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

chore: refactor the crud method to custom repo class #38137

Merged

Conversation

AnaghHegde
Copy link
Member

@AnaghHegde AnaghHegde commented Dec 12, 2024

Description

As part of transaction support in PG, we are moving from using the jpa methods for database operations. This PR is refactoring the code to use custom repository class for DatasourceRepository from the default CrudRepository.

Automation

/ok-to-test tags="@tag.ImportExport"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12304558211
Commit: d85d3ae
Cypress dashboard.
Tags: @tag.ImportExport
Spec:


Thu, 12 Dec 2024 21:15:06 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new method to retrieve action collections by application ID without requiring additional parameters.
  • Bug Fixes

    • Deprecated the previous method for fetching action collections that required more parameters, streamlining the querying process.
  • Documentation

    • Updated method signatures to reflect the new querying capabilities.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes introduce a new method findByApplicationId(String applicationId) to the CustomActionCollectionRepositoryCE interface, allowing retrieval of ActionCollection objects by application ID without needing additional parameters. The existing method signature that includes AclPermission and Sort is marked as deprecated but remains functional. The implementation class, CustomActionCollectionRepositoryCEImpl, has been updated to support this new method while maintaining the original functionality of existing methods. Additionally, the findByApplicationId method has been removed from the ActionCollectionRepositoryCE interface.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java Added method: Flux<ActionCollection> findByApplicationId(String applicationId)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java Added method: public Flux<ActionCollection> findByApplicationId(String applicationId)
Deprecated method: public Flux<ActionCollection> findByApplicationId(String applicationId, AclPermission aclPermission, Sort sort)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java Removed method: Flux<ActionCollection> findByApplicationId(String applicationId)

Possibly related PRs

  • chore: refactor crud to custom repository #38134: This PR involves refactoring the ApplicationRepositoryCE and moving methods to a custom repository, which relates to the changes in repository methods in the main PR, specifically the addition of new methods for fetching ActionCollection objects.

Suggested labels

ok-to-test

Suggested reviewers

  • abhvsn
  • sharat87

🎉 In the code where actions play,
A new method joins the fray!
Fetching collections with ease,
Simplifying queries, aiming to please.
Deprecated the old, but fear not,
For the new path is clear, and hits the spot! 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df9059c and d85d3ae.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java (0 hunks)
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 Dec 12, 2024
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

🧹 Outside diff range and nitpick comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java (2)

45-46: Add Javadoc to clarify method relationships.

Consider adding documentation to explain:

  1. The relationship between this method and its overloads
  2. When to use this version vs. the permission-aware versions
  3. Any security implications
+/**
+ * Finds ActionCollections by applicationId without explicit permission checks.
+ * Note: Prefer using permission-aware overloads unless specifically needed.
+ *
+ * @param applicationId the ID of the application
+ * @return Flux of ActionCollections
+ */
 Flux<ActionCollection> findByApplicationId(String applicationId);

Line range hint 13-46: Consider reordering methods for better readability.

Group related methods together:

  1. All findByApplicationId variants
  2. All findByPageId variants
  3. Other specialized finders
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java (1)

Line range hint 20-29: Add proper deprecation documentation.

The deprecated method should include Javadoc with @deprecated tag explaining the reason for deprecation and suggesting the migration path to the new method.

+    /**
+     * @deprecated Use {@link #findByApplicationId(String)} instead.
+     * This method will be removed in a future release.
+     */
     @Override
     @Deprecated
     public Flux<ActionCollection> findByApplicationId(String applicationId, AclPermission aclPermission, Sort sort) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ea5021 and df9059c.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java (1 hunks)
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java (1)

46-46: ⚠️ Potential issue

Verify permission handling in the new method implementation.

The new method bypasses the explicit permission check present in other similar methods. Ensure this is intentional and doesn't create security vulnerabilities.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java (1)

172-176: Verify security implications of removing permission checks.

The new method doesn't include permission checks that were present in the deprecated version. Please confirm if this is intentional and doesn't introduce security vulnerabilities.

✅ Verification successful

Let me analyze the permission check patterns in the codebase with these broader searches to verify the security implications.


Permission check removal is intentional and safe

The implementation is correct as this method serves as a basic repository query without permission checks, while the interface provides other methods with permission checks for secured operations:

  • findByApplicationId(String, AclPermission, Sort) - deprecated but with permissions
  • findByApplicationId(String, Optional<AclPermission>, Optional<Sort>) - flexible permission checks
  • The new method is meant for internal repository operations where permissions are handled at the service layer
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for permission checks in similar repository methods
ast-grep --pattern 'public Flux<$_> find$_($_) {
  $$$
  .permission($_)
  $$$
}'

Length of output: 83


Script:

#!/bin/bash
# Search for similar repository methods with permission checks using a broader pattern
rg -U "public\s+Flux<.*?>\s+find.*?\(.*?\).*?\{[\s\S]*?permission.*?\}" --type java

# Search for the deprecated version of this method
rg -U "findByApplicationId.*?deprecated" --type java -A 10

# Look for permission checks in the base class or interface
fd "CustomActionCollectionRepository" --type f --exec rg -l "permission|PermissionGroup" {}

Length of output: 482


Script:

#!/bin/bash
# Let's examine the content of these repository files to understand the permission handling
cat ./app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java

# Also check the implementation file
cat ./app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java

# Search for any service layer that might be using this repository method
rg -U "findByApplicationId.*?ActionCollection" --type java -A 5

Length of output: 10369

Copy link

Failed server tests

  • com.appsmith.server.services.ce.ApplicationServiceCETest#cloneApplication_WithCustomSavedTheme_ThemesAlsoCopied

@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Dec 12, 2024
@AnaghHegde AnaghHegde merged commit 1f2a4aa into release Dec 13, 2024
51 checks passed
@AnaghHegde AnaghHegde deleted the chore/refactor-crud-to-custom-repository-action-collection branch December 13, 2024 09:10
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
## Description
As part of transaction support in PG, we are moving from using the jpa
methods for database operations. This PR is refactoring the code to use
custom repository class for DatasourceRepository from the default
CrudRepository.

## Automation

/ok-to-test tags="@tag.ImportExport"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12304558211>
> Commit: d85d3ae
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12304558211&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport`
> Spec:
> <hr>Thu, 12 Dec 2024 21:15:06 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new method to retrieve action collections by application
ID without requiring additional parameters.

- **Bug Fixes**
- Deprecated the previous method for fetching action collections that
required more parameters, streamlining the querying process.

- **Documentation**
	- Updated method signatures to reflect the new querying capabilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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