Skip to content

Commit

Permalink
Use int casting
Browse files Browse the repository at this point in the history
These manifested as strings for some users
  • Loading branch information
daftspunk committed Apr 7, 2021
1 parent 6bcb7b9 commit d374aea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Auth/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function hasAccess($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $rolePermission && starts_with($rolePermission, $checkPermission) && $value === 1) {
if ($checkPermission != $rolePermission && starts_with($rolePermission, $checkPermission) && (int) $value === 1) {
$matched = true;
break;
}
Expand All @@ -102,7 +102,7 @@ public function hasAccess($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $rolePermission && ends_with($rolePermission, $checkPermission) && $value === 1) {
if ($checkPermission != $rolePermission && ends_with($rolePermission, $checkPermission) && (int) $value === 1) {
$matched = true;
break;
}
Expand All @@ -121,14 +121,14 @@ public function hasAccess($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkGroupPermission != $permission && starts_with($permission, $checkGroupPermission) && $value === 1) {
if ($checkGroupPermission != $permission && starts_with($permission, $checkGroupPermission) && (int) $value === 1) {
$matched = true;
break;
}
}
// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission === $rolePermission && $rolePermissions[$permission] === 1) {
elseif ($permission === $rolePermission && (int) $rolePermissions[$permission] === 1) {
$matched = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Auth/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function hasPermission($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $mergedPermission && starts_with($mergedPermission, $checkPermission) && $value === 1) {
if ($checkPermission != $mergedPermission && starts_with($mergedPermission, $checkPermission) && (int) $value === 1) {
$matched = true;
break;
}
Expand All @@ -496,7 +496,7 @@ public function hasPermission($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $mergedPermission && ends_with($mergedPermission, $checkPermission) && $value === 1) {
if ($checkPermission != $mergedPermission && ends_with($mergedPermission, $checkPermission) && (int) $value === 1) {
$matched = true;
break;
}
Expand All @@ -515,15 +515,15 @@ public function hasPermission($permissions, $all = true)

// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkMergedPermission != $permission && starts_with($permission, $checkMergedPermission) && $value === 1) {
if ($checkMergedPermission != $permission && starts_with($permission, $checkMergedPermission) && (int) $value === 1) {
$matched = true;
break;
}
}

// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission === $mergedPermission && $mergedPermissions[$permission] === 1) {
elseif ($permission === $mergedPermission && (int) $mergedPermissions[$permission] === 1) {
$matched = true;
break;
}
Expand Down

0 comments on commit d374aea

Please sign in to comment.