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

@ -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.
*