Skip to content

Fix: #2749 bug "Can no longer delete permissions" #2759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PermissionRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private function getSerializedRoleRelation($permission): array

private function getHydratedPermissionCollection(): Collection
{
$permissionInstance = new ($this->getPermissionClass())();
$permissionInstance = (new ($this->getPermissionClass())())->newInstance([], true);

return Collection::make(array_map(
fn ($item) => (clone $permissionInstance)
Expand All @@ -368,7 +368,7 @@ private function getHydratedRoleCollection(array $roles): Collection

private function hydrateRolesCache(): void
{
$roleInstance = new ($this->getRoleClass())();
$roleInstance = (new ($this->getRoleClass())())->newInstance([], true);

array_map(function ($item) use ($roleInstance) {
$role = (clone $roleInstance)
Expand Down
11 changes: 11 additions & 0 deletions tests/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@ public function it_is_retrievable_by_id()

$this->assertEquals($this->testUserPermission->id, $permission_by_id->id);
}

/** @test */
public function it_can_delete_hydrated_permissions()
{
$this->reloadPermissions();

$permission = app(Permission::class)->findByName($this->testUserPermission->name);
$permission->delete();

$this->assertCount(0, app(Permission::class)->where($this->testUserPermission->getKeyName(), $this->testUserPermission->getKey())->get());
}
}