2016-11-27 00:29:57 +00:00
|
|
|
<?php
|
2017-08-24 02:34:11 +00:00
|
|
|
/*
|
2016-11-27 00:29:57 +00:00
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-11-27 00:29:57 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-24 02:34:11 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2016-11-27 00:29:57 +00:00
|
|
|
|
2017-08-26 18:31:18 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Models\Subuser;
|
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
2016-11-27 00:29:57 +00:00
|
|
|
|
2017-08-24 02:34:11 +00:00
|
|
|
class SubuserRepository extends EloquentRepository implements SubuserRepositoryInterface
|
2016-11-27 00:29:57 +00:00
|
|
|
{
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-08-24 02:34:11 +00:00
|
|
|
* {@inheritdoc}
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-08-24 02:34:11 +00:00
|
|
|
public function model()
|
2016-11-27 00:29:57 +00:00
|
|
|
{
|
2017-08-24 02:34:11 +00:00
|
|
|
return Subuser::class;
|
2016-11-27 00:29:57 +00:00
|
|
|
}
|
2017-08-26 18:31:18 +00:00
|
|
|
|
2017-08-26 23:08:11 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithServer($id)
|
|
|
|
{
|
|
|
|
Assert::numeric($id, 'First argument passed to getWithServer must be numeric, received %s.');
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$instance = $this->getBuilder()->with('server', 'user')->find($id, $this->getColumns());
|
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithPermissions($id)
|
|
|
|
{
|
|
|
|
Assert::numeric($id, 'First argument passed to getWithPermissions must be numeric, received %s.');
|
|
|
|
|
|
|
|
$instance = $this->getBuilder()->with('permissions', 'user')->find($id, $this->getColumns());
|
2017-08-26 23:08:11 +00:00
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2017-09-24 01:45:25 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithPermissionsUsingUserAndServer($user, $server)
|
|
|
|
{
|
|
|
|
Assert::integerish($user, 'First argument passed to getWithPermissionsUsingUserAndServer must be integer, received %s.');
|
|
|
|
Assert::integerish($server, 'Second argument passed to getWithPermissionsUsingUserAndServer must be integer, received %s.');
|
|
|
|
|
|
|
|
$instance = $this->getBuilder()->with('permissions')->where([
|
|
|
|
['user_id', '=', $user],
|
|
|
|
['server_id', '=', $server],
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($instance)) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2017-08-26 18:31:18 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithServerAndPermissions($id)
|
|
|
|
{
|
|
|
|
Assert::numeric($id, 'First argument passed to getWithServerAndPermissions must be numeric, received %s.');
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$instance = $this->getBuilder()->with('server', 'permission', 'user')->find($id, $this->getColumns());
|
2017-08-26 18:31:18 +00:00
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2017-09-24 01:45:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithKey($user, $server)
|
|
|
|
{
|
|
|
|
Assert::integerish($user, 'First argument passed to getWithKey must be integer, received %s.');
|
|
|
|
Assert::integerish($server, 'Second argument passed to getWithKey must be integer, received %s.');
|
|
|
|
|
|
|
|
$instance = $this->getBuilder()->with('key')->where([
|
|
|
|
['user_id', '=', $user],
|
|
|
|
['server_id', '=', $server],
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($instance)) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2016-11-27 00:29:57 +00:00
|
|
|
}
|