admin(ui): display dynamic user information on sidebar

This commit is contained in:
Matthew Penner 2021-01-07 10:21:09 -07:00
parent 9eed88b430
commit 2352ef0369
9 changed files with 57 additions and 17 deletions

View file

@ -25,9 +25,11 @@ class VersionController extends ApplicationApiController
}
/**
* ?
* Returns version information.
*
* @return \Illuminate\Http\JsonResponse
*/
public function __invoke()
public function __invoke(): JsonResponse
{
return new JsonResponse($this->softwareVersionService->getVersionData());
}

View file

@ -168,9 +168,13 @@ class User extends Model implements
*
* @return array
*/
public function toVueObject(): array
public function toReactObject(): array
{
return (new Collection($this->toArray()))->except(['id', 'external_id'])->toArray();
$object = (new Collection($this->toArray()))->except(['id', 'external_id'])->toArray();
$object['avatar_url'] = $this->avatarURL();
$object['role_name'] = $this->roleName();
return $object;
}
/**
@ -203,6 +207,26 @@ class User extends Model implements
return trim($this->name_first . ' ' . $this->name_last);
}
/**
* Get's the avatar url for the user.
*
* @return string
*/
public function avatarURL(): string
{
return 'https://www.gravatar.com/avatar/' . md5($this->email) . '.jpg';
}
/**
* Get's the name of the role assigned to a user.
*
* @return string|null
*/
public function roleName():? string
{
return $this->root_admin ? 'Super Administrator' : null;
}
/**
* Returns all servers that a user owns.
*

View file

@ -20,12 +20,12 @@ abstract class BaseTransformer extends TransformerAbstract
/**
* @var \Pterodactyl\Models\ApiKey
*/
private $key;
private ApiKey $key;
/**
* @var bool
*/
private $rootAdmin;
private bool $rootAdmin;
/**
* Return the resource name for the JSONAPI output.

View file

@ -43,11 +43,10 @@ class UserTransformer extends BaseTransformer
'language' => $model->language,
'root_admin' => (bool) $model->root_admin,
'2fa' => (bool) $model->use_totp,
'avatar_url' => 'https://www.gravatar.com/avatar/' . md5($model->email) . '.jpg?s=40',
'role_name' => $model->root_admin ? 'Super Administrator' : null,
'avatar_url' => $model->avatarURL(),
'role_name' => $model->roleName(),
'created_at' => $this->formatTimestamp($model->created_at),
'updated_at' => $this->formatTimestamp($model->updated_at),
'avatar'
];
}