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: field-level access is incorrectly rejected when there're no allow rules #1510

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 14, 2024

Fixes #1501

Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

Walkthrough

The changes introduce a more detailed conditional logic to the generateEntityCheckerFunction in utils.ts, refining how policies based on kind and forField parameters are evaluated. Additionally, new test cases have been added to field-level-policy.test.ts to validate these changes, including scenarios where specific policies are applied to the visibility of fields based on conditions.

Changes

File Change Summary
packages/schema/src/plugins/enhancer/policy/utils.ts Updated the conditional logic in generateEntityCheckerFunction to improve decision-making processes based on kind and forField parameters.
tests/integration/tests/enhancements/with-policy/field-level-policy.test.ts Added new test scenarios including a z field with a read denial policy based on the value of x.

Sequence Diagram(s)

N/A

Assessment against linked issues

Objective Addressed Explanation
Fix the behavior of @deny('read', ...) field-level policies so that they correctly handle conditions where the policy should not block reads (e.g., @deny('read', false) doesn't block reads). [#1501]

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9c7527f and 21d38f9.

Files selected for processing (2)
  • packages/schema/src/plugins/enhancer/policy/utils.ts (1 hunks)
  • tests/integration/tests/enhancements/with-policy/field-level-policy.test.ts (2 hunks)
Additional comments not posted (4)
packages/schema/src/plugins/enhancer/policy/utils.ts (1)

Line range hint 1-422: Ensure comprehensive test coverage for policy utility functions.

Given the complexity and importance of the functions in this file, it is crucial to verify that there is comprehensive test coverage, especially for the new logic introduced. This can help prevent regressions and ensure that the policy enforcement behaves as expected under various conditions.

#!/bin/bash
# Description: Verify test coverage for policy utility functions.

# Test: Search for test cases covering the utility functions. Expect: Tests for all major paths and edge cases.
rg --type typescript --files-with-matches $'describe\\(".*utils.*",'
tests/integration/tests/enhancements/with-policy/field-level-policy.test.ts (3)

30-30: The addition of the new field z with a @deny('read', x <= 0) policy is crucial for testing the changes made in the PR. This line effectively tests the scenario described in the issue, ensuring that the policy does not block reads when it shouldn't.


44-44: The extensive tests for the visibility of field z across various scenarios are well-implemented. These tests check the read access permissions based on the value of x and ensure that the policy is enforced correctly. The tests are comprehensive and cover multiple methods of accessing the data (findUnique, create, etc.), which is good for ensuring robustness.
[APROVED]

Also applies to: 47-47, 51-51, 55-55, 59-59, 63-63, 67-67, 71-71, 76-76, 81-81, 86-86, 91-91, 97-97, 102-102, 104-104, 107-107, 110-110, 114-114, 116-116, 119-119, 127-127, 132-132, 134-134, 137-137, 139-139, 143-143


134-134: The test cases for the z field when x is greater than 0 (thus making z readable according to the policy) are correctly implemented. These tests validate the fix by ensuring that the policy behaves as expected when the condition is true.

Also applies to: 137-137, 139-139

@ymc9 ymc9 merged commit 484b920 into dev Jun 14, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/issue-1501 branch June 14, 2024 13:54
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.

1 participant