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

[WEB-2346] chore: add authorization to restore version #5444

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

aaryan610
Copy link
Collaborator

@aaryan610 aaryan610 commented Aug 28, 2024

Improvements:

Added authorization to restore to a version, similar to the edit access to a page.

Plane issue: WEB-2346

Summary by CodeRabbit

  • New Features

    • Introduced a new prop, pageId, to enhance page detail retrieval in the editor component.
    • Added restoreEnabled prop to control restoration functionality and improve UI behavior based on content editability.
    • Enhanced PageVersionsOverlay component with reactive capabilities to respond to observable state changes.
  • Bug Fixes

    • Improved the logic for determining the initial value of the document editor, ensuring consistent data flow.
  • Refactor

    • Updated component structures for better clarity and maintainability, aligning with new prop requirements.

Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

The changes across several components primarily involve the addition of new properties, such as pageId and restoreEnabled, which enhance the functionality and responsiveness of the components. Modifications include adjustments to how props are handled, particularly in the retrieval of page details and the control of restoration processes. The use of MobX's observer functionality in some components enables reactive updates based on observable state changes.

Changes

Files Change Summary
web/ce/components/pages/version/editor.tsx Added pageId prop to Props, updated usePage hook usage, and modified initialValue retrieval logic.
web/core/components/pages/editor/page-root.tsx Enhanced PageRoot component by adding isContentEditable prop to control editing capabilities.
web/core/components/pages/version/main-content.tsx Introduced restoreEnabled prop to control restoration logic and modified rendering for the restore button.
web/core/components/pages/version/root.tsx Wrapped PageVersionsOverlay with observer, added restoreEnabled prop, enhancing interactivity.

Poem

🐇 In the garden where changes bloom,
New props sprout, dispelling gloom.
With pageId and restore in hand,
Our components now dance, oh so grand!
Watch them react, swift as a breeze,
A joyful hop through code with ease! 🌼✨


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

Outside diff range, codebase verification and nitpick comments (1)
web/ce/components/pages/version/editor.tsx (1)

Line range hint 18-100: Review the integration of pageId and changes in data handling.

The addition of pageId to Props and its subsequent usage in the usePage hook is a significant improvement, streamlining the component's data retrieval process. This change makes the component less reliant on the useParams hook, which can lead to clearer and more manageable code.

However, ensure that the new data flow, especially the use of currentPageDetails for determining the initialValue of the DocumentReadOnlyEditorWithRef, is thoroughly tested. This is crucial as it affects the core functionality of the editor component.

The changes are approved, but thorough testing is recommended to ensure the integrity of the new data flow.

Would you like assistance in setting up additional unit tests to cover these changes?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9372677 and 8aa8cdb.

Files selected for processing (4)
  • web/ce/components/pages/version/editor.tsx (2 hunks)
  • web/core/components/pages/editor/page-root.tsx (2 hunks)
  • web/core/components/pages/version/main-content.tsx (4 hunks)
  • web/core/components/pages/version/root.tsx (4 hunks)
Additional comments not posted (4)
web/core/components/pages/version/root.tsx (1)

Line range hint 20-62: Ensure proper integration of MobX's observer and usage of restoreEnabled.

The wrapping of PageVersionsOverlay with MobX's observer is correctly implemented, ensuring that the component reacts to observable state changes. The new restoreEnabled prop is appropriately destructured and used within the component, enhancing its conditional rendering capabilities based on this state.

However, ensure that all child components that receive restoreEnabled as a prop are also properly handling it. This is crucial for maintaining consistent behavior across the component hierarchy.

The changes are approved, but verify the downstream usage of restoreEnabled.

Verification successful

restoreEnabled is properly integrated and used in child components. The restoreEnabled prop is correctly utilized in the PageVersionsMainContent component to control the restore functionality, ensuring that actions are only enabled when appropriate. Its absence in PageVersionsSidebarRoot aligns with its intended usage, confirming consistent and correct integration across components.

  • PageVersionsMainContent uses restoreEnabled to conditionally enable restore actions.
  • PageVersionsSidebarRoot does not require restoreEnabled, as indicated by the absence of its usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all child components handle `restoreEnabled` correctly.

# Test: Search for the usage of `restoreEnabled` in child components. Expect: Proper handling in each component.
rg --type typescript -A 5 $'restoreEnabled'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify all child components handle `restoreEnabled` correctly.

# Test: Search for the usage of `restoreEnabled` in .tsx and .ts files. Expect: Proper handling in each component.
rg --glob '*.tsx' --glob '*.ts' -A 5 'restoreEnabled'

Length of output: 3641

web/core/components/pages/version/main-content.tsx (1)

Line range hint 20-109: Validate the conditional logic and integration of restoreEnabled.

The integration of restoreEnabled into PageVersionsMainContent is well-executed, effectively controlling the restoration process based on this boolean prop. The early exit in handleRestoreVersion when restoreEnabled is false is a good practice, preventing unauthorized actions.

Additionally, the conditional rendering of the restore button based on restoreEnabled and the version status is a smart UI decision, enhancing the user experience by displaying relevant options only.

Ensure that the rest of the application respects this new prop, particularly in scenarios where restoreEnabled might be dynamically changed based on user permissions or other conditions.

The changes are approved, but verify the broader application context for restoreEnabled.

Verification successful

Integration of restoreEnabled is consistent across the application.

The restoreEnabled prop is effectively used in multiple components to control the restoration process, ensuring that actions are only available when appropriate. This consistent handling aligns with the intended functionality and enhances the application's control mechanisms.

  • Files:
    • web/core/components/pages/editor/page-root.tsx
    • web/core/components/pages/version/root.tsx
    • web/core/components/pages/version/main-content.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the application-wide respect for `restoreEnabled`.

# Test: Search for the usage and handling of `restoreEnabled` across the application. Expect: Consistent and correct handling.
rg --type typescript -A 5 $'restoreEnabled'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the application-wide respect for `restoreEnabled`.

# Test: Search for the usage and handling of `restoreEnabled` across the application. Expect: Consistent and correct handling.
rg --type ts -A 5 $'restoreEnabled'

Length of output: 3622

web/core/components/pages/editor/page-root.tsx (2)

46-46: Code Review: Addition of isContentEditable property.

The destructuring of the isContentEditable property from the page object is correctly implemented. This property is crucial for determining the editability of the content, which aligns with the PR's objective to control version restoration based on user permissions.

The addition of this property is approved as it enhances the component's responsiveness to the page's editability state.


126-126: Code Review: Conditional enabling of restoreEnabled.

The restoreEnabled property is now conditionally set based on the isContentEditable value. This is a critical change as it directly ties the ability to restore a version to whether the page content is editable by the user, thereby enhancing security and control over version management.

The implementation of this conditional logic is approved. It effectively ensures that the restore functionality is aligned with the existing access controls, similar to those implemented for editing access to a page.

@pushya22 pushya22 merged commit fb2a04d into preview Aug 28, 2024
13 of 14 checks passed
@SatishGandham SatishGandham deleted the fix/version-auth branch August 28, 2024 08:38
@aaryan610 aaryan610 changed the title [WEB-2293] chore: add authorization to restore version [WEB-2346] chore: add authorization to restore version Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants