Skip to content

Commit 29de208

Browse files
committed
Merge branch 'release/v0.7.16'
2 parents bd58750 + 064d8e9 commit 29de208

File tree

18 files changed

+161
-34
lines changed

18 files changed

+161
-34
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.16 (Derelict Dermodactylus)
7+
### Fixed
8+
* Fixed the /api/application/servers endpoint erroring when including subusers or egg
9+
* Fixed bug in migration files causing failures when using MySQL 8.
10+
* Fixed missing redirect return when an error occurs while modifying database information.
11+
* Fixes bug in login attempt tracking.
12+
* Fixes a bug where certain URL encoded files would not be editable in the file manager.
13+
14+
### Added
15+
* The application API now includes the egg's name in the egg model's response.
16+
* The /api/application/servers endpoint can now include server's databases and subusers.
17+
618
## v0.7.15 (Derelict Dermodactylus)
719
### Fixed
820
* Fixes support for PHP 7.3 when running `composer install` commands due to a dependency that needed updating.

app/Http/Controllers/Admin/DatabaseController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function create(DatabaseHostFormRequest $request): RedirectResponse
131131
sprintf('There was an error while trying to connect to the host or while executing a query: "%s"', $exception->getMessage())
132132
)->flash();
133133

134-
redirect()->route('admin.databases')->withInput($request->validated());
134+
return redirect()->route('admin.databases')->withInput($request->validated());
135135
} else {
136136
throw $exception;
137137
}
@@ -165,7 +165,7 @@ public function update(DatabaseHostFormRequest $request, DatabaseHost $host): Re
165165
$this->alert->danger(
166166
sprintf('There was an error while trying to connect to the host or while executing a query: "%s"', $exception->getMessage())
167167
)->flash();
168-
$redirect->withInput($request->normalize());
168+
return $redirect->withInput($request->normalize());
169169
} else {
170170
throw $exception;
171171
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class LoginController extends Controller
2020
{
2121
use AuthenticatesUsers;
2222

23-
const USER_INPUT_FIELD = 'user';
24-
2523
/**
2624
* @var \Illuminate\Auth\AuthManager
2725
*/
@@ -64,14 +62,14 @@ class LoginController extends Controller
6462
*
6563
* @var int
6664
*/
67-
protected $lockoutTime;
65+
protected $decayMinutes;
6866

6967
/**
7068
* After how many attempts should logins be throttled and locked.
7169
*
7270
* @var int
7371
*/
74-
protected $maxLoginAttempts;
72+
protected $maxAttempts;
7573

7674
/**
7775
* LoginController constructor.
@@ -98,8 +96,8 @@ public function __construct(
9896
$this->google2FA = $google2FA;
9997
$this->repository = $repository;
10098

101-
$this->lockoutTime = $this->config->get('auth.lockout.time');
102-
$this->maxLoginAttempts = $this->config->get('auth.lockout.attempts');
99+
$this->decayMinutes = $this->config->get('auth.lockout.time');
100+
$this->maxAttempts = $this->config->get('auth.lockout.attempts');
103101
}
104102

105103
/**
@@ -112,7 +110,7 @@ public function __construct(
112110
*/
113111
public function login(Request $request)
114112
{
115-
$username = $request->input(self::USER_INPUT_FIELD);
113+
$username = $request->input($this->username());
116114
$useColumn = $this->getField($username);
117115

118116
if ($this->hasTooManyLoginAttempts($request)) {
@@ -209,20 +207,30 @@ protected function sendFailedLoginResponse(Request $request, Authenticatable $us
209207
{
210208
$this->incrementLoginAttempts($request);
211209
$this->fireFailedLoginEvent($user, [
212-
$this->getField($request->input(self::USER_INPUT_FIELD)) => $request->input(self::USER_INPUT_FIELD),
210+
$this->getField($request->input($this->username())) => $request->input($this->username()),
213211
]);
214212

215-
$errors = [self::USER_INPUT_FIELD => trans('auth.failed')];
213+
$errors = [$this->username() => trans('auth.failed')];
216214

217215
if ($request->expectsJson()) {
218216
return response()->json($errors, 422);
219217
}
220218

221219
return redirect()->route('auth.login')
222-
->withInput($request->only(self::USER_INPUT_FIELD))
220+
->withInput($request->only($this->username()))
223221
->withErrors($errors);
224222
}
225223

224+
/**
225+
* Get the login username to be used by the controller.
226+
*
227+
* @return string
228+
*/
229+
public function username()
230+
{
231+
return 'user';
232+
}
233+
226234
/**
227235
* Determine if the user is logging in using an email or username,.
228236
*

app/Models/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ public function user()
168168
/**
169169
* Gets the subusers associated with a server.
170170
*
171-
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
171+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
172172
*/
173173
public function subusers()
174174
{
175-
return $this->hasManyThrough(User::class, Subuser::class, 'server_id', 'id', 'id', 'user_id');
175+
return $this->hasMany(Subuser::class, 'server_id', 'id');
176176
}
177177

178178
/**

app/Services/Nests/NestDeletionService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function handle(int $nest): int
5151
{
5252
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
5353
if ($count > 0) {
54-
throw new HasActiveServersException(trans('exceptions.service.delete_has_servers'));
54+
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
5555
}
5656

5757
return $this->repository->delete($nest);

app/Transformers/Api/Application/EggTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function transform(Egg $model)
4141
return [
4242
'id' => $model->id,
4343
'uuid' => $model->uuid,
44+
'name' => $model->name,
4445
'nest' => $model->nest_id,
4546
'author' => $model->author,
4647
'description' => $model->description,

app/Transformers/Api/Application/ServerTransformer.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ServerTransformer extends BaseTransformer
2828
'variables',
2929
'location',
3030
'node',
31+
'databases',
3132
];
3233

3334
/**
@@ -131,7 +132,7 @@ public function includeSubusers(Server $server)
131132

132133
$server->loadMissing('subusers');
133134

134-
return $this->collection($server->getRelation('subusers'), $this->makeTransformer(UserTransformer::class), 'user');
135+
return $this->collection($server->getRelation('subusers'), $this->makeTransformer(SubuserTransformer::class), 'subuser');
135136
}
136137

137138
/**
@@ -195,22 +196,22 @@ public function includeNest(Server $server)
195196
}
196197

197198
/**
198-
* Return a generic array with service option information for this server.
199+
* Return a generic array with egg information for this server.
199200
*
200201
* @param \Pterodactyl\Models\Server $server
201202
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
202203
*
203204
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
204205
*/
205-
public function includeOption(Server $server)
206+
public function includeEgg(Server $server)
206207
{
207208
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
208209
return $this->null();
209210
}
210211

211212
$server->loadMissing('egg');
212213

213-
return $this->item($server->getRelation('egg'), $this->makeTransformer(EggVariableTransformer::class), 'egg');
214+
return $this->item($server->getRelation('egg'), $this->makeTransformer(EggTransformer::class), 'egg');
214215
}
215216

216217
/**
@@ -269,4 +270,23 @@ public function includeNode(Server $server)
269270

270271
return $this->item($server->getRelation('node'), $this->makeTransformer(NodeTransformer::class), 'node');
271272
}
273+
274+
/**
275+
* Return a generic array with database information for this server.
276+
*
277+
* @param \Pterodactyl\Models\Server $server
278+
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
279+
*
280+
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
281+
*/
282+
public function includeDatabases(Server $server)
283+
{
284+
if (! $this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) {
285+
return $this->null();
286+
}
287+
288+
$server->loadMissing('databases');
289+
290+
return $this->collection($server->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), 'databases');
291+
}
272292
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Pterodactyl\Transformers\Api\Application;
4+
5+
use Pterodactyl\Models\Subuser;
6+
use Pterodactyl\Models\Permission;
7+
use Pterodactyl\Services\Acl\Api\AdminAcl;
8+
9+
class SubuserTransformer extends BaseTransformer
10+
{
11+
/**
12+
* List of resources that can be included.
13+
*
14+
* @var array
15+
*/
16+
protected $availableIncludes = ['user', 'server'];
17+
18+
/**
19+
* Return the resource name for the JSONAPI output.
20+
*
21+
* @return string
22+
*/
23+
public function getResourceName(): string
24+
{
25+
return Subuser::RESOURCE_NAME;
26+
}
27+
28+
/**
29+
* Return a transformed Subuser model that can be consumed by external services.
30+
*
31+
* @param \Pterodactyl\Models\Subuser $subuser
32+
* @return array
33+
*/
34+
public function transform(Subuser $subuser): array
35+
{
36+
return [
37+
'id' => $subuser->id,
38+
'user_id' => $subuser->user_id,
39+
'server_id' => $subuser->server_id,
40+
'permissions' => $subuser->permissions->map(function (Permission $permission) {
41+
return $permission->permission;
42+
}),
43+
'created_at' => $this->formatTimestamp($subuser->created_at),
44+
'updated_at' => $this->formatTimestamp($subuser->updated_at),
45+
];
46+
}
47+
48+
/**
49+
* Return a generic item of user for this subuser.
50+
*
51+
* @param \Pterodactyl\Models\Subuser $subuser
52+
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
53+
*
54+
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
55+
*/
56+
public function includeUser(Subuser $subuser)
57+
{
58+
if (! $this->authorize(AdminAcl::RESOURCE_USERS)) {
59+
return $this->null();
60+
}
61+
62+
$subuser->loadMissing('user');
63+
64+
return $this->item($subuser->getRelation('user'), $this->makeTransformer(UserTransformer::class), 'user');
65+
}
66+
67+
/**
68+
* Return a generic item of server for this subuser.
69+
*
70+
* @param \Pterodactyl\Models\Subuser $subuser
71+
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
72+
*
73+
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
74+
*/
75+
public function includeServer(Subuser $subuser)
76+
{
77+
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
78+
return $this->null();
79+
}
80+
81+
$subuser->loadMissing('server');
82+
83+
return $this->item($subuser->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server');
84+
}
85+
}

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| change this value if you are not maintaining your own internal versions.
1010
*/
1111

12-
'version' => '0.7.15',
12+
'version' => '0.7.16',
1313

1414
/*
1515
|--------------------------------------------------------------------------

config/auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
|
1313
*/
1414
'lockout' => [
15-
'time' => 120,
15+
'time' => 2,
1616
'attempts' => 3,
1717
],
1818

0 commit comments

Comments
 (0)