Dont let users increase pkt_msgs above 100

This commit is contained in:
Deon George 2024-10-16 08:19:36 +11:00
parent 32d31cea90
commit 38fd1539a6

View File

@ -23,7 +23,12 @@ class SystemRegisterRequest extends FormRequest
// @todo Also disallow claiming this hosts system
return Gate::allows($this->route('o')->users->count() ? 'update_nn' : 'register',$this->route('o'));
return Gate::allows(
$this->route('o')->users->count()
? 'update_nn'
: 'register',
$this->route('o')
);
}
public function messages(): array
@ -31,6 +36,7 @@ class SystemRegisterRequest extends FormRequest
return [
'hold' => 'Must be Yes or No',
'pollmode' => 'Must be Hold, Normal or Crash',
'pkt_msgs' => 'Sorry, only an admin can increase this above 100',
];
}
@ -39,7 +45,7 @@ class SystemRegisterRequest extends FormRequest
*
* If the system exists (POST & action="register" & system_id=<value>), then no validation required
* If the system doesnt exist (POST & action="register" & system_id undefined) then we need just a name to start the process (action="create")
* Then, full validation
* Then, full validation
* @return array
*/
public function rules(Request $request)
@ -70,7 +76,16 @@ class SystemRegisterRequest extends FormRequest
'hold' => 'sometimes|boolean',
'pollmode' => 'required|integer|min:0|max:2',
'heartbeat' => 'nullable|integer|min:0|max:48',
'pkt_msgs' => 'nullable|integer|min:5',
'pkt_msgs' => [
'nullable',
function ($attribute,$value,$fail) {
if (($value > 100) && (! Gate::allows('admin')))
$fail(true);
},
'integer',
'min:5',
'max:65535',
],
] : []));
}
}