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: fixed git config route protection using fetchGlobalGitConfigInit… #34873

Merged

Conversation

Shivam-z
Copy link
Contributor

@Shivam-z Shivam-z commented Jul 11, 2024

Description:

In this PR I have fixed the GitConfig route dev.appsmtih.com/profile with the help of fetchGlobalGitConfigInit method.
Now If an unauthorized user try to access this URL , it will redirects to the login page.

Issue video

Screencast.from.11-07-24.02.37.08.PM.IST.webm

Solution video

Screencast.from.11-07-24.02.36.02.PM.IST.webm

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.

Fixes #34603

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added automatic fetching of global Git configuration when visiting the UserProfile page.
  • Refactor

    • Simplified imports and component logic in the UserProfile and GitConfig components for better maintainability.
  • Bug Fixes

    • Improved initialization behavior of the GitConfig component by removing redundant fetch operations.
  • Tests

    • Introduced unit tests for the UserProfile component to verify rendering behavior based on user authentication states.

Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

The changes across the UserProfile components primarily involve a refactoring of how the global Git configuration is fetched. The fetchGlobalGitConfigInit action is now triggered in General.tsx and UserProfile/index.tsx using useEffect hooks, while it has been removed from GitConfig.tsx. This reorganization alters the initialization sequence and may impact the loading behavior of Git configuration data in these components, addressing user authentication issues.

Changes

File Path Change Summary
app/client/src/pages/UserProfile/General.tsx, app/client/src/pages/UserProfile/index.tsx Added useEffect and useState imports; included useEffect to fetch global Git config on mount.
app/client/src/pages/UserProfile/GitConfig.tsx Removed fetchGlobalGitConfigInit import and useEffect block that fetched the global Git config.
app/client/src/pages/UserProfile/index.test.tsx Introduced unit tests for UserProfile component to validate rendering based on authentication state.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant GitConfig
    participant General

    User->>App: Navigate to UserProfile
    App->>General: fetchGlobalGitConfigInit()
    General-->>App: Render UserProfile with Git config
    User->>GitConfig: Attempt to access Git config
    GitConfig-->>User: Access granted if authenticated
    GitConfig-->>User: Redirect to Login if not authenticated
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure Git user config page requires user sign-in (#34603) The refactoring ensures that the UserProfile component checks user authentication before rendering.

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.
    • @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 as 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.

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

CodeRabbit Configuration 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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c48aaac and 1b8857f.

Files selected for processing (1)
  • app/client/src/pages/UserProfile/General.tsx (3 hunks)
Additional comments not posted (3)
app/client/src/pages/UserProfile/General.tsx (3)

1-1: Include useEffect with fetchGlobalGitConfigInit

The useEffect hook now ensures that the global Git configuration is fetched when the component mounts, which is crucial for security.

Ensure that fetchGlobalGitConfigInit correctly handles unauthorized access and redirects users to the login page if they are not authenticated.


22-22: Verify import of fetchGlobalGitConfigInit

The new import statement for fetchGlobalGitConfigInit from actions/gitSyncActions is necessary for fetching the global Git configuration.


74-78: Ensure useEffect dependency array is empty

The useEffect hook correctly fetches the global Git configuration on mount. Ensure the dependency array remains empty to avoid unnecessary re-renders.

@brayn003
Copy link
Contributor

Hey @Shivam-z
Thanks for raising this PR.
I think, having the fetchGlobalGitConfigInit logic present in both UserProfile/General.tsx and UserProfile/General.tsx would lead to unnecessary API calls.
I suggest, instead of putting this logic in UserProfile/General.tsx, we should put it in the parent component i.e. UserProfile/index.tsx. Additionally, we should remove the fetchGlobalGitConfigInit logic from the UserProfile/index.tsx page.
This way we should be able to avoid redundant api calls and also promote a DRY approach for better maintainability.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b8857f and eabb187.

Files selected for processing (2)
  • app/client/src/pages/UserProfile/GitConfig.tsx (2 hunks)
  • app/client/src/pages/UserProfile/index.tsx (4 hunks)
Additional comments not posted (3)
app/client/src/pages/UserProfile/index.tsx (2)

Line range hint 1-11: Imports are necessary and correct.

The added imports (useEffect, useState, useDispatch, and fetchGlobalGitConfigInit) are necessary for the new functionality.


51-54: useEffect hook correctly fetches global Git configuration.

The useEffect hook correctly dispatches fetchGlobalGitConfigInit on component mount.

app/client/src/pages/UserProfile/GitConfig.tsx (1)

Line range hint 1-16: Removed unnecessary import.

The removal of fetchGlobalGitConfigInit from the import statements is appropriate since the global Git configuration fetch logic has been moved to the parent component.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 15, 2024
@Shivam-z
Copy link
Contributor Author

Hi @brayn003 ,
Thanks for your feedaback. In this commit I have fix the reundant API calls by removing fetchGlobalGitConfigInit logic from UserProfile/General.tsx and UserProfile/GitConfig.tsx and putting it in Parent component.

@brayn003
Copy link
Contributor

Hi @Shivam-z, apologies for the late response. The logical changes look good to me.
Appreciate if you could add some unit test cases for this. Once done, I can start running the CI suite and proceed with the ci/merging process

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eabb187 and 38cd867.

Files selected for processing (1)
  • app/client/src/pages/UserProfile/index.test.tsx (1 hunks)
Additional comments not posted (5)
app/client/src/pages/UserProfile/index.test.tsx (5)

1-16: Imports look good.

All necessary libraries and modules for testing, Redux, theming, routing, and the UserProfile component are appropriately imported.


18-84: Mock store setup looks comprehensive.

The default state covers various entities and UI states required for the tests. Ensure that the state structure aligns with the actual application state.


86-93: Jest mocks are appropriate.

The jest mocks for design-system-old/build/constants/messages and actions/gitSyncActions are correctly set up to isolate the tests from external dependencies.


96-115: Test case for rendering UserProfile component looks good.

The test case correctly mocks the store state and verifies that the UserProfile component renders as expected for logged-in users.


117-132: Test case for rendering Login page looks good.

The test case correctly mocks the store state and verifies that the Login page renders as expected for non-logged-in users.

@Shivam-z
Copy link
Contributor Author

@brayn003 added unit test case

@brayn003
Copy link
Contributor

Let me trigger the tests

@brayn003
Copy link
Contributor

brayn003 commented Jul 29, 2024

CI tests here - #35249

@brayn003
Copy link
Contributor

All the CI tests are passing. Will merge this PR shortly

@hetunandu hetunandu merged commit ef83390 into appsmithorg:release Jul 30, 2024
15 checks passed
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.

[Bug]: Git user config page can be accessed without user signed in
3 participants