Merge branch 'develop' into matthewpi/security-keys-backport
This commit is contained in:
commit
f631ac1946
1153 changed files with 25099 additions and 37002 deletions
|
@ -12,6 +12,8 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
use Webauthn\PublicKeyCredentialUserEntity;
|
||||
use Pterodactyl\Models\Traits\HasAccessTokens;
|
||||
use Illuminate\Auth\Passwords\CanResetPassword;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Pterodactyl\Traits\Helpers\AvailableLanguages;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
|
@ -29,11 +31,10 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
|||
* @property string $uuid
|
||||
* @property string $username
|
||||
* @property string $email
|
||||
* @property string|null $name_first
|
||||
* @property string|null $name_last
|
||||
* @property string $password
|
||||
* @property string|null $remember_token
|
||||
* @property string $language
|
||||
* @property int|null $admin_role_id
|
||||
* @property bool $root_admin
|
||||
* @property bool $use_totp
|
||||
* @property string|null $totp_secret
|
||||
|
@ -41,9 +42,12 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
|||
* @property bool $gravatar
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property string $avatar_url
|
||||
* @property string|null $admin_role_name
|
||||
* @property string $md5
|
||||
* @property \Pterodactyl\Models\AdminRole|null $adminRole
|
||||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\ApiKey[] $apiKeys
|
||||
* @property int|null $api_keys_count
|
||||
* @property string $name
|
||||
* @property \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
||||
* @property int|null $notifications_count
|
||||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\RecoveryToken[] $recoveryTokens
|
||||
|
@ -79,7 +83,9 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
|||
* @method static Builder|User whereUsername($value)
|
||||
* @method static Builder|User whereUuid($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
* @mixin \Barryvdh\LaravelIdeHelper\Eloquent
|
||||
* @mixin \Illuminate\Database\Query\Builder
|
||||
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
class User extends Model implements
|
||||
AuthenticatableContract,
|
||||
|
@ -119,8 +125,6 @@ class User extends Model implements
|
|||
'external_id',
|
||||
'username',
|
||||
'email',
|
||||
'name_first',
|
||||
'name_last',
|
||||
'password',
|
||||
'language',
|
||||
'use_totp',
|
||||
|
@ -165,8 +169,6 @@ class User extends Model implements
|
|||
'email' => 'required|email|between:1,191|unique:users,email',
|
||||
'external_id' => 'sometimes|nullable|string|max:191|unique:users,external_id',
|
||||
'username' => 'required|between:1,191|unique:users,username',
|
||||
'name_first' => 'required|string|between:1,191',
|
||||
'name_last' => 'required|string|between:1,191',
|
||||
'password' => 'sometimes|nullable|string',
|
||||
'root_admin' => 'boolean',
|
||||
'language' => 'string',
|
||||
|
@ -193,7 +195,9 @@ class User extends Model implements
|
|||
*/
|
||||
public function toReactObject(): array
|
||||
{
|
||||
return Collection::make($this->toArray())->except(['id', 'external_id'])->toArray();
|
||||
return Collection::make($this->append(['avatar_url', 'admin_role_name'])->toArray())
|
||||
->except(['id', 'external_id', 'admin_role', 'admin_role_id'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,20 +223,39 @@ class User extends Model implements
|
|||
$this->attributes['username'] = mb_strtolower($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a concatenated result for the accounts full name.
|
||||
*/
|
||||
public function getNameAttribute(): string
|
||||
public function avatarUrl(): Attribute
|
||||
{
|
||||
return trim($this->name_first . ' ' . $this->name_last);
|
||||
return Attribute::make(
|
||||
get: fn () => 'https://www.gravatar.com/avatar/' . $this->md5 . '.jpg',
|
||||
);
|
||||
}
|
||||
|
||||
public function adminRoleName(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => is_null($this->adminRole) ? ($this->root_admin ? 'None' : null) : $this->adminRole->name,
|
||||
);
|
||||
}
|
||||
|
||||
public function md5(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => md5(strtolower($this->email)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all servers that a user owns.
|
||||
* Returns all the activity logs where this user is the subject — not to
|
||||
* be confused by activity logs where this user is the _actor_.
|
||||
*/
|
||||
public function servers(): HasMany
|
||||
public function activity(): MorphToMany
|
||||
{
|
||||
return $this->hasMany(Server::class, 'owner_id');
|
||||
return $this->morphToMany(ActivityLog::class, 'subject', 'activity_log_subjects');
|
||||
}
|
||||
|
||||
public function adminRole(): HasOne
|
||||
{
|
||||
return $this->hasOne(AdminRole::class, 'id', 'admin_role_id');
|
||||
}
|
||||
|
||||
public function apiKeys(): HasMany
|
||||
|
@ -246,6 +269,11 @@ class User extends Model implements
|
|||
return $this->hasMany(RecoveryToken::class);
|
||||
}
|
||||
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class, 'owner_id');
|
||||
}
|
||||
|
||||
public function sshKeys(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserSSHKey::class);
|
||||
|
@ -256,15 +284,6 @@ class User extends Model implements
|
|||
return $this->hasMany(SecurityKey::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the activity logs where this user is the subject — not to
|
||||
* be confused by activity logs where this user is the _actor_.
|
||||
*/
|
||||
public function activity(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(ActivityLog::class, 'subject', 'activity_log_subjects');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the servers that a user can access by way of being the owner of the
|
||||
* server, or because they are assigned as a subuser for that server.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue