fix: exclude any permissions not defined internally when updating or creating subusers (#4416)
This commit is contained in:
parent
597821b3bb
commit
c748fa9842
3 changed files with 154 additions and 31 deletions
|
@ -2,45 +2,22 @@
|
|||
|
||||
namespace Pterodactyl\Policies;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
||||
|
||||
class ServerPolicy
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* ServerPolicy constructor.
|
||||
*/
|
||||
public function __construct(CacheRepository $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user has the given permission on/for the server.
|
||||
*
|
||||
* @param string $permission
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkPermission(User $user, Server $server, $permission)
|
||||
protected function checkPermission(User $user, Server $server, string $permission): bool
|
||||
{
|
||||
$key = sprintf('ServerPolicy.%s.%s', $user->uuid, $server->uuid);
|
||||
$subuser = $server->subusers->where('user_id', $user->id)->first();
|
||||
if (!$subuser || empty($permission)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$permissions = $this->cache->remember($key, Carbon::now()->addSeconds(5), function () use ($user, $server) {
|
||||
/** @var \Pterodactyl\Models\Subuser|null $subuser */
|
||||
$subuser = $server->subusers()->where('user_id', $user->id)->first();
|
||||
|
||||
return $subuser ? $subuser->permissions : [];
|
||||
});
|
||||
|
||||
return in_array($permission, $permissions);
|
||||
return in_array($permission, $subuser->permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue