Display total servers user can access in the Admin CP

closes #356
This commit is contained in:
Dane Everitt 2017-04-13 23:49:47 -04:00
parent 23e6e0510b
commit 6fda3b72e4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 17 additions and 5 deletions

View file

@ -44,7 +44,7 @@ class UserController extends Controller
*/
public function index(Request $request)
{
$users = User::withCount('servers');
$users = User::withCount('servers', 'subuserOf');
if (! is_null($request->input('query'))) {
$users->search($request->input('query'));

View file

@ -239,4 +239,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
{
return $this->hasMany(Server::class, 'owner_id');
}
/**
* Return all servers that user is listed as a subuser of directly.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function subuserOf()
{
return $this->hasMany(Subuser::class);
}
}

View file

@ -57,7 +57,8 @@
<th>Email</td>
<th>Client Name</th>
<th>Username</th>
<th>Servers</th>
<th class="text-center" data-toggle="tooltip" data-placement="top" title="Servers that this user is marked as the owner of.">Servers Owned</th>
<th class="text-center" data-toggle="tooltip" data-placement="top" title="Servers that this user can access because they are marked as a subuser.">Can Access</th>
<th></th>
</tr>
</thead>
@ -68,7 +69,8 @@
<td><a href="{{ route('admin.users.view', $user->id) }}">{{ $user->email }}</a></td>
<td>{{ $user->name_last }}, {{ $user->name_first }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->servers_count }}</td>
<td class="text-center">{{ $user->servers_count }}</td>
<td class="text-center">{{ $user->subuser_of_count }}</td>
<td class="text-center"><img src="https://www.gravatar.com/avatar/{{ md5(strtolower($user->email)) }}?s=20" class="img-circle" /></td>
</tr>
@endforeach

View file

@ -136,9 +136,9 @@
<td><a href="{{ route('admin.servers.view', $server->id) }}">{{ $server->name }}</a></td>
<td>
@if($server->owner_id === $user->id)
@lang('strings.owner')
<span class="label bg-purple">Owner</span>
@else
@lang('strings.subuser')
<span class="label bg-blue">Subuser</span>
@endif
</td>
<td><a href="{{ route('admin.nodes.view', $server->node->id) }}">{{ $server->node->name }}</a></td>