Skip to content

Commit 295f09c

Browse files
authored
Merge branch 'develop' into feature/server-mounts
2 parents 29876e0 + 34a46a3 commit 295f09c

File tree

195 files changed

+5396
-5418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+5396
-5418
lines changed

.babel-plugin-macrosrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
twin: {
3+
preset: 'styled-components',
4+
autoCssProp: true,
5+
config: './tailwind.config.js',
6+
},
7+
styledComponents: {
8+
pure: true,
9+
displayName: false,
10+
fileName: false,
11+
},
12+
};

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "Release"
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: '12'
16+
17+
- name: Create release branch and bump version
18+
env:
19+
REF: ${{ github.ref }}
20+
run: |
21+
BRANCH=release/${REF:10}
22+
git config --local user.email "ci@pterodactyl.io"
23+
git config --local user.name "Pterodactyl CI"
24+
git checkout -b $BRANCH
25+
git push -u origin $BRANCH
26+
sed -i "s/ 'version' => 'canary',/ 'version' => '${REF:11}',/" config/app.php
27+
git add config/app.php
28+
git commit -m "bump version for release"
29+
git push
30+
31+
- name: Build assets
32+
run: |
33+
yarn install
34+
yarn run build:production
35+
36+
- name: Create release archive
37+
run: |
38+
rm -rf node_modules/ test/ codecov.yml CODE_OF_CONDUCT.md CONTRIBUTING.md phpunit.dusk.xml phpunit.xml Vagrantfile
39+
tar -czf panel.tar.gz *
40+
41+
- name: Extract changelog
42+
id: extract_changelog
43+
env:
44+
REF: ${{ github.ref }}
45+
run: |
46+
sed -n "/^## ${REF:10}/,/^## /{/^## /b;p}" CHANGELOG.md > ./RELEASE_CHANGELOG
47+
echo ::set-output name=version_name::`sed -nr "s/^## (${REF:10} .*)$/\1/p" CHANGELOG.md`
48+
49+
- name: Create checksum and add to changelog
50+
run: |
51+
SUM=`sha256sum panel.tar.gz`
52+
echo -e "\n#### SHA256 Checksum\n\n\`\`\`\n$SUM\n\`\`\`\n" >> ./RELEASE_CHANGELOG
53+
echo $SUM > checksum.txt
54+
55+
- name: Create Release
56+
id: create_release
57+
uses: actions/create-release@v1
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
tag_name: ${{ github.ref }}
62+
release_name: ${{ steps.extract_changelog.outputs.version_name }}
63+
body_path: ./RELEASE_CHANGELOG
64+
draft: true
65+
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
66+
67+
- name: Upload binary
68+
id: upload-release-archive
69+
uses: actions/upload-release-asset@v1
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
upload_url: ${{ steps.create_release.outputs.upload_url }}
74+
asset_path: panel.tar.gz
75+
asset_name: panel.tar.gz
76+
asset_content_type: application/gzip
77+
78+
- name: Upload checksum
79+
id: upload-release-checksum
80+
uses: actions/upload-release-asset@v1
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
with:
84+
upload_url: ${{ steps.create_release.outputs.upload_url }}
85+
asset_path: ./checksum.txt
86+
asset_name: checksum.txt
87+
asset_content_type: text/plain

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: tests
22
on:
33
push:
4+
branch-ignore:
5+
- 'master'
6+
- 'release/**'
47
pull_request:
58
jobs:
69
integration_tests:

app/Contracts/Repository/AllocationRepositoryInterface.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,9 @@
33
namespace Pterodactyl\Contracts\Repository;
44

55
use Illuminate\Support\Collection;
6-
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
76

