mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Removed form request on ajax, cleaned up some other things
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
81b66d0039
commit
ff97b359ad
|
@ -163,16 +163,26 @@ class SettingsController extends Controller
|
|||
|
||||
}
|
||||
|
||||
public function slacktest(SlackSettingsRequest $request)
|
||||
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));
|
||||
// \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_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
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);
|
||||
|
||||
|
@ -221,7 +231,7 @@ class SettingsController extends Controller
|
|||
return response()->json(['message' => 'Success'], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['message' => 'Oops! Please check the channel name and webhook endpoint URL. Slack responded with: '.$e->getMessage()], 400);
|
||||
return response()->json(['message' => 'FARTS! Please check the channel name and webhook endpoint URL ('.$request->input('slack_endpoint').'). Slack responded with: '.$e->getMessage()], 400);
|
||||
}
|
||||
|
||||
//}
|
||||
|
|
|
@ -22,15 +22,12 @@ class SlackSettingsRequest extends Request
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
'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',
|
||||
'slack_botname' => 'string|nullable',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function response(array $errors)
|
||||
{
|
||||
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,10 +52,7 @@ class Setting extends Model
|
|||
'admin_cc_email' => 'email|nullable',
|
||||
'default_currency' => 'required',
|
||||
'locale' => 'required',
|
||||
'slack_endpoint' => 'url|required_with:slack_channel|nullable',
|
||||
'labels_per_page' => 'numeric',
|
||||
'slack_channel' => 'regex:/^[\#\@]?\w+/|required_with:slack_endpoint|nullable',
|
||||
'slack_botname' => 'string|nullable',
|
||||
'labels_width' => 'numeric',
|
||||
'labels_height' => 'numeric',
|
||||
'labels_pmargin_left' => 'numeric|nullable',
|
||||
|
|
|
@ -64,6 +64,7 @@ return array(
|
|||
'string' => 'The :attribute must be at least :min characters.',
|
||||
'array' => 'The :attribute must have at least :min items.',
|
||||
],
|
||||
'starts_with' => 'The :attribute must start with one of the following: :values.',
|
||||
'not_in' => 'The selected :attribute is invalid.',
|
||||
'numeric' => 'The :attribute must be a number.',
|
||||
'present' => 'The :attribute field must be present.',
|
||||
|
|
|
@ -165,14 +165,23 @@
|
|||
$("#slackteststatus").removeClass('text-danger');
|
||||
$("#slackteststatus").html('');
|
||||
$("#slacktesticon").html('<i class="fa fa-spinner spin"></i> Sending Slack test message...');
|
||||
$.ajax({
|
||||
$.ajax(
|
||||
{
|
||||
// If I comment this back in, I always get a success (200) message
|
||||
// Without it, I get
|
||||
// beforeSend: function (xhr) {
|
||||
// xhr.setRequestHeader("Content-Type","application/json");
|
||||
// xhr.setRequestHeader("Accept","text/json");
|
||||
// },
|
||||
|
||||
|
||||
url: '{{ route('api.settings.slacktest') }}',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content'),
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
// 'Accept': 'application/json',
|
||||
// 'Content-Type': 'application/json',
|
||||
},
|
||||
data: {
|
||||
'slack_endpoint': $('#slack_endpoint').val(),
|
||||
|
|
Loading…
Reference in a new issue