expose userclass / permissions

This commit is contained in:
Shish 2023-02-07 13:21:37 +00:00
parent 90dd842a7c
commit 010f976af5
2 changed files with 20 additions and 0 deletions

View file

@ -31,6 +31,7 @@ class User
public ?string $email;
public string $join_date;
public ?string $passhash;
#[Field]
public UserClass $class;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

View file

@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2;
use GQLA\Type;
use GQLA\Field;
use GQLA\Query;
/**
* @global UserClass[] $_shm_user_classes
*/
@ -13,8 +17,10 @@ $_shm_user_classes = [];
/**
* Class UserClass
*/
#[Type(name: "UserClass")]
class UserClass
{
#[Field]
public ?string $name = null;
public ?UserClass $parent = null;
public array $abilities = [];
@ -33,6 +39,19 @@ class UserClass
$_shm_user_classes[$name] = $this;
}
#[Field(type: "[String!]!")]
public function permissions(): array
{
global $_all_false;
$perms = [];
foreach ((new \ReflectionClass('\Shimmie2\Permissions'))->getConstants() as $k => $v) {
if ($this->can($v)) {
$perms[] = $v;
}
}
return $perms;
}
/**
* Determine if this class of user can perform an action or has ability.
*