87
interface AllocationRepositoryInterface extends RepositoryInterface
98
{
10-
/**
11-
* Set an array of allocation IDs to be assigned to a specific server.
12-
*
13-
* @param int|null $server
14-
* @param array $ids
15-
* @return int
16-
*/
17-
public function assignAllocationsToServer(int $server = null, array $ids): int;
18-
19-
/**
20-
* Return all of the allocations for a specific node.
21-
*
22-
* @param int $node
23-
* @return \Illuminate\Support\Collection
24-
*/
25-
public function getAllocationsForNode(int $node): Collection;
26-
27-
/**
28-
* Return all of the allocations for a node in a paginated format.
29-
*
30-
* @param int $node
31-
* @param int $perPage
32-
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
33-
*/
34-
public function getPaginatedAllocationsForNode(int $node, int $perPage = 100): LengthAwarePaginator;
35-
369
/**
3710
* Return all of the unique IPs that exist for a given node.
3811
*

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pterodactyl\Contracts\Repository;
44

5-
use Pterodactyl\Models\User;
65
use Pterodactyl\Models\Server;
76
use Illuminate\Support\Collection;
87
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@@ -107,16 +106,6 @@ public function loadDatabaseRelations(Server $server, bool $refresh = false): Se
107106
*/
108107
public function getDaemonServiceData(Server $server, bool $refresh = false): array;
109108

110-
/**
111-
* Return a paginated list of servers that a user can access at a given level.
112-
*
113-
* @param \Pterodactyl\Models\User $user
114-
* @param int $level
115-
* @param bool|int $paginate
116-
* @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
117-
*/
118-
public function filterUserAccessServers(User $user, int $level, $paginate = 25);
119-
120109
/**
121110
* Return a server by UUID.
122111
*

app/Http/Controllers/Api/Application/Nodes/AllocationController.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
44

55
use Pterodactyl\Models\Node;
6-
use Illuminate\Http\Response;
6+
use Illuminate\Http\JsonResponse;
77
use Pterodactyl\Models\Allocation;
88
use Pterodactyl\Services\Allocations\AssignmentService;
99
use Pterodactyl\Services\Allocations\AllocationDeletionService;
10-
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
1110
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
1211
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
1312
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
@@ -26,41 +25,32 @@ class AllocationController extends ApplicationApiController
2625
*/
2726
private $deletionService;
2827

29-
/**
30-
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
31-
*/
32-
private $repository;
33-
3428
/**
3529
* AllocationController constructor.
3630
*
3731
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
3832
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
39-
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
4033
*/
4134
public function __construct(
4235
AssignmentService $assignmentService,
43-
AllocationDeletionService $deletionService,
44-
AllocationRepositoryInterface $repository
36+
AllocationDeletionService $deletionService
4537
) {
4638
parent::__construct();
4739

4840
$this->assignmentService = $assignmentService;
4941
$this->deletionService = $deletionService;
50-
$this->repository = $repository;
5142
}
5243

5344
/**
5445
* Return all of the allocations that exist for a given node.
5546
*
5647
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request
48+
* @param \Pterodactyl\Models\Node $node
5749
* @return array
5850
*/
59-
public function index(GetAllocationsRequest $request): array
51+
public function index(GetAllocationsRequest $request, Node $node): array
6052
{
61-
$allocations = $this->repository->getPaginatedAllocationsForNode(
62-
$request->getModel(Node::class)->id, 50
63-
);
53+
$allocations = $node->allocations()->paginate(50);
6454

6555
return $this->fractal->collection($allocations)
6656
->transformWith($this->getTransformer(AllocationTransformer::class))
@@ -71,32 +61,35 @@ public function index(GetAllocationsRequest $request): array
7161
* Store new allocations for a given node.
7262
*
7363
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest $request
74-
* @return \Illuminate\Http\Response
64+
* @param \Pterodactyl\Models\Node $node
65+
* @return \Illuminate\Http\JsonResponse
7566
*
7667
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
7768
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
7869
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
7970
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
8071
*/
81-
public function store(StoreAllocationRequest $request): Response
72+
public function store(StoreAllocationRequest $request, Node $node): JsonResponse
8273
{
83-
$this->assignmentService->handle($request->getModel(Node::class), $request->validated());
74+
$this->assignmentService->handle($node, $request->validated());
8475

85-
return response('', 204);
76+
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
8677
}
8778

8879
/**
8980
* Delete a specific allocation from the Panel.
9081
*
9182
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
92-
* @return \Illuminate\Http\Response
83+
* @param \Pterodactyl\Models\Node $node
84+
* @param \Pterodactyl\Models\Allocation $allocation
85+
* @return \Illuminate\Http\JsonResponse
9386
*
9487
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
9588
*/
96-
public function delete(DeleteAllocationRequest $request): Response
89+
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): JsonResponse
9790
{
98-
$this->deletionService->handle($request->getModel(Allocation::class));
91+
$this->deletionService->handle($allocation);
9992

100-
return response('', 204);
93+
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
10194
}
10295
}

app/Http/Controllers/Api/Client/ClientApiController.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,40 @@
1010

