From 010f976af5ca544d13d207218323bcd60224e620 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 7 Feb 2023 13:21:37 +0000 Subject: [PATCH] expose userclass / permissions --- core/user.php | 1 + core/userclass.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/user.php b/core/user.php index 55819a84..48394723 100644 --- a/core/user.php +++ b/core/user.php @@ -31,6 +31,7 @@ class User public ?string $email; public string $join_date; public ?string $passhash; + #[Field] public UserClass $class; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/core/userclass.php b/core/userclass.php index 32bac793..ce78701e 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -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. *