From 95c739a3f3ceaf5e2d725f592a6caf6d76dbd9df Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 30 Mar 2017 15:30:59 -0400 Subject: [PATCH] Update subusers view --- CHANGELOG.md | 7 + .../Controllers/Server/SubuserController.php | 2 + app/Models/Permission.php | 74 ++++ app/Repositories/SubuserRepository.php | 72 +--- public/themes/pterodactyl/css/pterodactyl.css | 4 + resources/lang/en/server.php | 12 +- .../pterodactyl/server/users/new.blade.php | 351 ++---------------- .../pterodactyl/server/users/view.blade.php | 281 ++------------ 8 files changed, 145 insertions(+), 658 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada37ee00..fc9e99937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.6.0-pre.8 (Courageous Carniadactylus) +### Fixed +* `[pre.7]` — Fixes bug with subuser checkbox display. + +### Changed +* Subuser permissions are now stored in `Permission::list()` to make views way cleaner and make adding to views significantly cleaner. + ## v0.6.0-pre.7 (Courageous Carniadactylus) ### Fixed * `[pre.6]` — Addresses misconfigured console queue that was still sending data way to quickly thus causing the console to explode on some devices when large amounts of data were sent. diff --git a/app/Http/Controllers/Server/SubuserController.php b/app/Http/Controllers/Server/SubuserController.php index 390f7b328..3caba0e0e 100644 --- a/app/Http/Controllers/Server/SubuserController.php +++ b/app/Http/Controllers/Server/SubuserController.php @@ -79,6 +79,7 @@ class SubuserController extends Controller 'server' => $server, 'node' => $server->node, 'subuser' => $subuser, + 'permlist' => Models\Permission::list(), 'permissions' => $subuser->permissions->mapWithKeys(function ($item, $key) { return [$item->permission => true]; }), @@ -146,6 +147,7 @@ class SubuserController extends Controller return view('server.users.new', [ 'server' => $server, + 'permissions' => Models\Permission::list(), 'node' => $server->node, ]); } diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 7dfd55f3f..a2bd58a7b 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -58,6 +58,80 @@ class Permission extends Model 'subuser_id' => 'integer', ]; + /** + * A list of all permissions available for a user. + * + * @var array + */ + protected static $permissions = [ + 'power' => [ + 'power-start' => 's:power:start', + 'power-stop' => 's:power:stop', + 'power-restart' => 's:power:restart', + 'power-kill' => 's:power:kill', + 'send-command' => 's:command', + ], + 'subuser' => [ + 'list-subusers' => null, + 'view-subuser' => null, + 'edit-subuser' => null, + 'create-subuser' => null, + 'delete-subuser' => null, + ], + 'server' => [ + 'set-connection' => null, + 'view-startup' => null, + 'edit-startup' => null, + ], + 'sftp' => [ + 'view-sftp' => null, + 'view-sftp-password' => null, + 'reset-sftp' => 's:set-password', + ], + 'file' => [ + 'list-files' => 's:files:get', + 'edit-files' => 's:files:read', + 'save-files' => 's:files:post', + 'move-files' => 's:files:move', + 'copy-files' => 's:files:copy', + 'compress-files' => 's:files:compress', + 'decompress-files' => 's:files:decompress', + 'create-files' => 's:files:create', + 'upload-files' => 's:files:upload', + 'delete-files' => 's:files:delete', + 'download-files' => null, + ], + 'task' => [ + 'list-tasks' => null, + 'view-task' => null, + 'toggle-task' => null, + 'queue-task' => null, + 'create-task' => null, + 'delete-task' => null, + ], + 'database' => [ + 'view-databases' => null, + 'reset-db-password' => null, + ], + ]; + + /** + * Return a collection of permissions available. + * + * @param array $single + * @return \Illuminate\Support\Collection|array + */ + public static function list($single = false) + { + if ($single) { + return collect(self::$permissions)->mapWithKeys(function ($item) { + return $item; + })->all(); + } + + return collect(self::$permissions); + } + /** * Find permission by permission node. * diff --git a/app/Repositories/SubuserRepository.php b/app/Repositories/SubuserRepository.php index 3b74ad1ad..37dd60501 100644 --- a/app/Repositories/SubuserRepository.php +++ b/app/Repositories/SubuserRepository.php @@ -45,62 +45,6 @@ class SubuserRepository 's:console', ]; - /** - * Allowed permissions and their related daemon permission. - * - * @var array - */ - protected $permissions = [ - // Power Permissions - 'power-start' => 's:power:start', - 'power-stop' => 's:power:stop', - 'power-restart' => 's:power:restart', - 'power-kill' => 's:power:kill', - - // Commands - 'send-command' => 's:command', - - // File Manager - 'list-files' => 's:files:get', - 'edit-files' => 's:files:read', - 'save-files' => 's:files:post', - 'create-files' => 's:files:create', - 'download-files' => null, - 'upload-files' => 's:files:upload', - 'delete-files' => 's:files:delete', - 'move-files' => 's:files:move', - 'copy-files' => 's:files:copy', - 'compress-files' => 's:files:compress', - 'decompress-files' => 's:files:decompress', - - // Subusers - 'list-subusers' => null, - 'view-subuser' => null, - 'edit-subuser' => null, - 'create-subuser' => null, - 'delete-subuser' => null, - - // Tasks - 'list-tasks' => null, - 'view-task' => null, - 'toggle-task' => null, - 'delete-task' => null, - 'create-task' => null, - 'queue-task' => null, - - // Management - 'set-connection' => null, - 'view-startup' => null, - 'edit-startup' => null, - 'view-sftp' => null, - 'reset-sftp' => 's:set-password', - 'view-sftp-password' => null, - - // Databases - 'view-databases' => null, - 'reset-db-password' => null, - ]; - /** * Creates a new subuser on the server. * @@ -155,12 +99,14 @@ class SubuserRepository 'daemonSecret' => (string) $uuid->generate('servers', 'uuid'), ]); + $perms = Permission::list(true); $daemonPermissions = $this->coreDaemonPermissions; + foreach ($data['permissions'] as $permission) { - if (array_key_exists($permission, $this->permissions)) { + if (array_key_exists($permission, $perms)) { // Build the daemon permissions array for sending. - if (! is_null($this->permissions[$permission])) { - array_push($daemonPermissions, $this->permissions[$permission]); + if (! is_null($perms[$permission])) { + array_push($daemonPermissions, $perms[$permission]); } Models\Permission::create([ @@ -272,12 +218,14 @@ class SubuserRepository $permission->delete(); } + $perms = Permission::list(true); $daemonPermissions = $this->coreDaemonPermissions; + foreach ($data['permissions'] as $permission) { - if (array_key_exists($permission, $this->permissions)) { + if (array_key_exists($permission, $perms)) { // Build the daemon permissions array for sending. - if (! is_null($this->permissions[$permission])) { - array_push($daemonPermissions, $this->permissions[$permission]); + if (! is_null($perms[$permission])) { + array_push($daemonPermissions, $perms[$permission]); } Models\Permission::create([ 'subuser_id' => $subuser->id, diff --git a/public/themes/pterodactyl/css/pterodactyl.css b/public/themes/pterodactyl/css/pterodactyl.css index 119099b50..aca92d909 100644 --- a/public/themes/pterodactyl/css/pterodactyl.css +++ b/public/themes/pterodactyl/css/pterodactyl.css @@ -276,3 +276,7 @@ span[aria-labelledby="select2-pUserId-container"] { .btn-icon > i.fa { line-height: 1.5; } + +.strong { + font-weight: bold !important; +} diff --git a/resources/lang/en/server.php b/resources/lang/en/server.php index 43913b64e..e0c34a888 100644 --- a/resources/lang/en/server.php +++ b/resources/lang/en/server.php @@ -59,24 +59,24 @@ return [ 'server_header' => 'Server Management', 'task_header' => 'Task Management', 'sftp_header' => 'SFTP Management', - 'db_header' => 'Database Management', - 'start' => [ + 'database_header' => 'Database Management', + 'power_start' => [ 'title' => 'Start Server', 'description' => 'Allows user to start the server.', ], - 'stop' => [ + 'power_stop' => [ 'title' => 'Stop Server', 'description' => 'Allows user to stop the server.', ], - 'restart' => [ + 'power_restart' => [ 'title' => 'Restart Server', 'description' => 'Allows user to restart the server.', ], - 'kill' => [ + 'power_kill' => [ 'title' => 'Kill Server', 'description' => 'Allows user to kill the server process.', ], - 'command' => [ + 'send_command' => [ 'title' => 'Send Console Command', 'description' => 'Allows sending a command from the console. If the user does not have stop or restart permissions they cannot send the application\'s stop command.', ], diff --git a/resources/themes/pterodactyl/server/users/new.blade.php b/resources/themes/pterodactyl/server/users/new.blade.php index 5cbe5617f..e77144232 100644 --- a/resources/themes/pterodactyl/server/users/new.blade.php +++ b/resources/themes/pterodactyl/server/users/new.blade.php @@ -60,340 +60,31 @@
-
- {{-- Left Side --}} -
-
-
-
-

