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

fix: Input validations on page update API #32692

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

sharat87
Copy link
Member

@sharat87 sharat87 commented Apr 16, 2024

Slack thread with details. Not including details here.

Sanity passes on EE.

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

Warning

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/8704837594
Commit: fb1724a
Cypress dashboard url: Click here!
It seems like no tests ran 😔. We are not able to recognize it, please check workflow here.

Summary by CodeRabbit

  • New Features
    • Enhanced page update capabilities with new fields for page name, icon, and custom slug.
  • Improvements
    • Improved text handling support for non-Latin characters and punctuation in page names.
  • Tests
    • Added test cases for new page creation scenarios and page updates.

@github-actions github-actions bot added the Bug Something isn't working label Apr 16, 2024
Copy link

Failed server tests

  • com.appsmith.server.refactors.ce.RefactoringServiceCETest#refactorActionName

@sharat87 sharat87 added the ok-to-test Required label for CI label Apr 16, 2024
@sharat87 sharat87 marked this pull request as ready for review April 18, 2024 03:01
Copy link
Contributor

coderabbitai bot commented Apr 18, 2024

Walkthrough

Walkthrough

The recent update enhances page management in the Appsmith server by introducing the PageUpdateDTO class for more effective handling of page updates. This change involves updating method signatures across various files to accept PageUpdateDTO instead of PageDTO, refining text handling with improved regular expressions, and adding relevant test cases for better validation and data handling.

Changes

File Path Changes
.../controllers/ce/PageControllerCE.java
.../newpages/base/NewPageServiceCE.java
.../newpages/base/NewPageServiceCEImpl.java
Updated method signatures to accept PageUpdateDTO instead of PageDTO.
.../dtos/PageUpdateDTO.java Introduced PageUpdateDTO, a DTO for page updates with fields like page name and icon, and a conversion method to PageDTO.
.../helpers/TextUtils.java Updated regular expressions for text handling, improving non-Latin character and separator processing.
.../controllers/PageControllerTest.java Added test cases for new page creation scenarios, enhancing validation for page properties.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c4e424f and f9e5745.
Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/controllers/PageControllerTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/controllers/PageControllerTest.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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

mohanarpit
mohanarpit previously approved these changes Apr 18, 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: 1

public record PageUpdateDTO(
@Pattern(regexp = "[^/\\\\:]+", message = "/, \\, : not allowed in page names") @Size(max = 30) String name,
String icon,
@Pattern(regexp = "[-\\w]+") String customSlug) {
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The regex pattern for customSlug does not strictly enforce the intended restrictions of only allowing hyphens, word characters, and underscores. The test results indicate that it also matches characters like periods and asterisks, which should not be allowed. Here are the recommended actions:

  • Adjust the regex pattern to ^[-\w]+$ to ensure it only matches strings composed entirely of hyphens, word characters (alphanumeric and underscores), and does not allow other characters.
Analysis chain

Validate the regex pattern for customSlug to ensure it only allows hyphens, word characters, and underscores.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the regex pattern for 'customSlug' by testing it against various inputs.
echo -e "slug-1\nslug_2\nslug.3\nslug*4" | grep -P "[-\\w]+"

Length of output: 89

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharat87 is this suggestion from code rabbit worth looking at?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NilanshBansal, yep, already confirming it. My hunch is that its not valid, but am trying to see if I can add a test to verify this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we're good. The Spring validation checks for a match, not a find. What @coderabbitai verified with is with a find, not a match.

Just pushed additional test cases to verify this as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharat87, thank you for the clarification regarding the regex validation behavior in Spring. It's a valuable distinction between a complete match and a partial find, and I appreciate the additional test cases you've added to confirm this behavior. I'll keep this in mind for future reviews!


New Learnings Added
User: sharat87"
URL: https://github.com/appsmithorg/appsmith/pull/32692

Timestamp: 2024-04-18T04:23:38.058Z
Learning: In Spring validation, regex checks for a complete match (`match`) rather than finding a match within a string (`find`). This distinction affects how regex patterns are interpreted in validation scenarios.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

@sharat87 sharat87 merged commit dcada45 into release Apr 18, 2024
15 checks passed
@sharat87 sharat87 deleted the chore/update-page-validation branch April 18, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants