From b1dda88c9dcc0b09f6280f2125bf97f257340568 Mon Sep 17 00:00:00 2001
From: snipe
Date: Tue, 15 Sep 2020 23:05:05 -0700
Subject: [PATCH 1/6] Removed SlackTest notification
---
app/Notifications/SlackTest.php | 51 ---------------------------------
1 file changed, 51 deletions(-)
delete mode 100644 app/Notifications/SlackTest.php
diff --git a/app/Notifications/SlackTest.php b/app/Notifications/SlackTest.php
deleted file mode 100644
index 99d37761b..000000000
--- a/app/Notifications/SlackTest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-from($settings->slack_botname, ':heart:')
- ->to($settings->slack_channel)
- ->image('https://snipeitapp.com/favicon.ico')
- ->content('Oh hai! Looks like your Slack integration with Snipe-IT is working!');
- }
-
-}
From 7736f12eb414d4267c669596b8fb307ca9061cc2 Mon Sep 17 00:00:00 2001
From: snipe
Date: Tue, 15 Sep 2020 23:05:27 -0700
Subject: [PATCH 2/6] Switch to Guzzle for the Slack test
---
.../Controllers/Api/SettingsController.php | 32 +++++++++++++------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php
index 5f5eecbb4..cd7eb2ed7 100644
--- a/app/Http/Controllers/Api/SettingsController.php
+++ b/app/Http/Controllers/Api/SettingsController.php
@@ -6,13 +6,13 @@ use App\Http\Controllers\Controller;
use App\Http\Transformers\LoginAttemptsTransformer;
use App\Models\Setting;
use App\Notifications\MailTest;
-use App\Notifications\SlackTest;
use App\Services\LdapAd;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
+use GuzzleHttp\Client;
class SettingsController extends Controller
{
@@ -91,24 +91,36 @@ class SettingsController extends Controller
return response()->json($message, 200);
}
- public function slacktest()
+ public function slacktest(Request $request)
{
+ \Log::debug($request->input('slack_channel'));
+ \Log::debug($request->input('slack_endpoint'));
+ \Log::debug($request->input('slack_botname'));
- if ($settings = Setting::getSettings()->slack_channel=='') {
- \Log::debug('Slack is not enabled. Cannot test.');
- return response()->json(['message' => 'Slack is not enabled, cannot test.'], 400);
- }
+ $slack = new Client([
+ 'base_url' => $request->input('slack_endpoint'),
+ 'defaults' => [
+ 'exceptions' => false
+ ]
+ ]);
- \Log::debug('Preparing to test slack connection');
+
+ $payload = json_encode(
+ [
+ 'channel' => $request->input('slack_channel'),
+ 'text' => trans('general.slack_test_msg'),
+ 'username' => $request->input('slack_botname'),
+ 'icon_emoji' => ':heart:'
+ ]);
try {
- Notification::send($settings = Setting::getSettings(), new SlackTest());
+ $slack->post($request->input('slack_endpoint'),['body' => $payload]);
return response()->json(['message' => 'Success'], 200);
} catch (\Exception $e) {
- \Log::debug('Slack connection failed');
- return response()->json(['message' => $e->getMessage()], 400);
+ return response()->json(['message' => 'Oops! Please check the channel name and webhook endpoint URL. Slack responded with: '.$e->getMessage()], 400);
}
+ return response()->json(['message' => 'Something went wrong :( '], 400);
}
From 3ceff29e0436c29b46be2ab9a8d70afc881107ff Mon Sep 17 00:00:00 2001
From: snipe
Date: Tue, 15 Sep 2020 23:05:42 -0700
Subject: [PATCH 3/6] Added some translations for Slack integration
---
resources/lang/en/admin/settings/general.php | 2 +-
resources/lang/en/general.php | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php
index 6f97789cd..6de059ba7 100644
--- a/resources/lang/en/admin/settings/general.php
+++ b/resources/lang/en/admin/settings/general.php
@@ -150,7 +150,7 @@ return array(
'slack_channel' => 'Slack Channel',
'slack_endpoint' => 'Slack Endpoint',
'slack_integration' => 'Slack Settings',
- 'slack_integration_help' => 'Slack integration is optional, however the endpoint and channel are required if you wish to use it. To configure Slack integration, you must first create an incoming webhook on your Slack account.',
+ 'slack_integration_help' => 'Slack integration is optional, however the endpoint and channel are required if you wish to use it. To configure Slack integration, you must first create an incoming webhook on your Slack account. Click on the Test Slack Integration button to confirm your settings are correct before saving. ',
'slack_integration_help_button' => 'Once you have saved your Slack information, a test button will appear.',
'slack_test_help' => 'Test whether your Slack integration is configured correctly. YOU MUST SAVE YOUR UPDATED SLACK SETTINGS FIRST.',
'snipe_version' => 'Snipe-IT version',
diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php
index ee7287515..8b60aa7d7 100644
--- a/resources/lang/en/general.php
+++ b/resources/lang/en/general.php
@@ -202,6 +202,7 @@
'sign_in' => 'Sign in',
'signature' => 'Signature',
'skin' => 'Skin',
+ 'slack_test_msg' => 'Oh hai! Looks like your Slack integration with Snipe-IT is working!',
'some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.',
'site_name' => 'Site Name',
'state' => 'State',
From 74b96a74137a97e48070bc4ee2b36d2258c11b4a Mon Sep 17 00:00:00 2001
From: snipe
Date: Tue, 15 Sep 2020 23:14:10 -0700
Subject: [PATCH 4/6] UI tweaks and updated JS to disable the save button if
the settings are not correct
---
resources/views/settings/slack.blade.php | 53 ++++++++++++++----------
1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php
index 6ad51eef5..f0199dcff 100644
--- a/resources/views/settings/slack.blade.php
+++ b/resources/views/settings/slack.blade.php
@@ -47,19 +47,19 @@
-