1111
abstract class ClientApiController extends ApplicationApiController
1212
{
13+
/**
14+
* Returns only the includes which are valid for the given transformer.
15+
*
16+
* @param \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer
17+
* @param array $merge
18+
* @return string[]
19+
*/
20+
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = [])
21+
{
22+
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
23+
return in_array($datum, $transformer->getAvailableIncludes());
24+
});
25+
26+
return array_merge($filtered, $merge);
27+
}
28+
29+
/**
30+
* Returns the parsed includes for this request.
31+
*
32+
* @return string[]
33+
*/
34+
protected function parseIncludes()
35+
{
36+
$includes = $this->request->query('include') ?? [];
37+
38+
if (! is_string($includes)) {
39+
return $includes;
40+
}
41+
42+
return array_map(function ($item) {
43+
return trim($item);
44+
}, explode(',', $includes));
45+
}
46+
1347
/**
1448
* Return an instance of an application transformer.
1549
*

app/Http/Controllers/Api/Client/ClientController.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Pterodactyl\Http\Controllers\Api\Client;
44

55
use Pterodactyl\Models\User;
6+
use Pterodactyl\Models\Server;
67
use Pterodactyl\Models\Permission;
8+
use Spatie\QueryBuilder\QueryBuilder;
79
use Pterodactyl\Repositories\Eloquent\ServerRepository;
810
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
911
use Pterodactyl\Http\Requests\Api\Client\GetServersRequest;
@@ -36,32 +38,36 @@ public function __construct(ServerRepository $repository)
3638
*/
3739
public function index(GetServersRequest $request): array
3840
{
39-
// Check for the filter parameter on the request.
40-
switch ($request->input('filter')) {
41-
case 'all':
42-
$filter = User::FILTER_LEVEL_ALL;
43-
break;
44-
case 'admin':
45-
$filter = User::FILTER_LEVEL_ADMIN;
46-
break;
47-
case 'owner':
48-
$filter = User::FILTER_LEVEL_OWNER;
49-
break;
50-
case 'subuser-of':
51-
default:
52-
$filter = User::FILTER_LEVEL_SUBUSER;
53-
break;
41+
$user = $request->user();
42+
$level = $request->getFilterLevel();
43+
$transformer = $this->getTransformer(ServerTransformer::class);
44+
45+
// Start the query builder and ensure we eager load any requested relationships from the request.
46+
$builder = Server::query()->with($this->getIncludesForTransformer($transformer, ['node']));
47+
48+
if ($level === User::FILTER_LEVEL_OWNER) {
49+
$builder = $builder->where('owner_id', $request->user()->id);
50+
}
51+
// If set to all, display all servers they can access, including those they access as an
52+
// admin. If set to subuser, only return the servers they can access because they are owner,
53+
// or marked as a subuser of the server.
54+
elseif (($level === User::FILTER_LEVEL_ALL && ! $user->root_admin) || $level === User::FILTER_LEVEL_SUBUSER) {
55+
$builder = $builder->whereIn('id', $user->accessibleServers()->pluck('id')->all());
5456
}
57+
// If set to admin, only display the servers a user can access because they are an administrator.
58+
// This means only servers the user would not have access to if they were not an admin (because they
59+
// are not an owner or subuser) are returned.
60+
elseif ($level === User::FILTER_LEVEL_ADMIN && $user->root_admin) {
61+
$builder = $builder->whereNotIn('id', $user->accessibleServers()->pluck('id')->all());
62+
}
63+
64+
$builder = QueryBuilder::for($builder)->allowedFilters(
65+
'uuid', 'name', 'external_id'
66+
);
5567

56-
$servers = $this->repository
57-
->setSearchTerm($request->input('query'))
58-
->filterUserAccessServers(
59-
$request->user(), $filter, config('pterodactyl.paginate.frontend.servers')
60-
);
68+
$servers = $builder->paginate(min($request->query('per_page', 50), 100))->appends($request->query());
6169

62-
return $this->fractal->collection($servers)
63-
->transformWith($this->getTransformer(ServerTransformer::class))
64-
->toArray();
70+
return $this->fractal->transformWith($transformer)->collection($servers)->toArray();
6571
}
6672

6773
/**

app/Http/Controllers/Api/Client/Servers/FileController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function createFolder(CreateFolderRequest $request, Server $server): Resp
159159
{
160160
$this->fileRepository
161161
->setServer($server)
162-
->createDirectory($request->input('name'), $request->input('directory', '/'));
162+
->createDirectory($request->input('name'), $request->input('root', '/'));
163163

164164
return Response::create('', Response::HTTP_NO_CONTENT);
165165
}

0 commit comments

Comments
 (0)