From 9d64c6751b524dadf8086360fd5c0548404dbbc2 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 17 Jul 2021 15:18:05 -0600 Subject: [PATCH] app: update models --- app/Models/AdminRole.php | 2 +- app/Models/Allocation.php | 2 +- app/Models/ApiKey.php | 2 +- app/Models/AuditLog.php | 2 +- app/Models/Backup.php | 4 ++-- app/Models/Database.php | 2 +- app/Models/DatabaseHost.php | 2 +- app/Models/Egg.php | 2 +- app/Models/EggVariable.php | 2 +- app/Models/Location.php | 2 +- app/Models/Model.php | 4 ++-- app/Models/Mount.php | 4 +--- app/Models/Nest.php | 5 +---- app/Models/Node.php | 5 +---- app/Models/Permission.php | 2 +- app/Models/RecoveryToken.php | 10 ++-------- app/Models/Schedule.php | 5 +---- app/Models/Server.php | 5 +---- app/Models/ServerTransfer.php | 2 +- app/Models/ServerVariable.php | 11 +++-------- app/Models/Setting.php | 2 +- app/Models/Subuser.php | 2 +- app/Models/Task.php | 2 +- app/Models/User.php | 2 +- app/Models/UserSSHKey.php | 26 ++++++++++++++++++++++++++ 25 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 app/Models/UserSSHKey.php diff --git a/app/Models/AdminRole.php b/app/Models/AdminRole.php index 9d7ddb322..3f4b44ea2 100644 --- a/app/Models/AdminRole.php +++ b/app/Models/AdminRole.php @@ -48,7 +48,7 @@ class AdminRole extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'name' => 'required|string|max:64', 'description' => 'nullable|string|max:255', 'sort_id' => 'sometimes|numeric', diff --git a/app/Models/Allocation.php b/app/Models/Allocation.php index 9363b4063..c01444951 100644 --- a/app/Models/Allocation.php +++ b/app/Models/Allocation.php @@ -53,7 +53,7 @@ class Allocation extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'node_id' => 'required|exists:nodes,id', 'ip' => 'required|ip', 'port' => 'required|numeric|between:1024,65535', diff --git a/app/Models/ApiKey.php b/app/Models/ApiKey.php index 4a54697ac..80b3df853 100644 --- a/app/Models/ApiKey.php +++ b/app/Models/ApiKey.php @@ -97,7 +97,7 @@ class ApiKey extends Model * * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'user_id' => 'required|exists:users,id', 'key_type' => 'present|integer|min:0|max:4', 'identifier' => 'required|string|size:16|unique:api_keys,identifier', diff --git a/app/Models/AuditLog.php b/app/Models/AuditLog.php index 1cd942e95..14d53af26 100644 --- a/app/Models/AuditLog.php +++ b/app/Models/AuditLog.php @@ -63,7 +63,7 @@ class AuditLog extends Model /** * @var bool */ - protected $immutableDates = true; + protected bool $immutableDates = true; /** * @var string[] diff --git a/app/Models/Backup.php b/app/Models/Backup.php index 26dcc7242..95503ecb0 100644 --- a/app/Models/Backup.php +++ b/app/Models/Backup.php @@ -40,7 +40,7 @@ class Backup extends Model /** * @var bool */ - protected $immutableDates = true; + protected bool $immutableDates = true; /** * @var array @@ -79,7 +79,7 @@ class Backup extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'server_id' => 'bail|required|numeric|exists:servers,id', 'uuid' => 'required|uuid', 'is_successful' => 'boolean', diff --git a/app/Models/Database.php b/app/Models/Database.php index b09545da8..291604632 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -61,7 +61,7 @@ class Database extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'server_id' => 'required|numeric|exists:servers,id', 'database_host_id' => 'required|exists:database_hosts,id', 'database' => 'required|string|alpha_dash|between:3,48', diff --git a/app/Models/DatabaseHost.php b/app/Models/DatabaseHost.php index 323a3cc8f..a2cc2719c 100644 --- a/app/Models/DatabaseHost.php +++ b/app/Models/DatabaseHost.php @@ -24,7 +24,7 @@ class DatabaseHost extends Model /** * @var bool */ - protected $immutableDates = true; + protected bool $immutableDates = true; /** * The table associated with the model. diff --git a/app/Models/Egg.php b/app/Models/Egg.php index 6e2c26802..c8698e05a 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -111,7 +111,7 @@ class Egg extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'nest_id' => 'required|bail|numeric|exists:nests,id', 'uuid' => 'required|string|size:36', 'name' => 'required|string|max:191', diff --git a/app/Models/EggVariable.php b/app/Models/EggVariable.php index 99966da3a..64e2234ad 100644 --- a/app/Models/EggVariable.php +++ b/app/Models/EggVariable.php @@ -40,7 +40,7 @@ class EggVariable extends Model /** * @var bool */ - protected $immutableDates = true; + protected bool $immutableDates = true; /** * The table associated with the model. diff --git a/app/Models/Location.php b/app/Models/Location.php index bc9a1fb4f..df04eb417 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -38,7 +38,7 @@ class Location extends Model * * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'short' => 'required|string|between:1,60|unique:locations,short', 'long' => 'string|nullable|between:1,191', ]; diff --git a/app/Models/Model.php b/app/Models/Model.php index 42cd92246..184b3d1c1 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -20,7 +20,7 @@ abstract class Model extends IlluminateModel * * @var bool */ - protected $immutableDates = false; + protected bool $immutableDates = false; /** * Determines if the model should undergo data validation before it is saved @@ -45,7 +45,7 @@ abstract class Model extends IlluminateModel /** * @var array */ - public static $validationRules = []; + public static array $validationRules = []; /** * Listen for the model saving event and fire off the validation diff --git a/app/Models/Mount.php b/app/Models/Mount.php index c1eb7a3a1..435b58a4f 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -52,10 +52,8 @@ class Mount extends Model /** * Rules verifying that the data being stored matches the expectations of the database. - * - * @var string */ - public static $validationRules = [ + public static array $validationRules = [ 'name' => 'required|string|min:2|max:64|unique:mounts,name', 'description' => 'nullable|string|max:191', 'source' => 'required|string', diff --git a/app/Models/Nest.php b/app/Models/Nest.php index 9a48f8b61..8728f3fe1 100644 --- a/app/Models/Nest.php +++ b/app/Models/Nest.php @@ -38,10 +38,7 @@ class Nest extends Model 'description', ]; - /** - * @var array - */ - public static $validationRules = [ + public static array $validationRules = [ 'author' => 'sometimes|string|email', 'name' => 'required|string|max:191', 'description' => 'nullable|string', diff --git a/app/Models/Node.php b/app/Models/Node.php index b91e29d54..052b352a2 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -100,10 +100,7 @@ class Node extends Model 'description', 'maintenance_mode', ]; - /** - * @var array - */ - public static $validationRules = [ + public static array $validationRules = [ 'name' => 'required|regex:/^([\w .-]{1,100})$/', 'description' => 'string|nullable', 'location_id' => 'required|exists:locations,id', diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 5a0fc95f8..aa505398b 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -96,7 +96,7 @@ class Permission extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'subuser_id' => 'required|numeric|min:1', 'permission' => 'required|string', ]; diff --git a/app/Models/RecoveryToken.php b/app/Models/RecoveryToken.php index 0244c7bca..ff139b862 100644 --- a/app/Models/RecoveryToken.php +++ b/app/Models/RecoveryToken.php @@ -21,15 +21,9 @@ class RecoveryToken extends Model */ public $timestamps = true; - /** - * @var bool - */ - protected $immutableDates = true; + protected bool $immutableDates = true; - /** - * @var string[] - */ - public static $validationRules = [ + public static array $validationRules = [ 'token' => 'required|string', ]; diff --git a/app/Models/Schedule.php b/app/Models/Schedule.php index 82a43c732..24588b891 100644 --- a/app/Models/Schedule.php +++ b/app/Models/Schedule.php @@ -105,10 +105,7 @@ class Schedule extends Model 'only_when_online' => false, ]; - /** - * @var array - */ - public static $validationRules = [ + public static array $validationRules = [ 'server_id' => 'required|exists:servers,id', 'name' => 'required|string|max:191', 'cron_day_of_week' => 'required|string', diff --git a/app/Models/Server.php b/app/Models/Server.php index bd539282a..dca0e20d5 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -107,10 +107,7 @@ class Server extends Model */ protected $guarded = ['id', self::CREATED_AT, self::UPDATED_AT, 'deleted_at']; - /** - * @var array - */ - public static $validationRules = [ + public static array $validationRules = [ 'external_id' => 'sometimes|nullable|string|between:1,191|unique:servers', 'owner_id' => 'required|integer|exists:users,id', 'name' => 'required|string|min:1|max:191', diff --git a/app/Models/ServerTransfer.php b/app/Models/ServerTransfer.php index 7e297b601..0b6a372f4 100644 --- a/app/Models/ServerTransfer.php +++ b/app/Models/ServerTransfer.php @@ -61,7 +61,7 @@ class ServerTransfer extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'server_id' => 'required|numeric|exists:servers,id', 'old_node' => 'required|numeric', 'new_node' => 'required|numeric', diff --git a/app/Models/ServerVariable.php b/app/Models/ServerVariable.php index 9b3ad81fa..b8ebc188e 100644 --- a/app/Models/ServerVariable.php +++ b/app/Models/ServerVariable.php @@ -20,23 +20,18 @@ class ServerVariable extends Model */ public const RESOURCE_NAME = 'server_variable'; - /** @var bool */ - protected $immutableDates = true; - - /** @var string */ protected $table = 'server_variables'; - /** @var string[] */ + protected bool $immutableDates = true; + protected $guarded = ['id', 'created_at', 'updated_at']; - /** @var string[] */ protected $casts = [ 'server_id' => 'integer', 'variable_id' => 'integer', ]; - /** @var string[] */ - public static $validationRules = [ + public static array $validationRules = [ 'server_id' => 'required|int', 'variable_id' => 'required|int', 'variable_value' => 'string', diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 458248628..9f4396bb1 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -24,7 +24,7 @@ class Setting extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'key' => 'required|string|between:1,191', 'value' => 'string', ]; diff --git a/app/Models/Subuser.php b/app/Models/Subuser.php index 8dcdaf37c..f69c4c6dc 100644 --- a/app/Models/Subuser.php +++ b/app/Models/Subuser.php @@ -52,7 +52,7 @@ class Subuser extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'user_id' => 'required|numeric|exists:users,id', 'server_id' => 'required|numeric|exists:servers,id', 'permissions' => 'nullable|array', diff --git a/app/Models/Task.php b/app/Models/Task.php index 82ba72370..348a9098f 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -95,7 +95,7 @@ class Task extends Model /** * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'schedule_id' => 'required|numeric|exists:schedules,id', 'sequence_id' => 'required|numeric|min:1', 'action' => 'required|string', diff --git a/app/Models/User.php b/app/Models/User.php index 1378ee43a..a5c335898 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -138,7 +138,7 @@ class User extends Model implements * * @var array */ - public static $validationRules = [ + public static array $validationRules = [ 'uuid' => 'required|string|size:36|unique:users,uuid', 'email' => 'required|email|between:1,191|unique:users,email', 'external_id' => 'sometimes|nullable|string|max:191|unique:users,external_id', diff --git a/app/Models/UserSSHKey.php b/app/Models/UserSSHKey.php new file mode 100644 index 000000000..147902236 --- /dev/null +++ b/app/Models/UserSSHKey.php @@ -0,0 +1,26 @@ + 'required|string', + 'public_key' => 'required|string', + ]; +}