Properly validate schedule names; closes #2405

This commit is contained in:
Dane Everitt 2020-09-24 19:25:34 -07:00
parent 48a104667f
commit 6a4914df3b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Schedules; namespace Pterodactyl\Http\Requests\Api\Client\Servers\Schedules;
use Pterodactyl\Models\Schedule;
use Pterodactyl\Models\Permission; use Pterodactyl\Models\Permission;
class StoreScheduleRequest extends ViewScheduleRequest class StoreScheduleRequest extends ViewScheduleRequest
@ -19,13 +20,15 @@ class StoreScheduleRequest extends ViewScheduleRequest
*/ */
public function rules(): array public function rules(): array
{ {
$rules = Schedule::getRules();
return [ return [
'name' => 'required|string|min:1', 'name' => $rules['name'],
'is_active' => 'filled|boolean', 'is_active' => array_merge(['filled'], $rules['is_active']),
'minute' => 'required|string', 'minute' => $rules['cron_minute'],
'hour' => 'required|string', 'hour' => $rules['cron_hour'],
'day_of_month' => 'required|string', 'day_of_month' => $rules['cron_day_of_month'],
'day_of_week' => 'required|string', 'day_of_week' => $rules['cron_day_of_week'],
]; ];
} }
} }

View File

@ -103,7 +103,7 @@ class Schedule extends Model
*/ */
public static $validationRules = [ public static $validationRules = [
'server_id' => 'required|exists:servers,id', 'server_id' => 'required|exists:servers,id',
'name' => 'nullable|string|max:255', 'name' => 'required|string|max:255',
'cron_day_of_week' => 'required|string', 'cron_day_of_week' => 'required|string',
'cron_day_of_month' => 'required|string', 'cron_day_of_month' => 'required|string',
'cron_hour' => 'required|string', 'cron_hour' => 'required|string',