Tightened up accessor code for better inheritence
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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://'])) {
|
||||
|
||||
Reference in New Issue
Block a user