Fix daemon key provider service
Handles missing keys if user is an admin or the server owner. Step in the right direction for #733 where all users have their own keys now. Still need to address admin status revocation in order to fully address that issue.
This commit is contained in:
parent
88562b5cd6
commit
b1f6058e31
8 changed files with 159 additions and 53 deletions
|
@ -39,6 +39,26 @@ class DaemonKeyRepository extends EloquentRepository implements DaemonKeyReposit
|
|||
return DaemonKey::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the server and user relations onto a key model.
|
||||
*
|
||||
* @param \Pterodactyl\Models\DaemonKey $key
|
||||
* @param bool $refresh
|
||||
* @return \Pterodactyl\Models\DaemonKey
|
||||
*/
|
||||
public function loadServerAndUserRelations(DaemonKey $key, bool $refresh = false): DaemonKey
|
||||
{
|
||||
if (! $key->relationLoaded('server') || $refresh) {
|
||||
$key->load('server');
|
||||
}
|
||||
|
||||
if (! $key->relationLoaded('user') || $refresh) {
|
||||
$key->load('user');
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -65,13 +65,16 @@ class SubuserRepository extends EloquentRepository implements SubuserRepositoryI
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return a subuser and associated permissions given a user_id and server_id.
|
||||
*
|
||||
* @param int $user
|
||||
* @param int $server
|
||||
* @return \Pterodactyl\Models\Subuser
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithPermissionsUsingUserAndServer($user, $server)
|
||||
public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser
|
||||
{
|
||||
Assert::integerish($user, 'First argument passed to getWithPermissionsUsingUserAndServer must be integer, received %s.');
|
||||
Assert::integerish($server, 'Second argument passed to getWithPermissionsUsingUserAndServer must be integer, received %s.');
|
||||
|
||||
$instance = $this->getBuilder()->with('permissions')->where([
|
||||
['user_id', '=', $user],
|
||||
['server_id', '=', $server],
|
||||
|
|
Reference in a new issue