mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 11:55:51 -05:00
acl none check
This commit is contained in:
@@ -49,10 +49,11 @@ class AdminAcl
|
||||
|
||||
/**
|
||||
* Determine if an API key has permission to perform a specific read/write operation.
|
||||
* Asking for no action is denied, so a request that never set one fails closed.
|
||||
*/
|
||||
public static function can(int $permission, int $action = self::READ): bool
|
||||
{
|
||||
return ($permission & $action) === $action;
|
||||
return $action !== self::NONE && ($permission & $action) === $action;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ uses(TestCase::class);
|
||||
* Provide valid and invalid permissions combos for testing.
|
||||
*/
|
||||
dataset('permissionsDataProvider', function () {
|
||||
return [[AdminAcl::READ, AdminAcl::READ, true], [AdminAcl::READ | AdminAcl::WRITE, AdminAcl::READ, true], [AdminAcl::READ | AdminAcl::WRITE, AdminAcl::WRITE, true], [AdminAcl::WRITE, AdminAcl::WRITE, true], [AdminAcl::READ, AdminAcl::WRITE, false], [AdminAcl::NONE, AdminAcl::READ, false], [AdminAcl::NONE, AdminAcl::WRITE, false]];
|
||||
return [[AdminAcl::READ, AdminAcl::READ, true], [AdminAcl::READ | AdminAcl::WRITE, AdminAcl::READ, true], [AdminAcl::READ | AdminAcl::WRITE, AdminAcl::WRITE, true], [AdminAcl::WRITE, AdminAcl::WRITE, true], [AdminAcl::READ, AdminAcl::WRITE, false], [AdminAcl::NONE, AdminAcl::READ, false], [AdminAcl::NONE, AdminAcl::WRITE, false], [AdminAcl::NONE, AdminAcl::NONE, false], [AdminAcl::READ | AdminAcl::WRITE, AdminAcl::NONE, false]];
|
||||
});
|
||||
test('permissions', function (int $permission, int $check, bool $outcome) {
|
||||
expect(AdminAcl::can($permission, $check))->toBe($outcome);
|
||||
|
||||
Reference in New Issue
Block a user