Jelajahi Sumber

chore: 🦺 Added Validation to settings

IceToast 2 tahun lalu
induk
melakukan
d9d776e5da

+ 17 - 1
app/Settings/DiscordSettings.php

@@ -33,7 +33,23 @@ class DiscordSettings extends Settings
     }
 
     /**
-     * Summary of optionTypes
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'bot_token' => 'nullable|string',
+            'client_id' => 'nullable|string',
+            'client_secret' => 'nullable|string',
+            'guild_id' => 'nullable|string',
+            'invite_url' => 'nullable|string|url',
+            'role_id' => 'nullable|string',
+        ];
+    }
+
+    /**
+     * Summary of optionInputData array
      * Only used for the settings page
      * @return array<array<'type'|'label'|'description'|'options', string|bool|float|int|array<string, string>>>
      */

+ 13 - 4
app/Settings/GeneralSettings.php

@@ -34,16 +34,25 @@ class GeneralSettings extends Settings
         ];
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
     public static function getValidations()
     {
-        // create validation rules that can be used in the controller
         return [
-            'main_site' => 'required|string|max:1',
+            'main_site' => 'nullable|string',
             'credits_display_name' => 'required|string',
             'initial_user_credits' => 'required|numeric',
             'initial_server_limit' => 'required|numeric',
-            'recaptcha_enabled' => 'required|boolean',
-
+            'recaptcha_enabled' => 'nullable|string',
+            'recaptcha_site_key' => 'nullable|string',
+            'recaptcha_secret_key' => 'nullable|string',
+            'phpmyadmin_url' => 'nullable|string',
+            'alert_enabled' => 'nullable|string',
+            'alert_type' => 'nullable|string',
+            'alert_message' => 'nullable|string',
+            'theme' => 'required|string'
         ];
     }
 

+ 20 - 2
app/Settings/InvoiceSettings.php

@@ -27,6 +27,24 @@ class InvoiceSettings extends Settings
         return 'invoice';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'company_address' => 'nullable|string',
+            'company_mail' => 'nullable|string',
+            'company_name' => 'nullable|string',
+            'company_phone' => 'nullable|string',
+            'company_vat' => 'nullable|string',
+            'company_website' => 'nullable|string',
+            'enabled' => 'nullable|string',
+            'prefix' => 'nullable|string',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page
@@ -56,9 +74,9 @@ class InvoiceSettings extends Settings
                 'description' => 'The phone of your company.',
             ],
             'company_vat' => [
-                'label' => 'Company VAT',
+                'label' => 'Company VAT ID',
                 'type' => 'string',
-                'description' => 'The VAT of your company.',
+                'description' => 'The VAT ID of your company.',
             ],
             'company_website' => [
                 'label' => 'Company Website',

+ 15 - 0
app/Settings/LocaleSettings.php

@@ -21,6 +21,21 @@ class LocaleSettings extends Settings
         return 'locale';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'available' => 'nullable|array',
+            'clients_can_change' => 'nullable|string',
+            'datatables' => 'nullable|string',
+            'default' => 'nullable|string',
+            'dynamic' => 'nullable|string',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 19 - 0
app/Settings/MailSettings.php

@@ -50,6 +50,25 @@ class MailSettings extends Settings
         }
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'mail_host' => 'nullable|string',
+            'mail_port' => 'nullable|int',
+            'mail_username' => 'nullable|string',
+            'mail_password' => 'nullable|string',
+            'mail_encryption' => 'nullable|string',
+            'mail_from_address' => 'nullable|string',
+            'mail_from_name' => 'nullable|string',
+            'mail_mailer' => 'nullable|string',
+            'mail_enabled' => 'nullable|boolean',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 14 - 0
app/Settings/PterodactylSettings.php

@@ -37,6 +37,20 @@ class PterodactylSettings extends Settings
         return str_ends_with($this->panel_url, '/') ? $this->panel_url : $this->panel_url . '/';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'panel_url' => 'required|string|url',
+            'admin_token' => 'required|string',
+            'user_token' => 'required|string',
+            'per_page_limit' => 'required|integer|min:1|max:10000',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 16 - 0
app/Settings/ReferralSettings.php

@@ -23,6 +23,22 @@ class ReferralSettings extends Settings
         return 'referral';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'allowed' => 'nullable|string',
+            'always_give_commission' => 'nullable|boolean',
+            'enabled' => 'nullable|boolean',
+            'reward' => 'nullable|numeric',
+            'mode' => 'nullable|string',
+            'percentage' => 'nullable|numeric',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 14 - 0
app/Settings/ServerSettings.php

@@ -19,6 +19,20 @@ class ServerSettings extends Settings
         return 'server';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'allocation_limit' => 'required|integer|min:0',
+            'creation_enabled' => 'nullable|string',
+            'enable_upgrade' => 'nullable|string',
+            'charge_first_hour' => 'nullable|string',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 12 - 0
app/Settings/TicketSettings.php

@@ -15,6 +15,18 @@ class TicketSettings extends Settings
         return 'ticket';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'enabled' => 'nullable|string',
+            'notify' => 'nullable|string',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 22 - 0
app/Settings/UserSettings.php

@@ -35,6 +35,28 @@ class UserSettings extends Settings
         return 'user';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        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',
+            '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',
+        ];
+    }
+
     /**
      * Summary of optionTypes
      * Only used for the settings page

+ 19 - 0
app/Settings/WebsiteSettings.php

@@ -28,6 +28,25 @@ class WebsiteSettings extends Settings
         return 'website';
     }
 
+    /**
+     * Summary of validations array
+     * @return array<string, string>
+     */
+    public static function getValidations()
+    {
+        return [
+            'motd_enabled' => 'nullable|string',
+            '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',
+            'seo_title' => 'nullable|string',
+            'seo_description' => 'nullable|string',
+        ];
+    }
+
 
     /**
      * Summary of optionTypes