Skip to content

Commit f1a3008

Browse files
committed
Fix display and subuser settings for databases
1 parent 4d31004 commit f1a3008

File tree

8 files changed

+74
-33
lines changed

8 files changed

+74
-33
lines changed

app/Policies/ServerPolicy.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,22 @@ public function viewDatabases(User $user, Server $server)
450450
return $user->permissions()->server($server)->permission('view-databases')->exists();
451451
}
452452

453+
/**
454+
* Check if user has permission to reset database passwords.
455+
*
456+
* @param Pterodactyl\Models\User $user
457+
* @param Pterodactyl\Models\Server $server
458+
* @return boolean
459+
*/
460+
public function resetDbPassword(User $user, Server $server)
461+
{
462+
if ($this->isOwner($user, $server)) {
463+
return true;
464+
}
465+
466+
return $user->permissions()->server($server)->permission('reset-db-password')->exists();
467+
}
468+
453469
/**
454470
* Check if user has permission to view all tasks for a server.
455471
*
@@ -546,13 +562,4 @@ public function createTask(User $user, Server $server)
546562
return $user->permissions()->server($server)->permission('create-task')->exists();
547563
}
548564

549-
public function resetDbPassword(User $user, Server $server)
550-
{
551-
if ($this->isOwner($user, $server)) {
552-
return true;
553-
}
554-
555-
return $user->permissions()->server($server)->permission('create-task')->exists();
556-
}
557-
558565
}

app/Repositories/SubuserRepository.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ class SubuserRepository
9292
'view-startup' => null,
9393
'edit-startup' => null,
9494
'view-sftp' => null,
95-
'reset-sftp' => 's:set-password'
95+
'reset-sftp' => 's:set-password',
96+
97+
// Databases
98+
'view-databases' => null,
99+
'reset-db-password' => null
96100
];
97101

98102
public function __construct()

resources/views/layouts/master.blade.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,9 @@
194194
@can('list-files', $server)<li class="server-files"><a href="/server/{{ $server->uuidShort }}/files">{{ trans('pagination.sidebar.files') }}</a></li>@endcan
195195
@can('list-subusers', $server)<li class="server-users"><a href="/server/{{ $server->uuidShort }}/users">{{ trans('pagination.sidebar.subusers') }}</a></li>@endcan
196196
@can('list-tasks', $server)<li class="server-tasks"><a href="/server/{{ $server->uuidShort }}/tasks">Scheduled Tasks</a></li>@endcan
197-
@can('view-sftp', $server)
197+
@if(Gate::allows('view-startup', $server) || Gate::allows('view-sftp', $server) || Gate::allows('view-databases', $server))
198198
<li class="server-settings"><a href="/server/{{ $server->uuidShort }}/settings">{{ trans('pagination.sidebar.manage') }}</a></li>
199-
@else
200-
@can('view-startup', $server)
201-
<li class="server-settings"><a href="/server/{{ $server->uuidShort }}/settings">{{ trans('pagination.sidebar.manage') }}</a></li>
202-
@endcan
203-
@endcan
199+
@endif
204200
</ul>
205201
</li>
206202
@endif
@@ -251,13 +247,9 @@
251247
@can('list-files', $server)<a href="/server/{{ $server->uuidShort }}/files" class="list-group-item server-files">{{ trans('pagination.sidebar.files') }}</a>@endcan
252248
@can('list-subusers', $server)<a href="/server/{{ $server->uuidShort }}/users" class="list-group-item server-users">{{ trans('pagination.sidebar.subusers') }}</a>@endcan
253249
@can('list-tasks', $server)<a href="/server/{{ $server->uuidShort }}/tasks" class="list-group-item server-tasks">Scheduled Tasks</a>@endcan
254-
@can('view-sftp', $server)
250+
@if(Gate::allows('view-startup', $server) || Gate::allows('view-sftp', $server) || Gate::allows('view-databases', $server))
255251
<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>
256-
@else
257-
@can('view-startup', $server)
258-
<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>
259-
@endcan
260-
@endcan
252+
@endif
261253
</div>
262254
@endif
263255
@show

resources/views/server/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</div>
4949
<div class="col-md-6">
5050
<hr />
51-
@can('command', $server)
51+
@can('send-command', $server)
5252
<form action="#" method="post" id="console_command" style="display:none;">
5353
<fieldset>
5454
<div class="input-group">
@@ -408,7 +408,7 @@ function updatePlayerListVisibility(data) {
408408
});
409409
@endcan
410410
411-
@can('command', $server)
411+
@can('send-command', $server)
412412
// Send Command to Server
413413
$('#console_command').submit(function (event) {
414414

resources/views/server/settings.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class="form-control" value="{{ old($item->env_variable, $item->a_serverValue) }}
152152
<tr>
153153
<td>{{ $database->database }}</td>
154154
<td>{{ $database->username }}</td>
155-
<td><code>{{ Crypt::decrypt($database->password) }}</code> <a href="#" data-action="reset-database-password" data-id="{{ $database->id }}"><i class="fa fa-refresh pull-right"></i></a></td>
155+
<td><code>{{ Crypt::decrypt($database->password) }}</code> @can('reset-db-password', $server)<a href="#" data-action="reset-database-password" data-id="{{ $database->id }}"><i class="fa fa-refresh pull-right"></i></a>@endcan</td>
156156
<td><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
157157
</tr>
158158
@endforeach

resources/views/server/users/index.blade.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
<tr>
3232
<th>Email</th>
3333
<th>Created</th>
34-
<th>Modified</th>
3534
@can('view-subuser', $server)<th></th>@endcan
3635
@can('delete-subuser', $server)<th></th>@endcan
3736
</tr>
@@ -41,7 +40,6 @@
4140
<tr>
4241
<td><code>{{ $user->a_userEmail }}</code></td>
4342
<td>{{ $user->created_at }}</td>
44-
<td>{{ $user->updated_at }}</td>
4543
@can('view-subuser', $server)
4644
<td class="text-center"><a href="{{ route('server.subusers.view', ['server' => $server->uuidShort, 'id' => md5($user->id)]) }}" class="text-success"><i class="fa fa-wrench"></i></a></td>
4745
@endcan

resources/views/server/users/new.blade.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
<?php $oldInput = array_flip(is_array(old('permissions')) ? old('permissions') : []) ?>
3333
<div class="row">
3434
<div class="form-group col-md-12">
35-
<label class="control-label">User Email:</label>
36-
<div>
37-
<input type="text" name="email" autocomplete="off" value="{{ old('email') }}" class="form-control" />
38-
</div>
35+
<div class="well" style="padding: 0 19px 19px;margin-bottom:0;">
36+
<label class="control-label">User Email:</label>
37+
<div>
38+
<input type="text" name="email" autocomplete="off" value="{{ old('email') }}" class="form-control" />
39+
</div>
40+
</div>
3941
</div>
4042
</div>
4143
<div class="row">
@@ -113,7 +115,7 @@
113115
<div class="checkbox highlight">
114116
<label class="checkbox-custom highlight" data-initialize="checkbox">
115117
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['download-files']))checked="checked"@endif value="download-files"> <strong>Download Files</strong>
116-
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to download files. If a user is given this permission they can download and view file contents.</small><p>
118+
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to download files. If a user is given this permission they can download and view file contents even if that permission is not assigned on the panel.</small><p>
117119
</label>
118120
</div>
119121
</div>
@@ -172,6 +174,25 @@
172174
<p class="text-muted"><small>Allows a user to modify startup variables for a server.</small><p>
173175
</label>
174176
</div>
177+
</div>
178+
</div>
179+
<div class="row">
180+
<div class="col-md-6 fuelux">
181+
<h4>Database Management</h4><hr />
182+
<div class="checkbox highlight">
183+
<label class="checkbox-custom highlight" data-initialize="checkbox">
184+
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['view-databases']))checked="checked"@endif value="view-databases"> <strong>View Database Details</strong>
185+
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to view all databases associated with this server (including usernames and password for the databases).</small><p>
186+
</label>
187+
</div>
188+
<div class="checkbox highlight">
189+
<label class="checkbox-custom highlight" data-initialize="checkbox">
190+
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['reset-db-password']))checked="checked"@endif value="reset-db-password"> <strong>Reset Database Password</strong>
191+
<p class="text-muted"><small>Allows a user to reset passwords for databases.</small><p>
192+
</label>
193+
</div>
194+
</div>
195+
<div class="col-md-6 fuelux">
175196
<h4>SFTP Management</h4><hr />
176197
<div class="checkbox highlight">
177198
<label class="checkbox-custom highlight" data-initialize="checkbox">

resources/views/server/users/view.blade.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<div class="checkbox highlight">
105105
<label class="checkbox-custom highlight" data-initialize="checkbox">
106106
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['download-files']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="download-files"> <strong>Download Files</strong>
107-
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to download files. If a user is given this permission they can download and view file contents.</small><p>
107+
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to download files. If a user is given this permission they can download and view file contents even if that permission is not assigned on the panel.</small><p>
108108
</label>
109109
</div>
110110
</div>
@@ -163,6 +163,25 @@
163163
<p class="text-muted"><small>Allows a user to modify startup variables for a server.</small><p>
164164
</label>
165165
</div>
166+
</div>
167+
</div>
168+
<div class="row">
169+
<div class="col-md-6 fuelux">
170+
<h4>Database Management</h4><hr />
171+
<div class="checkbox highlight">
172+
<label class="checkbox-custom highlight" data-initialize="checkbox">
173+
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['view-databases']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="view-databases"> <strong>View Database Details</strong>
174+
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to view all databases associated with this server (including usernames and password for the databases).</small><p>
175+
</label>
176+
</div>
177+
<div class="checkbox highlight">
178+
<label class="checkbox-custom highlight" data-initialize="checkbox">
179+
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['reset-db-password']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="reset-db-password"> <strong>Reset Database Password</strong>
180+
<p class="text-muted"><small>Allows a user to reset passwords for databases.</small><p>
181+
</label>
182+
</div>
183+
</div>
184+
<div class="col-md-6 fuelux">
166185
<h4>SFTP Management</h4><hr />
167186
<div class="checkbox highlight">
168187
<label class="checkbox-custom highlight" data-initialize="checkbox">

0 commit comments

Comments
 (0)