Pulled slack validation out of setting model validation so it doesn’t fail mysteriously on other pages

This commit is contained in:
snipe 2020-04-08 15:07:02 -07:00
parent 92695782ff
commit 206bd675f2
No known key found for this signature in database
GPG key ID: 10BFFDA3ED34B5AC
2 changed files with 14 additions and 7 deletions

View file

@ -645,14 +645,24 @@ class SettingsController extends Controller
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
} }
$validatedData = $request->validate([
'slack_endpoint' => 'url|required_with:slack_channel|nullable',
'slack_channel' => 'regex:/(?<!\w)#\w+/|required_with:slack_endpoint|nullable',
'slack_botname' => 'string|nullable',
]);
if ($validatedData) {
$setting->slack_endpoint = $request->input('slack_endpoint'); $setting->slack_endpoint = $request->input('slack_endpoint');
$setting->slack_channel = $request->input('slack_channel'); $setting->slack_channel = $request->input('slack_channel');
$setting->slack_botname = $request->input('slack_botname'); $setting->slack_botname = $request->input('slack_botname');
if ($setting->save()) { $setting->save();
return redirect()->route('settings.index') return redirect()->route('settings.index')
->with('success', trans('admin/settings/message.update.success')); ->with('success', trans('admin/settings/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($setting->getErrors()); return redirect()->back()->withInput()->withErrors($setting->getErrors());
} }

View file

@ -20,9 +20,6 @@ class Setting extends Model
'admin_cc_email' => 'email|nullable', 'admin_cc_email' => 'email|nullable',
'default_currency' => 'required', 'default_currency' => 'required',
'locale' => 'required', 'locale' => 'required',
'slack_endpoint' => 'url|required_with:slack_channel|nullable',
'slack_channel' => 'regex:/(?<!\w)#\w+/|required_with:slack_endpoint|nullable',
'slack_botname' => 'string|nullable',
'labels_per_page' => 'numeric|min:1', 'labels_per_page' => 'numeric|min:1',
'labels_width' => 'numeric', 'labels_width' => 'numeric',
'labels_height' => 'numeric', 'labels_height' => 'numeric',