Skip to content

Commit 55de8bf

Browse files
committed
Add method to get boolean permission as bool
1 parent 1ce9b2d commit 55de8bf

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

wcfsetup/install/files/lib/system/session/SessionHandler.class.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,25 @@ public function getPermission(string $permission): mixed
745745
return $this->groupData[$permission];
746746
}
747747

748+
/**
749+
* Returns true if the active user has the given permission.
750+
* Only works for boolean permisions.
751+
*
752+
* @throws \BadMethodCallException
753+
* @since 6.3
754+
*/
755+
public function hasPermission(string $permission): bool
756+
{
757+
$result = $this->getPermission($permission);
758+
if ($result === true || $result === 1 || $result === '1') {
759+
return true;
760+
} else if ($result === false || $result === 0 || $result === '0') {
761+
return false;
762+
}
763+
764+
throw new \BadMethodCallException("'{$permission}' is not a boolean permission");
765+
}
766+
748767
/**
749768
* Returns true if a permission was set to 'Never'. This is required to preserve
750769
* compatibility, while preventing ACLs from overruling a 'Never' setting.

0 commit comments

Comments
 (0)