Skip to content

Commit

Permalink
Merge pull request #1259 from sergiz/pr/hasdirectpermission-cleanup
Browse files Browse the repository at this point in the history
hasDirectPermission cleanup
  • Loading branch information
drbyte authored Nov 8, 2019
2 parents 238cd38 + 541991d commit 7e06ec0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/Traits/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,14 @@ public function hasDirectPermission($permission): bool

if (is_string($permission)) {
$permission = $permissionClass->findByName($permission, $this->getDefaultGuardName());
if (! $permission) {
return false;
}
}

if (is_int($permission)) {
$permission = $permissionClass->findById($permission, $this->getDefaultGuardName());
if (! $permission) {
return false;
}
}

if (! $permission instanceof Permission) {
return false;
throw new PermissionDoesNotExist;
}

return $this->permissions->contains('id', $permission->id);
Expand Down
8 changes: 6 additions & 2 deletions tests/HasPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,19 @@ public function it_throws_an_exception_when_calling_hasDirectPermission_with_an_
{
$user = User::create(['email' => '[email protected]']);

$this->assertFalse($user->hasDirectPermission(new \stdClass()));
$this->expectException(PermissionDoesNotExist::class);

$user->hasDirectPermission(new \stdClass());
}

/** @test */
public function it_throws_an_exception_when_calling_hasDirectPermission_with_null()
{
$user = User::create(['email' => '[email protected]']);

$this->assertFalse($user->hasDirectPermission(null));
$this->expectException(PermissionDoesNotExist::class);

$user->hasDirectPermission(null);
}

/** @test */
Expand Down

0 comments on commit 7e06ec0

Please sign in to comment.