db: add User has one AdminRole relation
This commit is contained in:
parent
1e61fd161c
commit
e01d859b53
5 changed files with 16 additions and 8 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,6 +1,9 @@
|
||||||
/vendor
|
/vendor
|
||||||
*.DS_Store*
|
*.DS_Store*
|
||||||
.env
|
!.env.ci
|
||||||
|
!.env.dusk
|
||||||
|
!.env.example
|
||||||
|
.env*
|
||||||
.vagrant/*
|
.vagrant/*
|
||||||
.vscode/*
|
.vscode/*
|
||||||
storage/framework/*
|
storage/framework/*
|
||||||
|
|
|
@ -25,7 +25,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
||||||
* @property string|null $name_first
|
* @property string|null $name_first
|
||||||
* @property string|null $name_last
|
* @property string|null $name_last
|
||||||
* @property string $password
|
* @property string $password
|
||||||
* @property string|null $remeber_token
|
* @property string|null $remember_token
|
||||||
* @property string $language
|
* @property string $language
|
||||||
* @property bool $root_admin
|
* @property bool $root_admin
|
||||||
* @property bool $use_totp
|
* @property bool $use_totp
|
||||||
|
@ -36,6 +36,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
||||||
* @property \Carbon\Carbon $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
*
|
*
|
||||||
* @property string $name
|
* @property string $name
|
||||||
|
* @property \Pterodactyl\Models\AdminRole $adminRole
|
||||||
* @property \Pterodactyl\Models\ApiKey[]|\Illuminate\Database\Eloquent\Collection $apiKeys
|
* @property \Pterodactyl\Models\ApiKey[]|\Illuminate\Database\Eloquent\Collection $apiKeys
|
||||||
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
|
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
|
||||||
* @property \Pterodactyl\Models\RecoveryToken[]|\Illuminate\Database\Eloquent\Collection $recoveryTokens
|
* @property \Pterodactyl\Models\RecoveryToken[]|\Illuminate\Database\Eloquent\Collection $recoveryTokens
|
||||||
|
@ -172,7 +173,7 @@ class User extends Model implements
|
||||||
{
|
{
|
||||||
$object = (new Collection($this->toArray()))->except(['id', 'external_id'])->toArray();
|
$object = (new Collection($this->toArray()))->except(['id', 'external_id'])->toArray();
|
||||||
$object['avatar_url'] = $this->avatarURL();
|
$object['avatar_url'] = $this->avatarURL();
|
||||||
$object['role_name'] = $this->roleName();
|
$object['role_name'] = $this->adminRoleName();
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
@ -222,9 +223,14 @@ class User extends Model implements
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function roleName():? string
|
public function adminRoleName():? string
|
||||||
{
|
{
|
||||||
return $this->root_admin ? 'Super Administrator' : null;
|
$role = $this->adminRole;
|
||||||
|
if (is_null($role)) {
|
||||||
|
return $this->root_admin ? 'None' : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $role->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,7 @@ class UserTransformer extends BaseTransformer
|
||||||
'root_admin' => (bool) $model->root_admin,
|
'root_admin' => (bool) $model->root_admin,
|
||||||
'2fa' => (bool) $model->use_totp,
|
'2fa' => (bool) $model->use_totp,
|
||||||
'avatar_url' => $model->avatarURL(),
|
'avatar_url' => $model->avatarURL(),
|
||||||
'role_name' => $model->roleName(),
|
'role_name' => $model->adminRoleName(),
|
||||||
'created_at' => $this->formatTimestamp($model->created_at),
|
'created_at' => $this->formatTimestamp($model->created_at),
|
||||||
'updated_at' => $this->formatTimestamp($model->updated_at),
|
'updated_at' => $this->formatTimestamp($model->updated_at),
|
||||||
];
|
];
|
||||||
|
|
|
@ -14,7 +14,7 @@ class CreateAdminRolesTable extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('admin_roles', function (Blueprint $table) {
|
Schema::create('admin_roles', function (Blueprint $table) {
|
||||||
$table->integer('id')->unsigned();
|
$table->increments('id');
|
||||||
$table->string('name', 64);
|
$table->string('name', 64);
|
||||||
$table->string('description', 255)->nullable();
|
$table->string('description', 255)->nullable();
|
||||||
$table->integer('sort_id');
|
$table->integer('sort_id');
|
||||||
|
|
|
@ -29,7 +29,6 @@ class AddAdminRoleIdColumnToUsersTable extends Migration
|
||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
Schema::table('users', function (Blueprint $table) {
|
||||||
$table->dropForeign(['admin_role_id']);
|
$table->dropForeign(['admin_role_id']);
|
||||||
$table->dropIndex('admin_role_id');
|
|
||||||
$table->dropColumn('admin_role_id');
|
$table->dropColumn('admin_role_id');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue