diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php index da2f5f7a01..ac8e9009aa 100644 --- a/app/Models/SnipeModel.php +++ b/app/Models/SnipeModel.php @@ -156,19 +156,13 @@ class SnipeModel extends Model $this->attributes['status_id'] = $value; } - // This gets a little twitchy since *most* things have a property in the table called "name" (but users don't) - // AND we want to be able to use the actual display_name value from the database if it's set (usually via SCIM) - protected function displayNameAttribute(): Attribute + protected function displayName(): Attribute { - // This override should only kick in if the model has a display_name property (users) - if (isset($this->display_name)) { - return Attribute::make( - get: fn (string $value) => $this->display_name, - ); - } - return Attribute::make( - get: fn (string $value) => $this->name, + + return Attribute:: make( + get: fn(mixed $value) => $this->name, ); } + } diff --git a/app/Models/User.php b/app/Models/User.php index 5374b5e284..148a393dc8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -200,8 +200,20 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo }); } + /** + * This overrides the SnipeModel displayName accessor to return the full name if display_name is not set + * @see SnipeModel::displayName() + * @return Attribute + */ - public function isAvatarExternal() + protected function displayName(): Attribute + { + return Attribute:: make( + get: fn(mixed $value) => $value ?? $this->getFullNameAttribute(), + ); + } + + public function isAvatarExternal() : bool { // Check if it's a google avatar or some external avatar if (Str::startsWith($this->avatar, ['http://', 'https://'])) {