@lang('server.users.new.power_header')

-
-
-
- + @foreach($permissions as $block => $perms) +
+
+
+

@lang('server.users.new.' . $block . '_header')

+
+
+ @foreach($perms as $permission => $daemon) +
+
+ + +
+

@lang('server.users.new.' . str_replace('-', '_', $permission) . '.description')

-
- -
-
- -
-
- -
-
- -
-
+ @endforeach
-
-
-
-
-

@lang('server.users.new.subuser_header')

-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
-
-
-
-

@lang('server.users.new.server_header')

-
-
-
- -
-
- -
-
- -
-
-
-
-
-
-
-
-
-

@lang('server.users.new.sftp_header')

-
-
-
- -
-
- -
-
- -
-
-
-
-
-
-
- {{-- Right Side --}} -
-
-
-
-

@lang('server.users.new.file_header')

-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
-
-
-
-

@lang('server.users.new.task_header')

-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
-
-
-
-

@lang('server.users.new.db_header')

-
-
-
- -
-
- -
-
-
-
-
-
+ @if ($loop->iteration % 2 === 0) +
+ @endif + @endforeach
@endsection diff --git a/resources/themes/pterodactyl/server/users/view.blade.php b/resources/themes/pterodactyl/server/users/view.blade.php index fdb4e0c0d..61fd5c48a 100644 --- a/resources/themes/pterodactyl/server/users/view.blade.php +++ b/resources/themes/pterodactyl/server/users/view.blade.php @@ -62,270 +62,31 @@
-
- {{-- Left Side --}} -
-
-
-
-

