diff --git a/app/Contracts/Repository/SubuserRepositoryInterface.php b/app/Contracts/Repository/SubuserRepositoryInterface.php deleted file mode 100644 index 1379e120b..000000000 --- a/app/Contracts/Repository/SubuserRepositoryInterface.php +++ /dev/null @@ -1,25 +0,0 @@ -transaction(function ($instance) use ($request, $subuser, $server) { - $this->repository->update($subuser->id, [ - 'permissions' => $this->getDefaultPermissions($request), - ]); + $subuser->update(['permissions' => $this->getDefaultPermissions($request)]); try { $this->serverRepository->setServer($server)->revokeUserJTI($subuser->user_id); diff --git a/app/Providers/RepositoryServiceProvider.php b/app/Providers/RepositoryServiceProvider.php index 8a0434f52..d9dc95b0e 100644 --- a/app/Providers/RepositoryServiceProvider.php +++ b/app/Providers/RepositoryServiceProvider.php @@ -11,7 +11,6 @@ use Pterodactyl\Repositories\Eloquent\UserRepository; use Pterodactyl\Repositories\Eloquent\ApiKeyRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\SessionRepository; -use Pterodactyl\Repositories\Eloquent\SubuserRepository; use Pterodactyl\Repositories\Eloquent\DatabaseRepository; use Pterodactyl\Repositories\Eloquent\LocationRepository; use Pterodactyl\Repositories\Eloquent\ScheduleRepository; @@ -28,7 +27,6 @@ use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Repositories\Eloquent\ServerVariableRepository; use Pterodactyl\Contracts\Repository\SessionRepositoryInterface; -use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface; use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface; @@ -60,7 +58,6 @@ class RepositoryServiceProvider extends ServiceProvider $this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class); $this->app->bind(SessionRepositoryInterface::class, SessionRepository::class); $this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class); - $this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class); $this->app->bind(TaskRepositoryInterface::class, TaskRepository::class); $this->app->bind(UserRepositoryInterface::class, UserRepository::class); } diff --git a/app/Repositories/Eloquent/SubuserRepository.php b/app/Repositories/Eloquent/SubuserRepository.php deleted file mode 100644 index 141378753..000000000 --- a/app/Repositories/Eloquent/SubuserRepository.php +++ /dev/null @@ -1,69 +0,0 @@ -relationLoaded('server') || $refresh) { - $subuser->load('server'); - } - - if (!$subuser->relationLoaded('user') || $refresh) { - $subuser->load('user'); - } - - return $subuser; - } - - /** - * Return a subuser with the associated permissions relationship. - */ - public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser - { - if (!$subuser->relationLoaded('permissions') || $refresh) { - $subuser->load('permissions'); - } - - if (!$subuser->relationLoaded('user') || $refresh) { - $subuser->load('user'); - } - - return $subuser; - } - - /** - * Return a subuser and associated permissions given a user_id and server_id. - * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser - { - $instance = $this->getBuilder()->with('permissions')->where([ - ['user_id', '=', $user], - ['server_id', '=', $server], - ])->first(); - - if (is_null($instance)) { - throw new RecordNotFoundException(); - } - - return $instance; - } -} diff --git a/app/Services/Subusers/SubuserCreationService.php b/app/Services/Subusers/SubuserCreationService.php index c207b0d07..ad63ce337 100644 --- a/app/Services/Subusers/SubuserCreationService.php +++ b/app/Services/Subusers/SubuserCreationService.php @@ -7,7 +7,7 @@ use Pterodactyl\Models\Server; use Pterodactyl\Models\Subuser; use Illuminate\Database\ConnectionInterface; use Pterodactyl\Services\Users\UserCreationService; -use Pterodactyl\Repositories\Eloquent\SubuserRepository; +use Pterodactyl\Exceptions\Model\DataValidationException; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; use Pterodactyl\Exceptions\Repository\RecordNotFoundException; use Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException; @@ -20,7 +20,6 @@ class SubuserCreationService */ public function __construct( private ConnectionInterface $connection, - private SubuserRepository $subuserRepository, private UserCreationService $userCreationService, private UserRepositoryInterface $userRepository ) { @@ -31,9 +30,9 @@ class SubuserCreationService * If the email address already belongs to a user on the system a new user will not * be created. * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException - * @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException + * @throws DataValidationException + * @throws ServerSubuserExistsException + * @throws UserIsServerOwnerException * @throws \Throwable */ public function handle(Server $server, string $email, array $permissions): Subuser @@ -46,7 +45,7 @@ class SubuserCreationService throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner')); } - $subuserCount = $this->subuserRepository->findCountWhere([['user_id', '=', $user->id], ['server_id', '=', $server->id]]); + $subuserCount = $server->subusers()->where('user_id', $user->id)->count(); if ($subuserCount !== 0) { throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists')); } @@ -64,7 +63,7 @@ class SubuserCreationService ]); } - return $this->subuserRepository->create([ + return Subuser::query()->create([ 'user_id' => $user->id, 'server_id' => $server->id, 'permissions' => array_unique($permissions),