From e01d859b534fac31a23b57f79a177b08a430c199 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Tue, 19 Jan 2021 18:51:29 -0700 Subject: [PATCH] db: add User has one AdminRole relation --- .gitignore | 5 ++++- app/Models/User.php | 14 ++++++++++---- .../Api/Application/UserTransformer.php | 2 +- .../2020_09_25_021109_create_admin_roles_table.php | 2 +- ...057_add_admin_role_id_column_to_users_table.php | 1 - 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 58250120e..11f82a76e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ /vendor *.DS_Store* -.env +!.env.ci +!.env.dusk +!.env.example +.env* .vagrant/* .vscode/* storage/framework/* diff --git a/app/Models/User.php b/app/Models/User.php index 7f2c8675d..b0d2ea614 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -25,7 +25,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification; * @property string|null $name_first * @property string|null $name_last * @property string $password - * @property string|null $remeber_token + * @property string|null $remember_token * @property string $language * @property bool $root_admin * @property bool $use_totp @@ -36,6 +36,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification; * @property \Carbon\Carbon $updated_at * * @property string $name + * @property \Pterodactyl\Models\AdminRole $adminRole * @property \Pterodactyl\Models\ApiKey[]|\Illuminate\Database\Eloquent\Collection $apiKeys * @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers * @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['avatar_url'] = $this->avatarURL(); - $object['role_name'] = $this->roleName(); + $object['role_name'] = $this->adminRoleName(); return $object; } @@ -222,9 +223,14 @@ class User extends Model implements * * @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; } /** diff --git a/app/Transformers/Api/Application/UserTransformer.php b/app/Transformers/Api/Application/UserTransformer.php index 24fb6360a..3a4c859d0 100644 --- a/app/Transformers/Api/Application/UserTransformer.php +++ b/app/Transformers/Api/Application/UserTransformer.php @@ -44,7 +44,7 @@ class UserTransformer extends BaseTransformer 'root_admin' => (bool) $model->root_admin, '2fa' => (bool) $model->use_totp, 'avatar_url' => $model->avatarURL(), - 'role_name' => $model->roleName(), + 'role_name' => $model->adminRoleName(), 'created_at' => $this->formatTimestamp($model->created_at), 'updated_at' => $this->formatTimestamp($model->updated_at), ]; diff --git a/database/migrations/2020_09_25_021109_create_admin_roles_table.php b/database/migrations/2020_09_25_021109_create_admin_roles_table.php index 058c00b9a..e65a457b5 100644 --- a/database/migrations/2020_09_25_021109_create_admin_roles_table.php +++ b/database/migrations/2020_09_25_021109_create_admin_roles_table.php @@ -14,7 +14,7 @@ class CreateAdminRolesTable extends Migration public function up() { Schema::create('admin_roles', function (Blueprint $table) { - $table->integer('id')->unsigned(); + $table->increments('id'); $table->string('name', 64); $table->string('description', 255)->nullable(); $table->integer('sort_id'); diff --git a/database/migrations/2021_01_16_201057_add_admin_role_id_column_to_users_table.php b/database/migrations/2021_01_16_201057_add_admin_role_id_column_to_users_table.php index 1bc4ebe01..d85e97027 100644 --- a/database/migrations/2021_01_16_201057_add_admin_role_id_column_to_users_table.php +++ b/database/migrations/2021_01_16_201057_add_admin_role_id_column_to_users_table.php @@ -29,7 +29,6 @@ class AddAdminRoleIdColumnToUsersTable extends Migration { Schema::table('users', function (Blueprint $table) { $table->dropForeign(['admin_role_id']); - $table->dropIndex('admin_role_id'); $table->dropColumn('admin_role_id'); }); }