@lang('server.users.new.power_header')

-
-
-
- - -

@lang('server.users.new.start.description')

+ @foreach($permlist as $block => $perms) +
+
+
+

@lang('server.users.new.' . $block . '_header')

+
+
+ @foreach($perms as $permission => $daemon) +
+
+ + +
+

@lang('server.users.new.' . str_replace('-', '_', $permission) . '.description')

-
- - @lang('server.users.new.stop.title') -

@lang('server.users.new.stop.description')

-
-
- - @lang('server.users.new.restart.title') -

@lang('server.users.new.restart.description')

-
-
- - @lang('server.users.new.kill.title') -

@lang('server.users.new.kill.description')

-
-
- - @lang('server.users.new.command.title') -

@lang('server.users.new.command.description')

-
-
+ @endforeach
-
-
-
-
-

@lang('server.users.new.subuser_header')

-
-
-
- - @lang('server.users.new.list_subusers.title') -

@lang('server.users.new.list_subusers.description')

-
-
- - @lang('server.users.new.view_subuser.title') -

@lang('server.users.new.view_subuser.description')

-
-
- - @lang('server.users.new.edit_subuser.title') -

@lang('server.users.new.edit_subuser.description')

-
-
- - @lang('server.users.new.create_subuser.title') -

@lang('server.users.new.create_subuser.description')

