Skip to content

Commit 95c739a

Browse files
committed
Update subusers view
1 parent f2f834a commit 95c739a

File tree

8 files changed

+145
-658
lines changed

8 files changed

+145
-658
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.6.0-pre.8 (Courageous Carniadactylus)
7+
### Fixed
8+
* `[pre.7]` — Fixes bug with subuser checkbox display.
9+
10+
### Changed
11+
* Subuser permissions are now stored in `Permission::list()` to make views way cleaner and make adding to views significantly cleaner.
12+
613
## v0.6.0-pre.7 (Courageous Carniadactylus)
714
### Fixed
815
* `[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.

app/Http/Controllers/Server/SubuserController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function getView(Request $request, $uuid, $id)
7979
'server' => $server,
8080
'node' => $server->node,
8181
'subuser' => $subuser,
82+
'permlist' => Models\Permission::list(),
8283
'permissions' => $subuser->permissions->mapWithKeys(function ($item, $key) {
8384
return [$item->permission => true];
8485
}),
@@ -146,6 +147,7 @@ public function getNew(Request $request, $uuid)
146147

147148
return view('server.users.new', [
148149
'server' => $server,
150+
'permissions' => Models\Permission::list(),
149151
'node' => $server->node,
150152
]);
151153
}

app/Models/Permission.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,80 @@ class Permission extends Model
5858
'subuser_id' => 'integer',
5959
];
6060

61+
/**
62+
* A list of all permissions available for a user.
63+
*
64+
* @var array
65+
*/
66+
protected static $permissions = [
67+
'power' => [
68+
'power-start' => 's:power:start',
69+
'power-stop' => 's:power:stop',
70+
'power-restart' => 's:power:restart',
71+
'power-kill' => 's:power:kill',
72+
'send-command' => 's:command',
73+
],
74+
'subuser' => [
75+
'list-subusers' => null,
76+
'view-subuser' => null,
77+
'edit-subuser' => null,
78+
'create-subuser' => null,
79+
'delete-subuser' => null,
80+
],
81+
'server' => [
82+
'set-connection' => null,
83+
'view-startup' => null,
84+
'edit-startup' => null,
85+
],
86+
'sftp' => [
87+
'view-sftp' => null,
88+
'view-sftp-password' => null,
89+
'reset-sftp' => 's:set-password',
90+
],
91+
'file' => [
92+
'list-files' => 's:files:get',
93+
'edit-files' => 's:files:read',
94+
'save-files' => 's:files:post',
95+
'move-files' => 's:files:move',
96+
'copy-files' => 's:files:copy',
97+
'compress-files' => 's:files:compress',
98+
'decompress-files' => 's:files:decompress',
99+
'create-files' => 's:files:create',
100+
'upload-files' => 's:files:upload',
101+
'delete-files' => 's:files:delete',
102+
'download-files' => null,
103+
],
104+
'task' => [
105+
'list-tasks' => null,
106+
'view-task' => null,
107+
'toggle-task' => null,
108+
'queue-task' => null,
109+
'create-task' => null,
110+
'delete-task' => null,
111+
],
112+
'database' => [
113+
'view-databases' => null,
114+
'reset-db-password' => null,
115+
],
116+
];
117+
118+
/**
119+
* Return a collection of permissions available.
120+
*
121+
* @param array $single
122+
* @return \Illuminate\Support\Collection|array
123+
*/
124+
public static function list($single = false)
125+
{
126+
if ($single) {
127+
return collect(self::$permissions)->mapWithKeys(function ($item) {
128+
return $item;
129+
})->all();
130+
}
131+
132+
return collect(self::$permissions);
133+
}
134+
61135
/**
62136
* Find permission by permission node.
63137
*

app/Repositories/SubuserRepository.php

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,6 @@ class SubuserRepository
4545
's:console',
4646
];
4747

48-
/**
49-
* Allowed permissions and their related daemon permission.
50-
*
51-
* @var array
52-
*/
53-
protected $permissions = [
54-
// Power Permissions
55-
'power-start' => 's:power:start',
56-
'power-stop' => 's:power:stop',
57-
'power-restart' => 's:power:restart',
58-
'power-kill' => 's:power:kill',
59-
60-
// Commands
61-
'send-command' => 's:command',
62-
63-
// File Manager
64-
'list-files' => 's:files:get',
65-
'edit-files' => 's:files:read',
66-
'save-files' => 's:files:post',
67-
'create-files' => 's:files:create',
68-
'download-files' => null,
69-
'upload-files' => 's:files:upload',
70-
'delete-files' => 's:files:delete',
71-
'move-files' => 's:files:move',
72-
'copy-files' => 's:files:copy',
73-
'compress-files' => 's:files:compress',
74-
'decompress-files' => 's:files:decompress',
75-
76-
// Subusers
77-
'list-subusers' => null,
78-
'view-subuser' => null,
79-
'edit-subuser' => null,
80-
'create-subuser' => null,
81-
'delete-subuser' => null,
82-
83-
// Tasks
84-
'list-tasks' => null,
85-
'view-task' => null,
86-
'toggle-task' => null,
87-
'delete-task' => null,
88-
'create-task' => null,
89-
'queue-task' => null,
90-
91-
// Management
92-
'set-connection' => null,
93-
'view-startup' => null,
94-
'edit-startup' => null,
95-
'view-sftp' => null,
96-
'reset-sftp' => 's:set-password',
97-
'view-sftp-password' => null,
98-
99-
// Databases
100-
'view-databases' => null,
101-
'reset-db-password' => null,
102-
];
103-
10448
/**
10549
* Creates a new subuser on the server.
10650
*
@@ -155,12 +99,14 @@ public function create($sid, array $data)
15599
'daemonSecret' => (string) $uuid->generate('servers', 'uuid'),
156100
]);
157101

102+
$perms = Permission::list(true);
158103
$daemonPermissions = $this->coreDaemonPermissions;
104+
159105
foreach ($data['permissions'] as $permission) {
160-
if (array_key_exists($permission, $this->permissions)) {
106+
if (array_key_exists($permission, $perms)) {
161107
// Build the daemon permissions array for sending.
162-
if (! is_null($this->permissions[$permission])) {
163-
array_push($daemonPermissions, $this->permissions[$permission]);
108+
if (! is_null($perms[$permission])) {
109+
array_push($daemonPermissions, $perms[$permission]);
164110
}
165111

166112
Models\Permission::create([
@@ -272,12 +218,14 @@ public function update($id, array $data)
272218
$permission->delete();
273219
}
274220

221+
$perms = Permission::list(true);
275222
$daemonPermissions = $this->coreDaemonPermissions;
223+
276224
foreach ($data['permissions'] as $permission) {
277-
if (array_key_exists($permission, $this->permissions)) {
225+
if (array_key_exists($permission, $perms)) {
278226
// Build the daemon permissions array for sending.
279-
if (! is_null($this->permissions[$permission])) {
280-
array_push($daemonPermissions, $this->permissions[$permission]);
227+
if (! is_null($perms[$permission])) {
228+
array_push($daemonPermissions, $perms[$permission]);
281229
}
282230
Models\Permission::create([
283231
'subuser_id' => $subuser->id,

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,7 @@ span[aria-labelledby="select2-pUserId-container"] {
276276
.btn-icon > i.fa {
277277
line-height: 1.5;
278278
}
279+
280+
.strong {
281+
font-weight: bold !important;
282+
}

resources/lang/en/server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@
5959
'server_header' => 'Server Management',
6060
'task_header' => 'Task Management',
6161
'sftp_header' => 'SFTP Management',
62-
'db_header' => 'Database Management',
63-
'start' => [
62+
'database_header' => 'Database Management',
63+
'power_start' => [
6464
'title' => 'Start Server',
6565
'description' => 'Allows user to start the server.',
6666
],
67-
'stop' => [
67+
'power_stop' => [
6868
'title' => 'Stop Server',
6969
'description' => 'Allows user to stop the server.',
7070
],
71-
'restart' => [
71+
'power_restart' => [
7272
'title' => 'Restart Server',
7373
'description' => 'Allows user to restart the server.',
7474
],
75-
'kill' => [
75+
'power_kill' => [
7676
'title' => 'Kill Server',
7777
'description' => 'Allows user to kill the server process.',
7878
],
79-
'command' => [
79+
'send_command' => [
8080
'title' => 'Send Console Command',
8181
'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.',
8282
],

0 commit comments

Comments
 (0)