Merge branch 'develop' into feature/server-transfers-actually
This commit is contained in:
commit
fd4de9168a
49 changed files with 1000 additions and 37 deletions
|
@ -18,7 +18,7 @@ namespace Pterodactyl\Models;
|
|||
* @property \Pterodactyl\Models\Server|null $server
|
||||
* @property \Pterodactyl\Models\Node $node
|
||||
*/
|
||||
class Allocation extends Validable
|
||||
class Allocation extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
@ -75,7 +75,7 @@ class Allocation extends Validable
|
|||
/**
|
||||
* Accessor to automatically provide the IP alias if defined.
|
||||
*
|
||||
* @param null|string $value
|
||||
* @param string|null $value
|
||||
* @return string
|
||||
*/
|
||||
public function getAliasAttribute($value)
|
||||
|
@ -86,7 +86,7 @@ class Allocation extends Validable
|
|||
/**
|
||||
* Accessor to quickly determine if this allocation has an alias.
|
||||
*
|
||||
* @param null|string $value
|
||||
* @param string|null $value
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasAliasAttribute($value)
|
||||
|
|
|
@ -16,7 +16,7 @@ use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class ApiKey extends Validable
|
||||
class ApiKey extends Model
|
||||
{
|
||||
const RESOURCE_NAME = 'api_key';
|
||||
|
||||
|
|
82
app/Models/Backup.php
Normal file
82
app/Models/Backup.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $server_id
|
||||
* @property int $uuid
|
||||
* @property string $name
|
||||
* @property string $ignored_files
|
||||
* @property string $disk
|
||||
* @property string|null $sha256_hash
|
||||
* @property int $bytes
|
||||
* @property \Carbon\CarbonImmutable|null $completed_at
|
||||
* @property \Carbon\CarbonImmutable $created_at
|
||||
* @property \Carbon\CarbonImmutable $updated_at
|
||||
* @property \Carbon\CarbonImmutable|null $deleted_at
|
||||
*
|
||||
* @property \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
class Backup extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
const RESOURCE_NAME = 'backup';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'backups';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'bytes' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [
|
||||
'completed_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'sha256_hash' => null,
|
||||
'bytes' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
'server_id' => 'bail|required|numeric|exists:servers,id',
|
||||
'uuid' => 'required|uuid',
|
||||
'name' => 'required|string',
|
||||
'ignored_files' => 'string',
|
||||
'disk' => 'required|string',
|
||||
'sha256_hash' => 'nullable|string',
|
||||
'bytes' => 'numeric',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class DaemonKey extends Validable
|
||||
class DaemonKey extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class Database extends Validable
|
||||
class Database extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class DatabaseHost extends Validable
|
||||
class DatabaseHost extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Pterodactyl\Models;
|
|||
* @property \Pterodactyl\Models\Egg|null $scriptFrom
|
||||
* @property \Pterodactyl\Models\Egg|null $configFrom
|
||||
*/
|
||||
class Egg extends Validable
|
||||
class Egg extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class EggVariable extends Validable
|
||||
class EggVariable extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class Location extends Validable
|
||||
class Location extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -5,11 +5,18 @@ namespace Pterodactyl\Models;
|
|||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
||||
|
||||
abstract class Validable extends Model
|
||||
abstract class Model extends IlluminateModel
|
||||
{
|
||||
/**
|
||||
* Set to true to return immutable Carbon date instances from the model.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = false;
|
||||
|
||||
/**
|
||||
* Determines if the model should undergo data validation before it is saved
|
||||
* to the database.
|
||||
|
@ -47,7 +54,7 @@ abstract class Validable extends Model
|
|||
|
||||
static::$validatorFactory = Container::getInstance()->make(Factory::class);
|
||||
|
||||
static::saving(function (Validable $model) {
|
||||
static::saving(function (Model $model) {
|
||||
return $model->validate();
|
||||
});
|
||||
}
|
||||
|
@ -148,4 +155,19 @@ abstract class Validable extends Model
|
|||
)
|
||||
)->passes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a timestamp as DateTime object.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Support\Carbon|\Carbon\CarbonImmutable
|
||||
*/
|
||||
protected function asDateTime($value)
|
||||
{
|
||||
if (! $this->immutableDates) {
|
||||
return parent::asDateTime($value);
|
||||
}
|
||||
|
||||
return parent::asDateTime($value)->toImmutable();
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace Pterodactyl\Models;
|
|||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Egg[] $eggs
|
||||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Pack[] $packs
|
||||
*/
|
||||
class Nest extends Validable
|
||||
class Nest extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -32,9 +32,10 @@ use Pterodactyl\Models\Traits\Searchable;
|
|||
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
|
||||
* @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations
|
||||
*/
|
||||
class Node extends Validable
|
||||
class Node extends Model
|
||||
{
|
||||
use Notifiable, Searchable;
|
||||
use Notifiable;
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -20,7 +20,7 @@ use Pterodactyl\Models\Traits\Searchable;
|
|||
* @property \Pterodactyl\Models\Egg|null $egg
|
||||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
|
||||
*/
|
||||
class Pack extends Validable
|
||||
class Pack extends Model
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Permission extends Validable
|
||||
class Permission extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
@ -37,6 +37,12 @@ class Permission extends Validable
|
|||
const ACTION_USER_UPDATE = 'user.update';
|
||||
const ACTION_USER_DELETE = 'user.delete';
|
||||
|
||||
const ACTION_BACKUP_READ = 'backup.read';
|
||||
const ACTION_BACKUP_CREATE = 'backup.create';
|
||||
const ACTION_BACKUP_UPDATE = 'backup.update';
|
||||
const ACTION_BACKUP_DELETE = 'backup.delete';
|
||||
const ACTION_BACKUP_DOWNLOAD = 'backup.download';
|
||||
|
||||
const ACTION_ALLOCATION_READ = 'allocation.read';
|
||||
const ACTION_ALLOCIATION_UPDATE = 'allocation.update';
|
||||
|
||||
|
@ -135,6 +141,17 @@ class Permission extends Validable
|
|||
],
|
||||
],
|
||||
|
||||
'backup' => [
|
||||
'description' => 'Permissions that control a user\'s ability to generate and manage server backups.',
|
||||
'keys' => [
|
||||
'create' => 'Allows a user to create new backups for this server.',
|
||||
'read' => 'Allows a user to view all backups that exist for this server.',
|
||||
'update' => '',
|
||||
'delete' => 'Allows a user to remove backups from the system.',
|
||||
'download' => 'Allows a user to download backups.',
|
||||
],
|
||||
],
|
||||
|
||||
// Controls permissions for editing or viewing a server's allocations.
|
||||
'allocation' => [
|
||||
'description' => 'Permissions that control a user\'s ability to modify the port allocations for this server.',
|
||||
|
|
|
@ -25,7 +25,7 @@ use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
|||
* @property \Pterodactyl\Models\Server $server
|
||||
* @property \Pterodactyl\Models\Task[]|\Illuminate\Support\Collection $tasks
|
||||
*/
|
||||
class Schedule extends Validable
|
||||
class Schedule extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
|
|
@ -52,10 +52,13 @@ use Znck\Eloquent\Traits\BelongsToThrough;
|
|||
* @property \Pterodactyl\Models\DaemonKey $key
|
||||
* @property \Pterodactyl\Models\DaemonKey[]|\Illuminate\Database\Eloquent\Collection $keys
|
||||
* @property \Pterodactyl\Models\ServerTransfer $transfer
|
||||
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
|
||||
*/
|
||||
class Server extends Validable
|
||||
class Server extends Model
|
||||
{
|
||||
use BelongsToThrough, Notifiable, Searchable;
|
||||
use BelongsToThrough;
|
||||
use Notifiable;
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
|
@ -340,7 +343,7 @@ class Server extends Validable
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all of the daemon keys belonging to this server.
|
||||
* Returns the associated server transfer.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
|
@ -348,4 +351,12 @@ class Server extends Validable
|
|||
{
|
||||
return $this->hasOne(ServerTransfer::class)->orderByDesc('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function backups()
|
||||
{
|
||||
return $this->hasMany(Backup::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
class Setting extends Validable
|
||||
class Setting extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
|
|
@ -15,7 +15,7 @@ use Illuminate\Notifications\Notifiable;
|
|||
* @property \Pterodactyl\Models\User $user
|
||||
* @property \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
class Subuser extends Validable
|
||||
class Subuser extends Model
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
|||
* @property \Pterodactyl\Models\Schedule $schedule
|
||||
* @property \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
class Task extends Validable
|
||||
class Task extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
|
||||
|
|
|
@ -40,12 +40,17 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
|||
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
|
||||
* @property \Pterodactyl\Models\DaemonKey[]|\Illuminate\Database\Eloquent\Collection $keys
|
||||
*/
|
||||
class User extends Validable implements
|
||||
class User extends Model implements
|
||||
AuthenticatableContract,
|
||||
AuthorizableContract,
|
||||
CanResetPasswordContract
|
||||
{
|
||||
use Authenticatable, Authorizable, AvailableLanguages, CanResetPassword, Notifiable, Searchable;
|
||||
use Authenticatable;
|
||||
use Authorizable;
|
||||
use AvailableLanguages;
|
||||
use CanResetPassword;
|
||||
use Notifiable;
|
||||
use Searchable;
|
||||
|
||||
const USER_LEVEL_USER = 0;
|
||||
const USER_LEVEL_ADMIN = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue