mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Cleanup slack validation
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
ff97b359ad
commit
86afe6c4b1
|
@ -166,15 +166,8 @@ class SettingsController extends Controller
|
|||
public function slacktest(Request $request)
|
||||
{
|
||||
|
||||
\Log::error(strncmp($request->input('slack_endpoint'), 'https://hooks.slack.com/', 24));
|
||||
\Log::error('Endpoint: '.$request->input('slack_endpoint'));
|
||||
\Log::error('Request: '.print_r($request->all(), true));
|
||||
// \Log::error('Rules: '.print_r(Setting::rules(), true));
|
||||
|
||||
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com|nullable',
|
||||
'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable',
|
||||
'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
|
||||
]);
|
||||
|
||||
|
@ -182,35 +175,7 @@ class SettingsController extends Controller
|
|||
return response()->json(['message' => 'Validation failed', 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
|
||||
// if (($request->filled('slack_endpoint')) && ((strncmp($request->input('slack_endpoint'), "https://hooks.slack.com/", 24) !== 0))) {
|
||||
// return response()->json(['message' => 'Oops! Please check the endpoint URL. Slack endpoints should start with https://hooks.slack.com. Your current endpoint is '.$request->input('slack_endpoint'), ['errors' => 'Invalid slack endpoint.']], 422);
|
||||
|
||||
// }
|
||||
|
||||
// if (($request->filled('slack_channel')) && (strpos($request->input('slack_channel'), '#') !== 0)) {
|
||||
// return response()->json(['message' => 'Oops! Please check the channel name. Slack channels should begin with #.', ['errors' => 'Invalid slack endpoint.']], 422);
|
||||
// }
|
||||
|
||||
|
||||
// if (!$validator = Validator::make($request->all(), [
|
||||
// 'slack_endpoint' => 'url"',
|
||||
// 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
|
||||
// ])) {
|
||||
|
||||
\Log::error('Fails validation with '.$request->input('slack_endpoint'));
|
||||
|
||||
|
||||
// Only attempt the slack request if the validation passes
|
||||
// if (!$request->validate([
|
||||
// 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com|nullable',
|
||||
// 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
|
||||
// ])) {
|
||||
// return response()->json(['message' => $validator->errors()], 422);
|
||||
//} else {
|
||||
|
||||
\Log::error('Passes validation with '.$request->input('slack_endpoint'));
|
||||
|
||||
// If validation passes, continue to the curl request
|
||||
$slack = new Client([
|
||||
'base_url' => e($request->input('slack_endpoint')),
|
||||
'defaults' => [
|
||||
|
|
Loading…
Reference in a new issue