Skip to content

Commit e4ef8ca

Browse files
committed
Fix model not found error when editing an existing subuser.
1 parent 205a10c commit e4ef8ca

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1515
* `[beta.2]` — New attempt at fixing the issues when rendering files in the browser file editor on certain browsers.
1616
* `[beta.2]` — Fixes broken auto-deploy time checking causing no tokens to work.
1717
* `[beta.2]` — Fixes display of subusers after creation.
18+
* `[beta.2]` — Fixes bug throwing model not found exception when editing an existing subuser.
1819

1920
### Changed
2021
* Deleting a server safely now continues even if the daemon reports a `HTTP/404` missing server error (requires `Daemon@0.4.0-beta.2.1`)

app/Repositories/SubuserRepository.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626

2727
use DB;
2828
use Validator;
29-
use Pterodactyl\Models;
29+
use Pterodactyl\Models\User;
30+
use Pterodactyl\Models\Server;
31+
use Pterodactyl\Models\Subuser;
32+
use Pterodactyl\Models\Permission;
3033
use Pterodactyl\Services\UuidService;
34+
use GuzzleHttp\Exception\TransferException;
3135
use Pterodactyl\Exceptions\DisplayException;
3236
use Pterodactyl\Exceptions\DisplayValidationException;
3337

@@ -57,7 +61,7 @@ class SubuserRepository
5761
*/
5862
public function create($sid, array $data)
5963
{
60-
$server = Models\Server::with('node')->findOrFail($sid);
64+
$server = Server::with('node')->findOrFail($sid);
6165

6266
$validator = Validator::make($data, [
6367
'permissions' => 'required|array',
@@ -72,7 +76,7 @@ public function create($sid, array $data)
7276

7377
try {
7478
// Determine if this user exists or if we need to make them an account.
75-
$user = Models\User::where('email', $data['email'])->first();
79+
$user = User::where('email', $data['email'])->first();
7680
if (! $user) {
7781
try {
7882
$repo = new UserRepository;
@@ -88,18 +92,18 @@ public function create($sid, array $data)
8892
}
8993
} elseif ($server->owner_id === $user->id) {
9094
throw new DisplayException('You cannot add the owner of a server as a subuser.');
91-
} elseif (Models\Subuser::select('id')->where('user_id', $user->id)->where('server_id', $server->id)->first()) {
95+
} elseif (Subuser::select('id')->where('user_id', $user->id)->where('server_id', $server->id)->first()) {
9296
throw new DisplayException('A subuser with that email already exists for this server.');
9397
}
9498

9599
$uuid = new UuidService;
96-
$subuser = Models\Subuser::create([
100+
$subuser = Subuser::create([
97101
'user_id' => $user->id,
98102
'server_id' => $server->id,
99103
'daemonSecret' => (string) $uuid->generate('servers', 'uuid'),
100104
]);
101105

102-
$perms = Models\Permission::list(true);
106+
$perms = Permission::list(true);
103107
$daemonPermissions = $this->coreDaemonPermissions;
104108

105109
foreach ($data['permissions'] as $permission) {
@@ -109,7 +113,7 @@ public function create($sid, array $data)
109113
array_push($daemonPermissions, $perms[$permission]);
110114
}
111115

112-
Models\Permission::create([
116+
Permission::create([
113117
'subuser_id' => $subuser->id,
114118
'permission' => $permission,
115119
]);
@@ -134,7 +138,7 @@ public function create($sid, array $data)
134138
DB::commit();
135139

136140
return $subuser;
137-
} catch (\GuzzleHttp\Exception\TransferException $ex) {
141+
} catch (TransferException $ex) {
138142
DB::rollBack();
139143
throw new DisplayException('There was an error attempting to connect to the daemon to add this user.', $ex);
140144
} catch (\Exception $ex) {
@@ -155,7 +159,7 @@ public function create($sid, array $data)
155159
*/
156160
public function delete($id)
157161
{
158-
$subuser = Models\Subuser::with('server.node')->findOrFail($id);
162+
$subuser = Subuser::with('server.node')->findOrFail($id);
159163
$server = $subuser->server;
160164

161165
DB::beginTransaction();
@@ -177,7 +181,7 @@ public function delete($id)
177181
}
178182
$subuser->delete();
179183
DB::commit();
180-
} catch (\GuzzleHttp\Exception\TransferException $ex) {
184+
} catch (TransferException $ex) {
181185
DB::rollBack();
182186
throw new DisplayException('There was an error attempting to connect to the daemon to delete this subuser.', $ex);
183187
} catch (\Exception $ex) {
@@ -208,7 +212,7 @@ public function update($id, array $data)
208212
throw new DisplayValidationException(json_encode($validator->all()));
209213
}
210214

211-
$subuser = Models\Subuser::with('server.node')->findOrFail($id);
215+
$subuser = Subuser::with('server.node')->findOrFail($id);
212216
$server = $subuser->server;
213217

214218
DB::beginTransaction();
@@ -227,7 +231,7 @@ public function update($id, array $data)
227231
if (! is_null($perms[$permission])) {
228232
array_push($daemonPermissions, $perms[$permission]);
229233
}
230-
Models\Permission::create([
234+
Permission::create([
231235
'subuser_id' => $subuser->id,
232236
'permission' => $permission,
233237
]);
@@ -249,7 +253,7 @@ public function update($id, array $data)
249253
]);
250254

251255
DB::commit();
252-
} catch (\GuzzleHttp\Exception\TransferException $ex) {
256+
} catch (TransferException $ex) {
253257
DB::rollBack();
254258
throw new DisplayException('There was an error attempting to connect to the daemon to update permissions.', $ex);
255259
} catch (\Exception $ex) {

0 commit comments

Comments
 (0)