Add back server sidebar list

This commit is contained in:
Dane Everitt 2018-02-24 13:58:48 -06:00
parent 5b6d3b8325
commit a1e704d3a7
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 99 additions and 18 deletions

View file

@ -103,9 +103,10 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
*
* @param \Pterodactyl\Models\User $user
* @param int $level
* @return \Illuminate\Pagination\LengthAwarePaginator
* @param bool $paginate
* @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
*/
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator;
public function filterUserAccessServers(User $user, int $level, bool $paginate = true);
/**
* Return a server by UUID.

View file

@ -0,0 +1,51 @@
<?php
namespace Pterodactyl\Http\ViewComposers;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Pterodactyl\Models\User;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class ServerListComposer
{
/**
* @var \Illuminate\Http\Request
*/
private $request;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/**
* ServerListComposer constructor.
*
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(Request $request, ServerRepositoryInterface $repository)
{
$this->request = $request;
$this->repository = $repository;
}
/**
* Attach a list of servers the user can access to the view.
*
* @param \Illuminate\View\View $view
*/
public function compose(View $view)
{
if (! $this->request->user()) {
return;
}
$servers = $this->repository
->setColumns(['id', 'owner_id', 'uuidShort', 'name', 'description'])
->filterUserAccessServers($this->request->user(), User::FILTER_LEVEL_SUBUSER, false);
$view->with('sidebarServerList', $servers);
}
}

View file

@ -1,15 +1,9 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Providers;
use Illuminate\Support\ServiceProvider;
use Pterodactyl\Http\ViewComposers\ServerListComposer;
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
class ViewComposerServiceProvider extends ServiceProvider
@ -20,5 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider
public function boot()
{
$this->app->make('view')->composer('server.*', ServerDataComposer::class);
// Add data to make the sidebar work when viewing a server.
$this->app->make('view')->composer(['server.*'], ServerListComposer::class);
}
}

View file

@ -211,11 +211,12 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
*
* @param \Pterodactyl\Models\User $user
* @param int $level
* @return \Illuminate\Pagination\LengthAwarePaginator
* @param bool $paginate
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
*/
public function filterUserAccessServers(User $user, int $level): LengthAwarePaginator
public function filterUserAccessServers(User $user, int $level, bool $paginate = true)
{
$instance = $this->getBuilder()->with(['user']);
$instance = $this->getBuilder()->select($this->getColumns())->with(['user']);
// If access level is set to owner, only display servers
// that the user owns.
@ -224,8 +225,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
}
// If set to all, display all servers they can access, including
// those they access as an admin. If set to subuser, only return the servers they can access because
// they are owner, or marked as a subuser of the server.
// those they access as an admin. If set to subuser, only return
// the servers they can access because they are owner, or marked
// as a subuser of the server.
elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) {
$instance->whereIn('id', $this->getUserAccessServers($user->id));
}
@ -236,7 +238,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
$instance->whereNotIn('id', $this->getUserAccessServers($user->id));
}
return $instance->search($this->getSearchTerm())->paginate(25);
$instance->search($this->getSearchTerm());
return $paginate ? $instance->paginate(25) : $instance->get();
}
/**