(Refactor) Validation and variable modification to align with the input data

This commit is contained in:
Jens 2023-03-30 16:21:31 +02:00 committed by IceToast
parent f63d8080a3
commit f7ab52fec1
10 changed files with 84 additions and 64 deletions

View file

@ -6,13 +6,13 @@ use Spatie\LaravelSettings\Settings;
class GeneralSettings extends Settings
{
public bool $store_enabled = true;
public bool $store_enabled = false;
public string $credits_display_name;
public bool $recaptcha_enabled;
public string $recaptcha_site_key;
public string $recaptcha_secret_key;
public string $phpmyadmin_url;
public bool $alert_enabled;
public bool $alert_enabled = false;
public string $alert_type;
public string $alert_message;
public string $theme;
@ -32,6 +32,26 @@ class GeneralSettings extends Settings
];
}
/**
* Summary of validations array
* @return array<string, string>
*/
public static function getValidations()
{
return [
'store_enabled' => 'boolean',
'credits_display_name' => 'required|string',
'recaptcha_enabled' => 'nullable|boolean',
'recaptcha_site_key' => 'nullable|string',
'recaptcha_secret_key' => 'nullable|string',
'phpmyadmin_url' => 'nullable|string',
'alert_enabled' => 'nullable|boolean',
'alert_type' => 'required|in:primary,secondary,success,danger,warning,info',
'alert_message' => 'required|string',
'theme' => 'required|in:default,BlueInfinity' // TODO: themes should be made/loaded dynamically
];
}
/**
* Summary of optionTypes
* Only used for the settings page
@ -110,7 +130,7 @@ class GeneralSettings extends Settings
'options' => [
'default' => 'Default',
'BlueInfinity' => 'Blue Infinity',
],
], // TODO: themes should be made/loaded dynamically
'description' => 'The theme to use for the site.'
],
];

View file

@ -6,21 +6,21 @@ use Spatie\LaravelSettings\Settings;
class InvoiceSettings extends Settings
{
public string $company_address;
public ?string $company_address;
public string $company_mail;
public ?string $company_mail;
public string $company_name;
public ?string $company_name;
public string $company_phone;
public ?string $company_phone;
public string $company_vat;
public ?string $company_vat;
public string $company_website;
public ?string $company_website;
public bool $enabled;
public bool $enabled = false;
public string $prefix;
public ?string $prefix;
public static function group(): string
{
@ -40,7 +40,7 @@ class InvoiceSettings extends Settings
'company_phone' => 'nullable|string',
'company_vat' => 'nullable|string',
'company_website' => 'nullable|string',
'enabled' => 'nullable|string',
'enabled' => 'nullable|boolean',
'prefix' => 'nullable|string',
];
}

View file

@ -6,15 +6,15 @@ use Spatie\LaravelSettings\Settings;
class LocaleSettings extends Settings
{
public string $available;
public ?string $available;
public bool $clients_can_change;
public bool $clients_can_change = false;
public string $datatables;
public ?string $datatables;
public string $default;
public bool $dynamic;
public bool $dynamic = false;
public static function group(): string
{
@ -29,10 +29,10 @@ class LocaleSettings extends Settings
{
return [
'available' => 'nullable|array',
'clients_can_change' => 'nullable|string',
'clients_can_change' => 'nullable|boolean',
'datatables' => 'nullable|string',
'default' => 'nullable|string',
'dynamic' => 'nullable|string',
'default' => 'required|in:' . implode(',', config('app.available_locales')),
'dynamic' => 'nullable|boolean',
];
}

View file

@ -22,7 +22,7 @@ class MailSettings extends Settings
public ?string $mail_mailer;
public ?bool $mail_enabled;
public bool $mail_enabled = false;
public static function group(): string
{

View file

@ -6,11 +6,11 @@ use Spatie\LaravelSettings\Settings;
class PterodactylSettings extends Settings
{
public ?string $admin_token;
public string $admin_token;
public ?string $user_token;
public string $user_token;
public ?string $panel_url;
public string $panel_url;
public int $per_page_limit;
@ -44,9 +44,9 @@ class PterodactylSettings extends Settings
public static function getValidations()
{
return [
'panel_url' => 'nullable|string|url',
'admin_token' => 'nullable|string',
'user_token' => 'nullable|string',
'panel_url' => 'required|string|url',
'admin_token' => 'required|string',
'user_token' => 'required|string',
'per_page_limit' => 'required|integer|min:1|max:10000',
];
}

View file

@ -8,15 +8,15 @@ class ReferralSettings extends Settings
{
public string $allowed;
public bool $always_give_commission;
public bool $always_give_commission = false;
public bool $enabled;
public bool $enabled = false;
public float $reward;
public ?float $reward;
public string $mode;
public int $percentage;
public ?int $percentage;
public static function group(): string
{
@ -30,11 +30,11 @@ class ReferralSettings extends Settings
public static function getValidations()
{
return [
'allowed' => 'nullable|string',
'allowed' => 'required|in:everyone,clients',
'always_give_commission' => 'nullable|boolean',
'enabled' => 'nullable|boolean',
'reward' => 'nullable|numeric',
'mode' => 'nullable|string',
'mode' => 'required|in:commission,percentage,both',
'percentage' => 'nullable|numeric',
];
}
@ -77,7 +77,7 @@ class ReferralSettings extends Settings
'type' => 'select',
'description' => 'Referral mode.',
'options' => [
'comission' => 'Comission',
'commission' => 'Commission',
'sign-up' => 'Sign-Up',
'both' => 'Both',
],

View file

@ -8,11 +8,11 @@ class ServerSettings extends Settings
{
public int $allocation_limit;
public bool $creation_enabled;
public bool $creation_enabled = false;
public bool $enable_upgrade;
public bool $enable_upgrade = false;
public bool $charge_first_hour;
public bool $charge_first_hour = false;
public static function group(): string
{
@ -27,9 +27,9 @@ class ServerSettings extends Settings
{
return [
'allocation_limit' => 'required|integer|min:0',
'creation_enabled' => 'nullable|string',
'enable_upgrade' => 'nullable|string',
'charge_first_hour' => 'nullable|string',
'creation_enabled' => 'nullable|boolean',
'enable_upgrade' => 'nullable|boolean',
'charge_first_hour' => 'nullable|boolean',
];
}

View file

@ -6,7 +6,7 @@ use Spatie\LaravelSettings\Settings;
class TicketSettings extends Settings
{
public bool $enabled;
public bool $enabled = false;
public string $notify;
@ -22,7 +22,7 @@ class TicketSettings extends Settings
public static function getValidations()
{
return [
'enabled' => 'nullable|string',
'enabled' => 'nullable|boolean',
'notify' => 'nullable|string',
];
}

View file

@ -10,9 +10,9 @@ class UserSettings extends Settings
public float $credits_reward_after_verify_email;
public bool $force_discord_verification;
public bool $force_discord_verification = false;
public bool $force_email_verification;
public bool $force_email_verification = false;
public float $initial_credits;
@ -26,9 +26,9 @@ class UserSettings extends Settings
public int $server_limit_after_verify_email;
public bool $register_ip_check;
public bool $register_ip_check = false;
public bool $creation_enabled;
public bool $creation_enabled = false;
public static function group(): string
{
@ -44,16 +44,16 @@ class UserSettings extends Settings
return [
'credits_reward_after_verify_discord' => 'required|numeric',
'credits_reward_after_verify_email' => 'required|numeric',
'force_discord_verification' => 'nullable|string',
'force_email_verification' => 'nullable|string',
'force_discord_verification' => 'nullable|boolean',
'force_email_verification' => 'nullable|boolean',
'initial_credits' => 'required|numeric',
'initial_server_limit' => 'required|numeric',
'min_credits_to_make_server' => 'required|numeric',
'server_limit_after_irl_purchase' => 'required|numeric',
'server_limit_after_verify_discord' => 'required|numeric',
'server_limit_after_verify_email' => 'required|numeric',
'register_ip_check' => 'nullable|string',
'creation_enabled' => 'nullable|string',
'register_ip_check' => 'nullable|boolean',
'creation_enabled' => 'nullable|boolean',
];
}

View file

@ -8,20 +8,20 @@ class WebsiteSettings extends Settings
{
public bool $show_imprint;
public bool $show_imprint = false;
public bool $show_privacy;
public bool $show_privacy = false;
public bool $show_tos;
public bool $show_tos = false;
public bool $useful_links_enabled;
public bool $enable_login_logo;
public string $seo_title;
public bool $useful_links_enabled = false;
public bool $enable_login_logo = false;
public ?string $seo_title;
public string $seo_description;
public bool $motd_enabled;
public ?string $seo_description;
public bool $motd_enabled = false;
public string $motd_message;
public ?string $motd_message;
public static function group(): string
{
@ -35,13 +35,13 @@ class WebsiteSettings extends Settings
public static function getValidations()
{
return [
'motd_enabled' => 'nullable|string',
'motd_enabled' => 'nullable|boolean',
'motd_message' => 'nullable|string',
'show_imprint' => 'nullable|string',
'show_privacy' => 'nullable|string',
'show_tos' => 'nullable|string',
'useful_links_enabled' => 'nullable|string',
'enable_login_logo' => 'nullable|string',
'show_imprint' => 'nullable|boolean',
'show_privacy' => 'nullable|boolean',
'show_tos' => 'nullable|boolean',
'useful_links_enabled' => 'nullable|boolean',
'enable_login_logo' => 'nullable|boolean',
'seo_title' => 'nullable|string',
'seo_description' => 'nullable|string',
];