Attach user to cache to prevent showing servers they can't access.

This commit is contained in:
Dane Everitt 2017-02-18 21:45:11 -05:00
parent 911434d033
commit f91e4c511e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 8 additions and 3 deletions

View file

@ -96,7 +96,7 @@ class Server extends Model
public static function byUuid($uuid)
{
// Results are cached because we call this functions a few times on page load.
$result = Cache::remember('Server.byUuid.' . $uuid, 60, function () use ($uuid) {
$result = Cache::remember('Server.byUuid.' . $uuid . Auth::user()->uuid, 60, function () use ($uuid) {
$query = self::with('service', 'node')->where(function ($q) use ($uuid) {
$q->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
});

View file

@ -24,6 +24,7 @@
namespace Pterodactyl\Observers;
use Auth;
use Cache;
use Carbon;
use Pterodactyl\Events;
@ -141,8 +142,8 @@ class ServerObserver
public function updated(Server $server)
{
// Clear Caches
Cache::forget('Server.byUuid.' . $server->uuid);
Cache::forget('Server.byUuid.' . $server->uuidShort);
Cache::forget('Server.byUuid.' . $server->uuid . Auth::user()->uuid);
Cache::forget('Server.byUuid.' . $server->uuidShort . Auth::user()->uuid);
event(new Events\Server\Updated($server));
}