Skip to content

Conversation

@GautierDele
Copy link
Member

@GautierDele GautierDele commented Jul 6, 2025

closes #27
closes #26

Summary by CodeRabbit

  • New Features

    • Added a new configuration option to control isolation of perimeter queries in access control settings.
  • Bug Fixes

    • Improved query isolation logic for access control, enhancing how conditions are combined.
  • Tests

    • Added and updated tests to verify the behavior of parent and perimeter query isolation options.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

Walkthrough

The changes update access control query configuration and logic by renaming the parent query isolation flag, introducing a new flag for perimeter query isolation, and adjusting how perimeters' query callbacks are applied. Test coverage is expanded to verify both parent and perimeter isolation behaviors, and perimeter query callbacks are revised to use strict filtering.

Changes

File(s) Change Summary
config/access-control.php Renamed 'isolated' to 'isolate_parent_query'; added 'isolate_perimeter_queries' flag in config.
src/Controls/Control.php Updated logic to use new config keys; added conditional perimeter query isolation.
tests/Feature/ControlsQueryTest.php Renamed test method; added test for perimeter isolation config; updated config usage in tests.
tests/Support/Access/Controls/ModelControl.php Replaced orWhereHas/orWhere with whereHas/where in perimeter query callbacks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Control
    participant ModelQuery

    User->>Control: queried(ModelQuery, user)
    Control->>Control: Check config for isolate_parent_query
    alt Parent query isolation enabled
        Control->>ModelQuery: Wrap all perimeter queries in nested where
    else
        Control->>ModelQuery: Apply perimeter queries directly
    end
    Control->>Control: For each perimeter
    Control->>Control: Check config for isolate_perimeter_queries
    alt Perimeter isolation enabled
        Control->>ModelQuery: Apply each perimeter query in orWhere closure
    else
        Control->>ModelQuery: Apply perimeter query directly
    end
    ModelQuery-->>User: Filtered results
Loading

Assessment against linked issues

Objective Addressed Explanation
SharedPerimeter should return shared records for users with correct permissions and relationships (#27)
Remove use of orWhere/orWhereHas in perimeter query callbacks to avoid collapsing conditions (#27)
Add configuration to control perimeter query isolation and update logic accordingly (#27)
Tests should cover both parent and perimeter isolation configuration behaviors (#27)

Poem

A rabbit hopped through fields of code,
Where queries once would overlap and explode.
Now isolation’s clear, both parent and peer,
With configs renamed and logic sincere.
Shared carrots (and records!) are found at last—
This bunny’s bug-fix is unsurpassed!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbfabb7 and c7d0774.

📒 Files selected for processing (4)
  • config/access-control.php (1 hunks)
  • src/Controls/Control.php (2 hunks)
  • tests/Feature/ControlsQueryTest.php (2 hunks)
  • tests/Support/Access/Controls/ModelControl.php (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/Support/Access/Controls/ModelControl.php (3)
src/Perimeters/Perimeter.php (1)
  • query (116-121)
tests/Support/Models/Model.php (1)
  • client (34-37)
tests/Support/Models/User.php (1)
  • client (50-53)
src/Controls/Control.php (1)
src/Perimeters/Perimeter.php (2)
  • query (116-121)
  • applyQueryCallback (64-67)
🪛 PHPMD (2.15.0)
tests/Feature/ControlsQueryTest.php

191-191: Avoid unused parameters such as '$user'. (Unused Code Rules)

(UnusedFormalParameter)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests on PHP 8.3 with Laravel ^12.0 and sqlite
🔇 Additional comments (9)
config/access-control.php (1)

11-13: Configuration changes look good!

The renaming from isolated to isolate_parent_query is more descriptive, and the new isolate_perimeter_queries option provides valuable granular control over query isolation behavior. The comments clearly explain the purpose of each option.

tests/Support/Access/Controls/ModelControl.php (3)

29-29: Good refactoring of query callback logic.

Changing from orWhereHas to whereHas aligns with the new perimeter isolation system where the Control class manages query combination logic rather than individual perimeter callbacks.


57-57: Consistent with the new isolation approach.

The change from orWhere to where maintains consistency with the new perimeter isolation design where strict filtering is applied at the perimeter level.


70-70: Proper alignment with isolation pattern.

The change from orWhere to where correctly implements the new approach where perimeter callbacks use strict filtering conditions.

src/Controls/Control.php (2)

84-84: Configuration key update is correct.

The change from access-control.queries.isolated to access-control.queries.isolate_parent_query properly aligns with the updated configuration structure.


122-128: Excellent implementation of perimeter query isolation.

The conditional logic properly implements the new perimeter isolation feature:

  • When isolate_perimeter_queries is enabled, each perimeter query is wrapped in an orWhere closure
  • When disabled, perimeter queries are applied directly to the main query
  • This provides the expected behavior for preventing overlapping perimeter conditions from collapsing

The implementation correctly leverages the refactored perimeter callbacks (now using strict where conditions) with the Control class managing the combination logic.

tests/Feature/ControlsQueryTest.php (3)

153-155: Test method rename and configuration update are correct.

The renaming from test_control_queried_not_isolated to test_control_queried_not_parent_isolated and the configuration key update to isolate_parent_query properly reflect the new configuration structure.


184-218: Excellent test coverage for perimeter isolation feature.

The new test method properly verifies the behavior when perimeter query isolation is disabled:

  • Sets up appropriate gate definitions for shared and own models
  • Creates models with different perimeter combinations
  • Verifies that the query count is 50 when isolate_perimeter_queries is false
  • This effectively tests the new perimeter isolation functionality

The test data setup and assertions align with the expected behavior of the new feature.


188-193: Static analysis hint is a false positive.

The $user parameter in the Gate::define closure is required by Laravel's Gate signature and is used appropriately within the closure context. This is not an unused parameter issue.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@GautierDele GautierDele merged commit ffa2ccf into main Jul 6, 2025
21 checks passed
@GautierDele GautierDele deleted the feature/isolate-perimeter-queries branch July 6, 2025 13:35
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.

SharedPerimeter excludes all results even with valid shared records Condition overlay perimeters

3 participants