|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Pterodactyl - Panel |
| 4 | + * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +namespace Pterodactyl\Http\Requests\Admin\Service; |
| 26 | + |
| 27 | +use Pterodactyl\Models\User; |
| 28 | +use Illuminate\Foundation\Http\FormRequest; |
| 29 | + |
| 30 | +class StoreOptionVariable extends FormRequest |
| 31 | +{ |
| 32 | + /** |
| 33 | + * Determine if user is allowed to access this request. |
| 34 | + * |
| 35 | + * @return bool |
| 36 | + */ |
| 37 | + public function authorize() |
| 38 | + { |
| 39 | + if (! $this->user() instanceof User) { |
| 40 | + return false; |
| 41 | + } |
| 42 | + |
| 43 | + return $this->user()->isRootAdmin(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Set the rules to be used for data passed to the request. |
| 48 | + * |
| 49 | + * @return array |
| 50 | + */ |
| 51 | + public function rules() |
| 52 | + { |
| 53 | + return [ |
| 54 | + 'name' => 'required|string|min:1|max:255', |
| 55 | + 'description' => 'nullable|string', |
| 56 | + 'env_variable' => 'required|regex:/^[\w]{1,255}$/', |
| 57 | + 'rules' => 'bail|required|string', |
| 58 | + 'default_value' => explode('|', $this->input('rules')), |
| 59 | + 'options' => 'sometimes|required|array', |
| 60 | + ]; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Return only the fields that we are interested in from the request. |
| 65 | + * This will include empty fields as a null value. |
| 66 | + * |
| 67 | + * @return array |
| 68 | + */ |
| 69 | + public function normalize() |
| 70 | + { |
| 71 | + return $this->only( |
| 72 | + array_keys($this->rules()) |
| 73 | + ); |
| 74 | + } |
| 75 | +} |
0 commit comments