Skip to content

Conversation

@GautierDele
Copy link
Member

@GautierDele GautierDele commented Jul 21, 2025

closes #32
closes #31
closes #30

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added configuration for mapping access control method names to permission identifiers, allowing for more flexible permission checks.
  • Bug Fixes

    • Improved handling of model class references to ensure correct namespace resolution in generated code.
  • Refactor

    • Updated console command options for better flag handling.
    • Adjusted internal logic to support configurable method mappings for permission checks.
  • Tests

    • Enhanced and updated tests to reflect new permission mapping and naming conventions.

@GautierDele GautierDele requested a review from Copilot July 21, 2025 17:46
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

A new configuration mapping for access control method names was introduced, allowing aliasing of method names to permission strings. The Control class was updated to use this mapping, and related tests and code were adjusted to reflect the new naming conventions. Console command and code generation behavior were also slightly refined.

Changes

File(s) Change Summary
config/access-control.php Added 'methods' mapping for access control method name aliasing.
src/Controls/Control.php Uses config mapping to remap method names for permission checks.
tests/Feature/ControlsShouldTest.php, tests/Feature/PoliciesTest.php Updated Gate ability names in tests and added a new test for remapped method configuration.
src/Console/PerimeterMakeCommand.php Changed overlay option from accepting a value to being a boolean flag.
src/Console/stubs/control.stub, tests/Unit/Console/MakeCommandsTest.php Added leading backslash for model class references in code generation and corresponding tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Control
    participant Config
    participant Perimeter

    User->>Control: calls applies(user, method, model)
    Control->>Config: fetch 'methods' mapping
    Control->>Control: map method via config (appliesMethod)
    Control->>Perimeter: applyAllowedCallback(user, appliesMethod, model)
    Perimeter-->>Control: returns permission result
    Control-->>User: returns boolean
Loading

Estimated code review effort

2 (~15 minutes)

Poem

In the warren of code, a mapping was spun,
Access methods remapped—now permission checks run!
With a hop and a skip, the tests all align,
Console flags toggled, the namespaces fine.
A rabbit approves, with a twitch of its nose—
“Refactored and ready, let’s see where it goes!” 🐇


📜 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 a17d5fe and 7613bcb.

📒 Files selected for processing (1)
  • src/Controls/Control.php (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Controls/Control.php
✨ 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements small adjustments to the access control system, primarily standardizing method naming conventions and improving configuration flexibility. The changes focus on normalizing the "viewAny" method to use "view" permissions and adding proper namespace escaping.

  • Standardizes "viewAny" method to use "view" permissions through configuration mapping
  • Adds leading backslashes for proper namespace escaping in generated code
  • Improves command option handling and fixes minor typos

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
config/access-control.php Adds method mapping configuration to standardize permission checking
src/Controls/Control.php Implements configurable method mapping for permission checks
src/Console/stubs/control.stub Adds leading backslash for proper namespace escaping
src/Console/PerimeterMakeCommand.php Changes overlay option from VALUE_OPTIONAL to VALUE_NONE
tests/Unit/Console/MakeCommandsTest.php Updates test assertion to expect proper namespace escaping
tests/Feature/PoliciesTest.php Updates Gate definition to use standardized "view" method
tests/Feature/ControlsShouldTest.php Updates test cases and adds new test for method configuration

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

🧹 Nitpick comments (1)
src/Controls/Control.php (1)

64-68: Configuration-based method mapping implementation looks solid.

The implementation correctly introduces method name aliasing through configuration while maintaining backward compatibility. The use of null coalescing operator ensures graceful fallback to the original method name.

However, consider the consistency with hardcoded method names in applyQueryControl() and applyScoutQueryControl() methods (lines 137, 172) which still use 'view' directly. Should these also respect the configuration mapping?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9c40752 and a17d5fe.

📒 Files selected for processing (7)
  • config/access-control.php (1 hunks)
  • src/Console/PerimeterMakeCommand.php (1 hunks)
  • src/Console/stubs/control.stub (1 hunks)
  • src/Controls/Control.php (1 hunks)
  • tests/Feature/ControlsShouldTest.php (2 hunks)
  • tests/Feature/PoliciesTest.php (1 hunks)
  • tests/Unit/Console/MakeCommandsTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/Feature/PoliciesTest.php (1)
tests/Support/Models/User.php (1)
  • User (10-64)
src/Controls/Control.php (2)
tests/Support/Access/Controls/ModelControl.php (1)
  • perimeters (17-75)
src/Perimeters/Perimeter.php (1)
  • applyAllowedCallback (76-79)
🪛 PHPMD (2.15.0)
tests/Feature/ControlsShouldTest.php

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

(UnusedFormalParameter)


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

(UnusedFormalParameter)


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

(UnusedFormalParameter)

🔇 Additional comments (9)
src/Console/stubs/control.stub (1)

16-16: Good improvement for namespace resolution.

Adding the leading backslash ensures the fully qualified class name is resolved from the global namespace, preventing potential namespace conflicts in generated control classes.

src/Console/PerimeterMakeCommand.php (1)

107-107: Good refactor of the overlay option.

Changing from VALUE_OPTIONAL to VALUE_NONE makes the --overlay option a proper boolean flag, which is more intuitive and consistent with how it's used in the command logic.

tests/Unit/Console/MakeCommandsTest.php (1)

112-112: Test assertion correctly updated to match stub changes.

The updated assertion properly reflects the addition of the leading backslash in the generated model property, maintaining test consistency with the stub template changes.

config/access-control.php (1)

15-30: Well-designed method mapping configuration.

The new methods configuration section provides a clean, centralized way to alias access control methods to their corresponding permissions. The mapping of viewAny to view helps unify similar permission checks, and the structure follows Laravel configuration conventions.

tests/Feature/PoliciesTest.php (1)

27-27: Test correctly updated to reflect method mapping changes.

The Gate ability name change from 'viewAny global models' to 'view global models' properly reflects the new configuration mapping where viewAny methods are aliased to view permissions. The test logic remains sound while adapting to the unified permission naming.

tests/Feature/ControlsShouldTest.php (4)

17-24: Excellent test coverage for the new configuration mapping feature.

The new test method properly validates that the configuration mapping works as expected, testing that 'viewAny' method gets mapped to 'view' permission when checking Gate abilities.


28-28: Test updated correctly to reflect the new naming convention.

The Gate ability name has been appropriately changed from 'viewAny client models' to 'view client models' to align with the new configuration mapping.


97-97: Test updated correctly to reflect the new naming convention.

The Gate ability name has been appropriately changed from 'viewAny global models' to 'view global models' to align with the new configuration mapping.


19-19: Static analysis false positives for unused parameters.

The PHPMD warnings about unused $user parameters in Gate::define callbacks are false positives. These parameters are required by Laravel's Gate callback signature even when not used in simple test scenarios.

Also applies to: 28-28, 97-97

@GautierDele GautierDele merged commit c8e3dd1 into main Jul 21, 2025
21 checks passed
@GautierDele GautierDele deleted the feature/small-adjustments branch July 21, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants