Skip to content

Commit 74ea1aa

Browse files
committed
Push subuser creation service
1 parent 2a55708 commit 74ea1aa

File tree

23 files changed

+1077
-229
lines changed

23 files changed

+1077
-229
lines changed

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ interface ServerRepositoryInterface extends BaseRepositoryInterface
3636
*/
3737
public function create($id, $overrides = [], $start = false);
3838

39+
/**
40+
* Set an access token and associated permissions for a server.
41+
*
42+
* @param string $key
43+
* @param array $permissions
44+
* @return \Psr\Http\Message\ResponseInterface
45+
*/
46+
public function setSubuserKey($key, array $permissions);
47+
3948
/**
4049
* Update server details on the daemon.
4150
*
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface PermissionRepositoryInterface extends RepositoryInterface
28+
{
29+
}

app/Facades/Version.php renamed to app/Contracts/Repository/SubuserRepositoryInterface.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**
2+
/*
33
* Pterodactyl - Panel
44
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
55
*
@@ -22,19 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Facades;
25+
namespace Pterodactyl\Contracts\Repository;
2626

27-
use Illuminate\Support\Facades\Facade;
28-
29-
class Version extends Facade
27+
interface SubuserRepositoryInterface extends RepositoryInterface
3028
{
31-
/**
32-
* Returns the facade accessor class.
33-
*
34-
* @return strig
35-
*/
36-
protected static function getFacadeAccessor()
37-
{
38-
return '\Pterodactyl\Services\VersionService';
39-
}
4029
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Service\Helper;
26+
27+
class CdnVersionFetchingException extends \Exception
28+
{
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Service\Subuser;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class ServerSubuserExistsException extends DisplayException
30+
{
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Service\Subuser;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class UserIsServerOwnerException extends DisplayException
30+
{
31+
}

app/Http/Controllers/Admin/BaseController.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Prologue\Alerts\AlertsMessageBag;
2929
use Pterodactyl\Http\Controllers\Controller;
3030
use Pterodactyl\Http\Requests\Admin\BaseFormRequest;
31+
use Pterodactyl\Services\Helpers\SoftwareVersionService;
3132

3233
class BaseController extends Controller
3334
{
@@ -41,10 +42,26 @@ class BaseController extends Controller
4142
*/
4243
protected $settings;
4344

44-
public function __construct(AlertsMessageBag $alert, Settings $settings)
45-
{
45+
/**
46+
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
47+
*/
48+
protected $version;
49+
50+
/**
51+
* BaseController constructor.
52+
*
53+
* @param \Prologue\Alerts\AlertsMessageBag $alert
54+
* @param \Krucas\Settings\Settings $settings
55+
* @param \Pterodactyl\Services\Helpers\SoftwareVersionService $version
56+
*/
57+
public function __construct(
58+
AlertsMessageBag $alert,
59+
Settings $settings,
60+
SoftwareVersionService $version
61+
) {
4662
$this->alert = $alert;
4763
$this->settings = $settings;
64+
$this->version = $version;
4865
}
4966

5067
/**
@@ -54,7 +71,7 @@ public function __construct(AlertsMessageBag $alert, Settings $settings)
5471
*/
5572
public function getIndex()
5673
{
57-
return view('admin.index');
74+
return view('admin.index', ['version' => $this->version]);
5875
}
5976

6077
/**

app/Models/Permission.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
namespace Pterodactyl\Models;
2626

2727
use Illuminate\Database\Eloquent\Model;
28+
use Sofa\Eloquence\Contracts\CleansAttributes;
29+
use Sofa\Eloquence\Eloquence;
2830

29-
class Permission extends Model
31+
class Permission extends Model implements CleansAttributes
3032
{
33+
use Eloquence;
34+
3135
/**
3236
* Should timestamps be used on this model.
3337
*
@@ -118,12 +122,12 @@ class Permission extends Model
118122
/**
119123
* Return a collection of permissions available.
120124
*
121-
* @param array $single
122-
* @return \Illuminate\Support\Collection|array
125+
* @param bool $array
126+
* @return array|\Illuminate\Support\Collection
123127
*/
124-
public static function listPermissions($single = false)
128+
public static function getPermissions($array = false)
125129
{
126-
if ($single) {
130+
if ($array) {
127131
return collect(self::$permissions)->mapWithKeys(function ($item) {
128132
return $item;
129133
})->all();

app/Models/Subuser.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626

2727
use Illuminate\Database\Eloquent\Model;
2828
use Illuminate\Notifications\Notifiable;
29+
use Sofa\Eloquence\Contracts\CleansAttributes;
30+
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
31+
use Sofa\Eloquence\Eloquence;
32+
use Sofa\Eloquence\Validable;
2933

30-
class Subuser extends Model
34+
class Subuser extends Model implements CleansAttributes, ValidableContract
3135
{
32-
use Notifiable;
36+
use Eloquence, Notifiable, Validable;
3337

3438
/**
3539
* The table associated with the model.
@@ -62,6 +66,24 @@ class Subuser extends Model
6266
'server_id' => 'integer',
6367
];
6468

69+
/**
70+
* @var array
71+
*/
72+
protected static $applicationRules = [
73+
'user_id' => 'required',
74+
'server_id' => 'required',
75+
'daemonSecret' => 'required',
76+
];
77+
78+
/**
79+
* @var array
80+
*/
81+
protected static $dataIntegrityRules = [
82+
'user_id' => 'numeric|exists:users,id',
83+
'server_id' => 'numeric|exists:servers,id',
84+
'daemonSecret' => 'string',
85+
];
86+
6587
/**
6688
* Gets the server associated with a subuser.
6789
*

app/Repositories/Daemon/ServerRepository.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public function create($id, $overrides = [], $start = false)
8484
]);
8585
}
8686

87+
/**
88+
* {@inheritdoc}
89+
*/
90+
public function setSubuserKey($key, array $permissions)
91+
{
92+
return $this->getHttpClient()->request('PATCH', '/server', [
93+
'json' => [
94+
'keys' => [
95+
$key => $permissions,
96+
],
97+
],
98+
]);
99+
}
100+
87101
/**
88102
* {@inheritdoc}
89103
*/

0 commit comments

Comments
 (0)