X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ddb7f33868ea499ab8f48a7062f145e8c0fbe02f..refs/pull/2023/head:/app/Auth/User.php diff --git a/app/Auth/User.php b/app/Auth/User.php index bce418a74..a581d9993 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -1,5 +1,6 @@ roles->pluck('system_name')->contains($role); } + /** + * Attach the default system role to this user. + */ + public function attachDefaultRole(): void + { + $roleId = setting('registration-role'); + if ($roleId && $this->roles()->where('id', '=', $roleId)->count() === 0) { + $this->roles()->attach($roleId); + } + } + /** * Get all permissions belonging to a the current user. * @param bool $cache @@ -151,16 +167,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function attachRole(Role $role) { - $this->attachRoleId($role->id); - } - - /** - * Attach a role id to this user. - * @param $id - */ - public function attachRoleId($id) - { - $this->roles()->attach($id); + $this->roles()->attach($role->id); } /** @@ -217,20 +224,27 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->belongsTo(Image::class, 'image_id'); } + /** + * Get the API tokens assigned to this user. + */ + public function apiTokens(): HasMany + { + return $this->hasMany(ApiToken::class); + } + /** * Get the url for editing this user. - * @return string */ - public function getEditUrl() + public function getEditUrl(string $path = ''): string { - return url('/http/source.bookstackapp.com/settings/users/' . $this->id); + $uri = '/settings/users/' . $this->id . '/' . trim($path, '/'); + return url(rtrim($uri, '/')); } /** * Get the url that links to this user's profile. - * @return mixed */ - public function getProfileUrl() + public function getProfileUrl(): string { return url('/http/source.bookstackapp.com/user/' . $this->id); }