-
-
- - @lang('server.users.new.delete_subuser.title') -

@lang('server.users.new.delete_subuser.description')

-
-
-
-
-
-
-
-
-
-

@lang('server.users.new.server_header')

-
-
-
- - @lang('server.users.new.set_connection.title') -

@lang('server.users.new.set_connection.description')

-
-
- - @lang('server.users.new.view_startup.title') -

@lang('server.users.new.view_startup.description')

-
-
- - @lang('server.users.new.edit_startup.title') -

@lang('server.users.new.edit_startup.description')

-
-
-
-
-
-
-
-
-
-

@lang('server.users.new.sftp_header')

-
-
-
- - @lang('server.users.new.view_sftp.title') -

@lang('server.users.new.view_sftp.description')

-
-
- - @lang('strings.danger') - @lang('server.users.new.view_sftp_password.title') -

@lang('server.users.new.view_sftp_password.description')

-
-
- - @lang('server.users.new.reset_sftp.title') -

@lang('server.users.new.reset_sftp.description')

-
-
-
-
-
-
-
- {{-- Right Side --}} -
-
-
-
-

@lang('server.users.new.file_header')

-
-
-
- - @lang('server.users.new.list_files.title') -

@lang('server.users.new.list_files.description')

-
-
- - @lang('server.users.new.edit_files.title') -

@lang('server.users.new.edit_files.description')

-
-
- - @lang('server.users.new.save_files.title') -

@lang('server.users.new.save_files.description')

-
-
- - @lang('server.users.new.move_files.title') -

@lang('server.users.new.move_files.description')

-
-
- - @lang('server.users.new.copy_files.title') -

@lang('server.users.new.copy_files.description')

-
-
- - @lang('server.users.new.compress_files.title') -

@lang('server.users.new.compress_files.description')

-
-
- - @lang('server.users.new.decompress_files.title') -

@lang('server.users.new.decompress_files.description')

-
-
- - @lang('server.users.new.create_files.title') -

@lang('server.users.new.create_files.description')

-
-
- - @lang('server.users.new.upload_files.title') -

@lang('server.users.new.upload_files.description')

-
-
- - @lang('strings.danger') - @lang('server.users.new.delete_files.title') -

@lang('server.users.new.delete_files.description')

-
-
- - @lang('strings.danger') - @lang('server.users.new.download_files.title') -

@lang('server.users.new.download_files.description')

-
-
-
-
-
-
-
-
-
-

@lang('server.users.new.task_header')

-
-
-
- - @lang('server.users.new.list_tasks.title') -

@lang('server.users.new.list_tasks.description')

-
-
- - @lang('server.users.new.view_task.title') -

@lang('server.users.new.view_task.description')

-
-
- - @lang('server.users.new.toggle_task.title') -

@lang('server.users.new.toggle_task.description')

-
-
- - @lang('server.users.new.queue_task.title') -

@lang('server.users.new.queue_task.description')

-
-
- - @lang('server.users.new.create_task.title') -

@lang('server.users.new.create_task.description')

-
-
- - @lang('strings.danger') - @lang('server.users.new.delete_task.title') -

@lang('server.users.new.delete_task.description')

-
-
-
-
-
-
-
-
-
-

@lang('server.users.new.db_header')

-
-
-
- - @lang('strings.danger') - @lang('server.users.new.view_databases.title') -

@lang('server.users.new.view_databases.description')

-
-
- - @lang('strings.danger') - @lang('server.users.new.reset_db_password.title') -

@lang('server.users.new.reset_db_password.description')

-
-
-
-
-
-
+ @if ($loop->iteration % 2 === 0) +
+ @endif + @endforeach
@can('edit-subuser', $server)