A free open source IT asset/license management system
adds generalized webhooks, updates settings page, translations, validation
Godfrey M35dd0d8def04
diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.phpindex ac94743383..0794aedd40 100644--- a/app/Http/Livewire/SlackSettingsForm.php+++ b/app/Http/Livewire/SlackSettingsForm.php@@ -12,6 +12,7 @@ class SlackSettingsForm extends Componentpublic $webhook_channel;public $webhook_botname;public $isDisabled ='disabled' ;+ public $webhook_name;public $webhook_link;public $webhook_placeholder;public $webhook_icon;@@ -20,31 +21,38 @@ class SlackSettingsForm extends Componentpublic Setting $setting;protected $rules = [- 'webhook_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable',- 'webhook_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',+ 'webhook_endpoint' => 'url|required_with:webhook_channel|starts_with:https://hooks.slack.com/services,https://discord.com/api/webhooks|nullable',+ 'webhook_channel' => 'required_with:webhook_endpoint|starts_with:#|nullable','webhook_botname' => 'string|nullable',];static $webhook_text= ["Slack" => array(+ "name" => "Slack","icon" => 'fab fa-slack',"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",- "link" => 'https://api.slack.com/messaging/webhooks'+ "link" => 'https://api.slack.com/messaging/webhooks',),"Discord" => array(+ "name" => "Discord","icon" => 'fab fa-discord',"placeholder" => "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXX",- "link" => 'https://support.discord.com/hc/en-us/articles/360045093012-Server-Integrations-Page'+ "link" => 'https://support.discord.com/hc/en-us/articles/360045093012-Server-Integrations-Page',),- "RocketChat"=> array(- "icon" => 'fab fa-rocketchat',- "placeholder" => "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXX",- "link" => '',+ "General"=> array(+ "name" => "General",+ "icon" => "fab fa-hashtag",+ "placeholder" => "",+ "link" => "",),];public function mount(){$this->setting = Setting::getSettings();+ $this->webhook_selected = $this->setting->webhook_selected;+ $this->webhook_placeholder = self::$webhook_text[$this->setting->webhook_selected]["placeholder"];+ $this->webhook_name = self::$webhook_text[$this->setting->webhook_selected]["name"];+ $this->webhook_icon = self::$webhook_text[$this->setting->webhook_selected]["icon"];$this->webhook_endpoint = $this->setting->webhook_endpoint;$this->webhook_channel = $this->setting->webhook_channel;$this->webhook_botname = $this->setting->webhook_botname;@@ -53,11 +61,12 @@ class SlackSettingsForm extends Component}public function updated($field){-// $this->webhook_selected = $this->webhook_options;- $this->validateOnly($field ,$this->rules);+ if($this->webhook_selected != 'General') {+ $this->validateOnly($field, $this->rules);+ }}public function updatedWebhookSelected(){-+ $this->webhook_name = self::$webhook_text[$this->webhook_selected]['name'];$this->webhook_icon = self::$webhook_text[$this->webhook_selected]["icon"]; ;$this->webhook_placeholder = self::$webhook_text[$this->webhook_selected]["placeholder"];$this->webhook_link = self::$webhook_text[$this->webhook_selected]["link"];@@ -77,7 +86,7 @@ class SlackSettingsForm extends Componentpublic function testWebhook(){- $slack = new Client([+ $webhook = new Client(['base_url' => e($this->webhook_endpoint),'defaults' => ['exceptions' => false,@@ -87,36 +96,39 @@ class SlackSettingsForm extends Component$payload = json_encode(['channel' => e($this->webhook_channel),- 'text' => trans('general.slack_test_msg'),+ 'text' => trans('general.webhook_test_msg'),'username' => e($this->webhook_botname),'icon_emoji' => ':heart:',]);try {- $slack->post($this->webhook_endpoint, ['body' => $payload]);+ $webhook->post($this->webhook_endpoint, ['body' => $payload]);$this->isDisabled='';- return session()->flash('success' , 'Your Slack Integration works!');+ return session()->flash('success' , 'Your'.$this->webhook_name.' Integration works!');} catch (\Exception $e) {$this->isDisabled= 'disabled';- return session()->flash('error' , trans('admin/settings/message.slack.error', ['error_message' => $e->getMessage()]));+ return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage()]));}//}- return session()->flash('message' , trans('admin/settings/message.slack.error_misc'));+ return session()->flash('message' , trans('admin/settings/message.webhook.error_misc'));}public function submit(){- $this->validate($this->rules);+ if($this->webhook_selected != 'General') {+ $this->validate($this->rules);+ }- $this->setting->webhook_selected = $this->webhwebhook_selected;+ $this->setting->webhook_selected = $this->webhook_selected;$this->setting->webhook_endpoint = $this->webhook_endpoint;$this->setting->webhook_channel = $this->webhook_channel;$this->setting->webhook_botname = $this->webhook_botname;+$this->setting->save();session()->flash('save',trans('admin/settings/message.update.success'));diff --git a/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php b/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.phpindex 8f59288226..02d7f5e4e9 100644--- a/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php+++ b/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php@@ -14,7 +14,7 @@ class AddsWebhookOptionToSettingsTable extends Migrationpublic function up(){Schema::table('settings', function (Blueprint $table) {- $table->string('webhook_selected')->after('slack_botname')->nullable();+ $table->string('webhook_selected')->after('slack_botname')->default('Slack');nullable();$table->renameColumn('slack_botname', 'webhook_botname');$table->renameColumn('slack_endpoint', 'webhook_endpoint');$table->renameColumn('slack_channel', 'webhook_channel');diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.phpindex 81d40792ac..401efd910c 100644--- a/resources/lang/en/admin/settings/general.php+++ b/resources/lang/en/admin/settings/general.php@@ -198,13 +198,15 @@ return ['show_images_in_email' => 'Show images in emails','show_images_in_email_help' => 'Uncheck this box if your Snipe-IT installation is behind a VPN or closed network and users outside the network will not be able to load images served from this installation in their emails.','site_name' => 'Site Name',- 'webhook' => ':app',- 'webhook_title' => 'Update :app Settings',- 'webhook_help' => ':app settings',+ 'integrations' => 'Integrations',+ 'webhook' => ':app',+ 'webhook_title' => 'Update Webhook Settings',+ 'webhook_help' => 'Integration settings','webhook_botname' => ':app Botname','webhook_channel' => ':app Channel','webhook_endpoint' => ':app Endpoint','webhook_integration' => ':app Settings',+ 'webhook_test' =>':app test integration','webhook_integration_help' => ':app integration is optional, however the endpoint and channel are required if you wish to use it. To configure :app integration, you must first <a href=":webhook_link" target="_new" rel="noopener">create an incoming webhook</a> on your :app account. Click on the <strong>Test :app Integration</strong> button to confirm your settings are correct before saving. ','webhook_integration_help_button' => 'Once you have saved your :app information, a test button will appear.','webhook_test_help' => 'Test whether your :app integration is configured correctly. YOU MUST SAVE YOUR UPDATED :app SETTINGS FIRST.',diff --git a/resources/lang/en/admin/settings/message.php b/resources/lang/en/admin/settings/message.phpindex b0648d1c1c..a4aba73ff7 100644--- a/resources/lang/en/admin/settings/message.php+++ b/resources/lang/en/admin/settings/message.php@@ -33,7 +33,7 @@ return ['testing_authentication' => 'Testing LDAP Authentication...','authentication_success' => 'User authenticated against LDAP successfully!'],- 'slack' => [+ 'webhook' => ['sending' => 'Sending Slack test message...','success_pt1' => 'Success! Check the ','success_pt2' => ' channel for your test message, and be sure to click SAVE below to store your settings.',diff --git a/resources/lang/en/general.php b/resources/lang/en/general.phpindex cc7ee7fa1c..fae0e9a585 100644--- a/resources/lang/en/general.php+++ b/resources/lang/en/general.php@@ -249,8 +249,8 @@ return ['signature' => 'Signature','signed_off_by' => 'Signed Off By','skin' => 'Skin',- 'slack_msg_note' => 'A slack message will be sent',- 'slack_test_msg' => 'Oh hai! Looks like your Slack integration with Snipe-IT is working!',+ 'webhook_msg_note' => 'A :app message will be sent',+ 'webhook_test_msg' => 'Oh hai! Looks like your :app integration with Snipe-IT is working!','some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.','site_name' => 'Site Name','state' => 'State',diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.phpindex c435ae0c4a..ea8262e1c5 100644--- a/resources/views/livewire/slack-settings-form.blade.php+++ b/resources/views/livewire/slack-settings-form.blade.php@@ -1,4 +1,34 @@++ {{-- Page title --}}+ @section('title')+ {{ trans('admin/settings/general.webhook_title') }}+ @parent+ @stop++ @section('header_right')+ <a href="{{ route('settings.index') }}" class="btn btn-primary"> {{ trans('general.back') }}</a>+ @stop+++ {{-- Page content --}}+ @section('content')+<div>+ <div class="row">+ <div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">+ <div class="panel box box-default">+ <div class="box-header with-border">+ <h2 class="box-title">+ <i class="{{$webhook_icon}}"></i> {{ trans('admin/settings/general.webhook', ['app'=>$webhook_name] ) }}+ </h2>+ </div>+ <div class="box-body">+ <div class="col-md-12">+ <p>+ {!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_name)) !!}+ </p>+ <br>+ </div><div class="col-md-12" style="border-top: 0px;">@if (session()->has('save'))@@ -32,10 +62,9 @@aria-label="webhook_selected"class="form-control ">- <option>{{ trans('admin/settings/general.no_default_group') }}</option><option value="Slack">Slack</option><option value="Discord">Discord</option>- <option value="RocketChat">RocketChat</option>+ <option value="General">General Webhook</option></select></div><br><br><br>@@ -106,15 +135,17 @@</div><!--Webhook Integration Test-->- @if($webhook_endpoint != null && $webhook_channel != null)- <div class="form-group">- <div class="col-md-offset-2 col-md-8">- <a href="#" wire:click.prevent="testWebhook"- class="btn btn-default btn-sm pull-left"><span>{!! trans('admin/settings/general.webhook_test',['app' => $webhook_selected ]) !!}</span></a>- <div wire:loading><span style="padding-left: 5px; font-size: 20px"><i- class="fas fa-spinner fa-spin"></i></span></div>+ @if($webhook_selected == 'Slack' || $webhook_selected == 'Discord')+ @if($webhook_endpoint != null && $webhook_channel != null)+ <div class="form-group">+ <div class="col-md-offset-2 col-md-8">+ <a href="#" wire:click.prevent="testWebhook"+ class="btn btn-default btn-sm pull-left"><span><i class="{{$webhook_icon}}"></i> {!! trans('admin/settings/general.webhook_test',['app' => $webhook_selected ]) !!}</span></a>+ <div wire:loading><span style="padding-left: 5px; font-size: 20px"><i+ class="fas fa-spinner fa-spin"></i></span></div>+ </div></div>- </div>+ @endif@endif<div class="box-footer" style="margin-top: 45px;">diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.phpindex f425dabd4e..5b49e1c7e4 100755--- a/resources/views/settings/index.blade.php+++ b/resources/views/settings/index.blade.php@@ -164,12 +164,12 @@<div class="box-body text-center"><h5><a href="{{ route('settings.slack.index') }}" class="settings_button">- <i class="fab fa-slack fa-4x" aria-hidden="true"></i>+ <i class="fa-regular fa-hashtag fa-4x" aria-hidden="true"></i><br><br>- <span class="name">{{ trans('admin/settings/general.slack') }}</span>+ <span class="name">{{ trans('admin/settings/general.integrations') }}</span></a></h5>- <p class="help-block">{{ trans('admin/settings/general.slack_help') }}</p>+ <p class="help-block">{{ trans('admin/settings/general.webhook_help') }}</p></div></div></div>diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.phpindex a5cbd8d0b3..a0e7eba690 100644--- a/resources/views/settings/slack.blade.php+++ b/resources/views/settings/slack.blade.php@@ -1,39 +1,7 @@@extends('layouts/default')-{{-- Page title --}}-@section('title')- {{ trans('admin/settings/general.slack_title') }}- @parent-@stop--@section('header_right')- <a href="{{ route('settings.index') }}" class="btn btn-primary"> {{ trans('general.back') }}</a>-@stop---{{-- Page content --}}-@section('content')--- <div class="row">- <div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">-- <div class="panel box box-default">- <div class="box-header with-border">- <h2 class="box-title">- <i class="fab fa-slack"></i> {{ trans('admin/settings/general.slack') }}- </h2>- </div>- <div class="box-body">- <div class="col-md-12">- <p>- {!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!}- </p>- <br>- </div>@livewire('slack-settings-form')-</div> <!-- /.col-md-8--></div> <!-- /.row-->