Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Nov 11, 2025

Closes #1888

@Boy132 Boy132 self-assigned this Nov 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

📝 Walkthrough

Walkthrough

This pull request fixes permission name casing inconsistencies. It updates role permission option keys to use consistent casing instead of lowercasing, adds a database migration to normalize existing permission names, and simplifies permission checking logic in the User model.

Changes

Cohort / File(s) Summary
Permission Key Casing Fix
app/Filament/Admin/Resources/Roles/RoleResource.php
Modified defaultForm to build permission option keys using original model name casing ($model) instead of lowercased values, while keeping displayed labels unchanged.
Permission Data Reconciliation
database/migrations/2025_11_11_121905_fix_case_for_role_permissions.php
New migration that normalizes existing Spatie permission names to match canonical casing from Role::getPermissionList, performing case-insensitive matching and updating mismatched permissions within a transaction.
Permission Check Simplification
app/Models/User.php
Simplified User::checkPermission method to return in_array() result directly instead of assigning to intermediate $check variable.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: correcting the case for role permissions across the codebase.
Description check ✅ Passed The description references issue #1888, which is related to role permissions not working correctly, matching the changeset's purpose.
Linked Issues check ✅ Passed The code changes directly address issue #1888 by fixing the case inconsistency in role permission names that was preventing proper permission validation.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the role permission case issue: migration to reconcile permissions, RoleResource to use correct casing, and User::checkPermission simplification.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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)
database/migrations/2025_11_11_121905_fix_case_for_role_permissions.php (1)

25-36: Optimize to only update when name changes.

The migration updates all permissions even when the name hasn't changed. Consider checking if an update is needed before executing it.

Apply this diff to improve performance:

 foreach (Permission::all() as $spatiePermission) {
     $name = $spatiePermission->name;
     
     foreach ($allPermissions as $permission) {
         if (Str::lower($name) === Str::lower($permission)) {
             $name = $permission;
             break;
         }
     }
     
-    $spatiePermission->update(['name' => $name]);
+    if ($name !== $spatiePermission->name) {
+        $spatiePermission->update(['name' => $name]);
+    }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89199df and 3fe18f9.

📒 Files selected for processing (3)
  • app/Filament/Admin/Resources/Roles/RoleResource.php (1 hunks)
  • app/Models/User.php (1 hunks)
  • database/migrations/2025_11_11_121905_fix_case_for_role_permissions.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
app/Models/User.php (2)
app/Models/Permission.php (1)
  • permissions (194-213)
app/Models/Subuser.php (1)
  • permissions (77-80)
database/migrations/2025_11_11_121905_fix_case_for_role_permissions.php (1)
app/Models/Role.php (1)
  • Role (24-144)
🔇 Additional comments (2)
app/Models/User.php (1)

345-345: LGTM! Cleaner return statement.

The direct return is more concise than using an intermediate variable.

app/Filament/Admin/Resources/Roles/RoleResource.php (1)

127-127: LGTM! Core fix for permission casing.

Using the original model casing ensures permission keys match the canonical format. This aligns with the database migration that normalizes existing permission names.

@Boy132 Boy132 merged commit 445c936 into main Nov 11, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/fix-role-permissions branch November 11, 2025 17:18
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Role Permission to see Panel Logs not giving you the permission to see the Panel Logs

3 participants