Skip to content

Conversation

@iqbalhasandev
Copy link
Member

🐛 Bug Fix: Wildcard Permissions (*) Not Working With Empty User Permissions

Problem

When users have no permissions (empty array []) or when permissions are manually passed as an empty array, wildcard patterns like * were not working as expected. This broke the intended behavior where certain components should be visible to all users regardless of their permission status.

Before this fix:

// User with permissions: []
<Can permission="*">Dashboard</Can>           // ❌ Hidden (incorrect)
<Can permission="* || admin">Menu</Can>       //  Hidden (incorrect)

After this fix:

// User with permissions: []
<Can permission="*">Dashboard</Can>           // ✅ Visible (correct)
<Can permission="* || admin">Menu</Can>       //  Visible (correct)

…y permissions

feat: enhance usePermissions to allow universal access with '*' pattern
@iqbalhasandev iqbalhasandev self-assigned this Sep 19, 2025
@iqbalhasandev iqbalhasandev added the bug Something isn't working label Sep 19, 2025
Copy link
Contributor

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 fixes a bug where wildcard pattern matching (*) failed when users had empty permissions arrays, preventing universal access patterns from working correctly.

  • Adds special handling for standalone wildcard (*) patterns to always return true for universal access
  • Updates regex patterns to properly match standalone wildcards in complex expressions
  • Adds comprehensive test coverage for wildcard patterns with empty permission arrays

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
hooks/use-permissions.tsx Implements universal access for * patterns and improves regex handling for wildcards
tests/wildcard-empty-permissions.test.tsx Adds comprehensive test suite for wildcard patterns with empty permissions
tests/use-permissions-coverage.test.tsx Updates existing test to reflect new * behavior with empty permissions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

iqbalhasandev and others added 2 commits September 19, 2025 08:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@iqbalhasandev iqbalhasandev merged commit 10d8ba9 into DevWizardHQ:main Sep 19, 2025
7 of 9 checks passed
@iqbalhasandev iqbalhasandev deleted the fix/wildcard-empty-permissions branch September 19, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Wildcard permissions (*) fail when user has empty permissions array

1 participant