X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d336ba687460d2bca898e86c12a26224fc36f071..refs/pull/2393/head:/app/Auth/User.php diff --git a/app/Auth/User.php b/app/Auth/User.php index 69f424cac..32179a1fb 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -1,6 +1,8 @@ roles->pluck('name')->contains($role); + return $this->roles->pluck('id')->contains($roleId); } /** @@ -116,6 +119,17 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->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 @@ -149,20 +163,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon /** * Attach a role to this user. - * @param Role $role */ 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); } /** @@ -227,6 +231,14 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->hasMany(ApiToken::class); } + /** + * Get the latest activity instance for this user. + */ + public function latestActivity(): HasOne + { + return $this->hasOne(Activity::class)->latest(); + } + /** * Get the url for editing this user. */ @@ -272,4 +284,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon { $this->notify(new ResetPassword($token)); } + + /** + * @inheritdoc + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->name}"; + } }