Skip to content

Commit 6dc1c15

Browse files
committed
Fix display of associated servers when viewing an administrative user in the Admin CP.
1 parent ae6b0f5 commit 6dc1c15

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
2222
* Mobile views are now more... viewable. Fixes `col-xs-6` usage thoughout the Admin CP where it was intended to be `col-md-6`.
2323
* Node Configuration tokens and Download tokens are stored using the cache helpers rather than a database to speed up functions and make use of auto-expiration/deletion functions.
2424
* Old daemon routes using `/remote` have been changed to use `/daemon`, panel changes now reflect this.
25+
* Only display servers that a user is owner of or subuser of in the Admin CP rather than all servers if the user is marked as an admin.
2526

2627
## v0.6.0-beta.2.1 (Courageous Carniadactylus)
2728
### Fixed

app/Models/User.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
5656
*/
5757
const USERNAME_RULES = 'regex:/^([\w\d\.\-]{1,255})$/';
5858

59+
/**
60+
* Level of servers to display when using access() on a user.
61+
*
62+
* @var string
63+
*/
64+
protected $accessLevel = 'all';
65+
5966
/**
6067
* The table associated with the model.
6168
*
@@ -194,6 +201,22 @@ public function serverAccessArray()
194201
)->pluck('id')->all();
195202
}
196203

204+
/**
205+
* Change the access level for a given call to `access()` on the user.
206+
*
207+
* @param string $level can be all, admin, subuser, owner
208+
* @return void
209+
*/
210+
public function setAccessLevel($level = 'all')
211+
{
212+
if (! in_array($level, ['all', 'admin', 'subuser', 'owner'])) {
213+
$level = 'all';
214+
}
215+
$this->accessLevel = $level;
216+
217+
return $this;
218+
}
219+
197220
/**
198221
* Returns an array of all servers a user is able to access.
199222
* Note: does not account for user admin status.
@@ -209,10 +232,27 @@ public function access(...$load)
209232
$query = Server::with(! empty($load) ? $load : ['service', 'node', 'allocation']);
210233
}
211234

212-
if (! $this->isRootAdmin()) {
235+
// If access level is set to owner, only display servers
236+
// that the user owns.
237+
if ($this->accessLevel === 'owner') {
238+
$query->where('owner_id', $this->id);
239+
}
240+
241+
// If set to all, display all servers they can access, including
242+
// those they access as an admin.
243+
//
244+
// If set to subuser, only return the servers they can access because
245+
// they are owner, or marked as a subuser of the server.
246+
if (($this->accessLevel === 'all' && ! $this->isRootAdmin()) || $this->accessLevel === 'subuser') {
213247
$query->whereIn('id', $this->serverAccessArray());
214248
}
215249

250+
// If set to admin, only display the servers a user can access
251+
// as an administrator (leaves out owned and subuser of).
252+
if ($this->accessLevel === 'admin' && $this->isRootAdmin()) {
253+
$query->whereNotIn('id', $this->serverAccessArray());
254+
}
255+
216256
return $query;
217257
}
218258

resources/themes/pterodactyl/admin/users/view.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
</tr>
127127
</thead>
128128
<tbody>
129-
@foreach($user->access()->get() as $server)
129+
@foreach($user->setAccessLevel('subuser')->access()->get() as $server)
130130
<tr>
131131
<td><a href="{{ route('server.index', $server->uuidShort) }}/"><i class="fa fa-tachometer"></i></a></td>
132132
<td><code>{{ $server->uuidShort }}</code></td>

0 commit comments

Comments
 (0)