mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-27 10:33:44 +02:00
Update last of existing services to use repositories, includes unit tests
Also update PHPDocs on all the repository interfaces and classes to be correct.
This commit is contained in:
@@ -24,24 +24,23 @@
|
||||
|
||||
namespace Pterodactyl\Services;
|
||||
|
||||
use Pterodactyl\Models\APIPermission;
|
||||
use Pterodactyl\Exceptions\Model\DataValidationException;
|
||||
use Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface;
|
||||
|
||||
class ApiPermissionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Models\APIPermission
|
||||
* @var \Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface
|
||||
*/
|
||||
protected $model;
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* ApiPermissionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Models\APIPermission $model
|
||||
* @param \Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(APIPermission $model)
|
||||
public function __construct(ApiPermissionRepositoryInterface $repository)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,16 +54,11 @@ class ApiPermissionService
|
||||
*/
|
||||
public function create($key, $permission)
|
||||
{
|
||||
$instance = $this->model->newInstance([
|
||||
// @todo handle an array of permissions to do a mass assignment?
|
||||
return $this->repository->withoutFresh()->create([
|
||||
'key_id' => $key,
|
||||
'permission' => $permission,
|
||||
]);
|
||||
|
||||
if (! $instance->save()) {
|
||||
throw new DataValidationException($instance->getValidator());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,6 +68,6 @@ class ApiPermissionService
|
||||
*/
|
||||
public function getPermissions()
|
||||
{
|
||||
return APIPermission::PERMISSIONS;
|
||||
return $this->repository->getModel()::CONST_PERMISSIONS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user