Skip to content

Commit 99747a5

Browse files
authored
fix: group entity can method (#649)
* fix: group entity can method * style: run php-cs-fixer * tests: update group testCan test * style: run rector
1 parent c015b21 commit 99747a5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Entities/Group.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ public function can(string $permission): bool
7070
{
7171
$this->populatePermissions();
7272

73-
return in_array(strtolower($permission), $this->permissions, true);
73+
// Check exact match
74+
if (! empty($this->permissions) && in_array($permission, $this->permissions, true)) {
75+
return true;
76+
}
77+
78+
// Check wildcard match
79+
$check = substr($permission, 0, strpos($permission, '.')) . '.*';
80+
81+
return ! empty($this->permissions) && in_array($check, $this->permissions, true);
7482
}
7583

7684
/**

tests/Authorization/GroupTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ public function testRemovePermission(): void
7171

7272
public function testCan(): void
7373
{
74-
$group = $this->groups->info('admin');
74+
$group1 = $this->groups->info('superadmin');
75+
$group2 = $this->groups->info('admin');
7576

76-
$this->assertTrue($group->can('users.edit'));
77-
$this->assertFalse($group->can('foo.bar'));
77+
$this->assertTrue($group1->can('users.*'));
78+
$this->assertTrue($group2->can('users.edit'));
79+
$this->assertFalse($group2->can('foo.bar'));
7880
}
7981
}

0 commit comments

Comments
 (0)