Tightened up accessor code for better inheritence

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-08-25 15:00:10 +01:00
parent b6d397bcca
commit e60f2b2332
2 changed files with 18 additions and 12 deletions

View File

@@ -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,
);
}
}

View File

@@ -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://'])) {