Fix test coverage for creating account API keys
This commit is contained in:
parent
3d14974d64
commit
815ce0e451
6 changed files with 62 additions and 148 deletions
|
@ -4,9 +4,12 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Contracts\HasAbilities;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class PersonalAccessToken extends Model implements HasAbilities
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const RESOURCE_NAME = 'personal_access_token';
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,17 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Services\Acl\Api;
|
||||
|
||||
use ReflectionClass;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
|
||||
class AdminAcl
|
||||
{
|
||||
/**
|
||||
* Resource permission columns in the api_keys table begin
|
||||
* with this identifier.
|
||||
*/
|
||||
public const COLUMN_IDENTIFIER = 'r_';
|
||||
|
||||
/**
|
||||
* The different types of permissions available for API keys. This
|
||||
* implements a read/write/none permissions scheme for all endpoints.
|
||||
|
@ -36,48 +27,4 @@ class AdminAcl
|
|||
public const RESOURCE_SERVER_DATABASES = 'server_databases';
|
||||
public const RESOURCE_ROLES = 'roles';
|
||||
public const RESOURCE_MOUNTS = 'mounts';
|
||||
|
||||
/**
|
||||
* Determine if an API key has permission to perform a specific read/write operation.
|
||||
*
|
||||
* @param int $permission
|
||||
* @param int $action
|
||||
* @return bool
|
||||
*/
|
||||
public static function can(int $permission, int $action = self::READ)
|
||||
{
|
||||
if ($permission & $action) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an API Key model has permission to access a given resource
|
||||
* at a specific action level.
|
||||
*
|
||||
* @param \Pterodactyl\Models\ApiKey $key
|
||||
* @param string $resource
|
||||
* @param int $action
|
||||
* @return bool
|
||||
*/
|
||||
public static function check(ApiKey $key, string $resource, int $action = self::READ)
|
||||
{
|
||||
return self::can(data_get($key, self::COLUMN_IDENTIFIER . $resource, self::NONE), $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all resource constants defined in this ACL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getResourceList(): array
|
||||
{
|
||||
$reflect = new ReflectionClass(__CLASS__);
|
||||
|
||||
return collect($reflect->getConstants())->filter(function ($value, $key) {
|
||||
return substr($key, 0, 9) === 'RESOURCE_';
|
||||
})->values()->toArray();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue