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

feat: captcha for invite user flow #31715

Merged
merged 25 commits into from Mar 18, 2024
Merged

Conversation

AnaghHegde
Copy link
Member

@AnaghHegde AnaghHegde commented Mar 13, 2024

Description

Add captcha for the invite user flow.

Fixes https://theappsmith.slack.com/archives/CGBPVEJ5C/p1710134091696379
#31789

Automation

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

🔍 Cypress test results

Important

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/8321963367
Commit: 769030f0a3deb09e256c38cba7d6d30a9a80a379
Cypress dashboard url: Click here!
All cypress tests have passed 🎉🎉🎉

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Integrated Google reCAPTCHA in the user invitation form to enhance security during form submissions.
  • Enhancements
    • Improved handling of URL parameters in utility functions for more robust data processing.

@AnaghHegde AnaghHegde self-assigned this Mar 13, 2024
Copy link
Contributor

coderabbitai bot commented Mar 13, 2024

Walkthrough

Walkthrough

The recent updates primarily focus on integrating Google reCAPTCHA into the user invitation process for enhanced security. This involves modifications across various files to handle the reCAPTCHA token, including adding necessary imports and logic for reCAPTCHA validation during form submission. Furthermore, the InviteUserRequest interface now supports an optional recaptchaToken field, and the URL parameter handling has been refined to improve the processing of object parameters.

Changes

Files Change Summary
.../workspace/InviteUsersForm.tsx Integrated Google reCAPTCHA; updated imports; added logic for reCAPTCHA token handling in form submission.
.../api/UserApi.tsx Added recaptchaToken field to InviteUserRequest; updated inviteUser for reCAPTCHA token URL parameter.
.../utils/URLUtils.ts Modified convertObjectToQueryParams to enhance object parameter processing.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@AnaghHegde
Copy link
Member Author

/build-deploy-preview skip-tests=true

@github-actions github-actions bot added the Enhancement New feature or request label Mar 13, 2024
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8259833023.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

@AnaghHegde AnaghHegde marked this pull request as draft March 13, 2024 05:16
Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

@appsmithorg appsmithorg deleted a comment from github-actions bot Mar 13, 2024
@AnaghHegde
Copy link
Member Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8262374710.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

Copy link

Failed server tests

  • com.appsmith.server.services.WorkspaceServiceTest#validUpdateWorkspaceValidWebsite

@AnaghHegde AnaghHegde marked this pull request as ready for review March 13, 2024 11:29
@AnaghHegde
Copy link
Member Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8263889038.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

Since the PR consists of changes on CE files, which has respective EE files on the EE repo, you will have to take care of those too. Else things won't work as expected on EE.

@ankitakinger ankitakinger added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 15, 2024
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8293970042.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

ankitakinger
ankitakinger previously approved these changes Mar 15, 2024
Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

@ankitakinger ankitakinger added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 15, 2024
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 16, 2024
@AnaghHegde
Copy link
Member Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8309461981.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 18, 2024
@rahulbarwal rahulbarwal added Templates Pod Issues related to Templates Templates Issues related to templates ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 18, 2024
Comment on lines +315 to +318
const recaptchaStatus = useScript(
`https://www.google.com/recaptcha/api.js?render=${googleRecaptchaSiteKey.apiKey}`,
AddScriptTo.HEAD,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of the useScript hook to dynamically load the Google reCAPTCHA script is a good practice for optimizing load times and ensuring the script is only loaded when necessary. However, as previously mentioned, adding error handling or a timeout mechanism could improve resilience and user experience in case the script fails to load or is delayed.

Consider enhancing the useScript hook to include error handling and a timeout mechanism. This could involve adding state variables to track loading errors and implementing a timeout to handle cases where the script loading is significantly delayed.

Comment on lines +418 to +441
const captchaWrappedInviteUsersSubmitHandler = handleSubmit(
async (values: any, dispatch: any) => {
try {
if (
googleRecaptchaSiteKey.enabled &&
recaptchaStatus === ScriptStatus.READY
) {
const token = await window.grecaptcha.execute(
googleRecaptchaSiteKey.apiKey,
{
action: "submit",
},
);

return inviteUsersSubmitHandler(values, dispatch, token);
} else {
return inviteUsersSubmitHandler(values, dispatch);
}
} catch (error) {
log.error(error);
throw error; // This will cause the form submission to fail
}
},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

The wrapping of the form submission handler with captcha verification logic is well-implemented. It conditionally includes the captcha token based on the reCAPTCHA configuration and script readiness. This approach ensures that the captcha verification step is integrated seamlessly into the form submission process.

However, the error handling in the catch block simply logs the error and rethrows it. While this is sufficient for debugging, it might not provide the best user experience in case of failures.

Consider adding user-friendly error handling in the catch block of the captchaWrappedInviteUsersSubmitHandler function. This could involve displaying a toast notification or updating the UI to inform the user about the issue, in addition to logging the error for debugging purposes.

Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

LGTM

@rahulbarwal
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8322859726.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 31715.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-31715.dp.appsmith.com

@AnaghHegde AnaghHegde merged commit 997fd96 into release Mar 18, 2024
49 of 51 checks passed
@AnaghHegde AnaghHegde deleted the feat/captcha-invite-user branch March 18, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request ok-to-test Required label for CI Templates Pod Issues related to Templates Templates Issues related to templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants