A free open source IT asset/license management system
fixes messages for integration test, removes slack request file, rehouses ajax method
Godfrey M3a86547ef558
diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.phpindex 26d380353f..d0f7fea602 100644--- a/app/Http/Controllers/Api/SettingsController.php+++ b/app/Http/Controllers/Api/SettingsController.php@@ -143,37 +143,6 @@ class SettingsController extends Controller}- public function slacktest($slack_endpoint,$slack_channel,$slack_botname)- {- // If validation passes, continue to the curl request- $slack = new Client([- 'base_url' => e($slack_endpoint),- 'defaults' => [- 'exceptions' => false,- ],- ]);-- $payload = json_encode(- [- 'channel' => e($slack_channel),- 'text' => trans('general.slack_test_msg'),- 'username' => e($slack_botname),- 'icon_emoji' => ':heart:',- ]);-- try {- $slack->post($slack_endpoint, ['body' => $payload]);- return response()->json(['message' => 'Success'], 200);-- } catch (\Exception $e) {- return response()->json(['message' => 'Please check the channel name and webhook endpoint URL ('.e($slack_endpoint).'). Slack responded with: '.$e->getMessage()], 400);- }-- //}- return response()->json(['message' => 'Something went wrong :( '], 400);- }--/*** Test the email configuration*diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.phpindex fbc54a0517..9e83087112 100644--- a/app/Http/Livewire/SlackSettingsForm.php+++ b/app/Http/Livewire/SlackSettingsForm.php@@ -2,9 +2,9 @@namespace App\Http\Livewire;+use GuzzleHttp\Client;use Livewire\Component;use App\Models\Setting;-use App\Http\Controllers\Api\SettingsController;class SlackSettingsForm extends Component{@@ -28,8 +28,35 @@ class SlackSettingsForm extends Componentreturn view('livewire.slack-settings-form');}- public function testSlack($slack_endpoint, $slack_channel, $slack_botname){- SettingsController::testSlack($slack_endpoint,$slack_channel,$slack_botname);+ public function testSlack(){++ // If validation passes, continue to the curl request+ $slack = new Client([+ 'base_url' => e($this->slack_endpoint),+ 'defaults' => [+ 'exceptions' => false,+ ],+ ]);++ $payload = json_encode(+ [+ 'channel' => e($this->slack_channel),+ 'text' => trans('general.slack_test_msg'),+ 'username' => e($this->slack_botname),+ 'icon_emoji' => ':heart:',+ ]);++ try {+ $slack->post($this->slack_endpoint, ['body' => $payload]);+ return session()->flash('success' , 'Your Slack Integration works!');++ } catch (\Exception $e) {+ return session()->flash('error' , 'Please check the channel name and webhook endpoint URL ('.e($this->slack_endpoint).'). Slack responded with: '.$e->getMessage());+ }++ //}+ return session()->flash('message' , 'Something went wrong :( ');+}@@ -47,7 +74,7 @@ class SlackSettingsForm extends Component$this->setting->save();- session()->flash('message',trans('admin/settings/message.update.success'));+ session()->flash('save',trans('admin/settings/message.update.success'));}diff --git a/app/Http/Requests/SlackSettingsRequest.php b/app/Http/Requests/SlackSettingsRequest.phpdeleted file mode 100644index e8f7d2f0ea..0000000000--- a/app/Http/Requests/SlackSettingsRequest.php+++ /dev/null@@ -1,32 +0,0 @@-<?php--namespace App\Http\Requests;--class SlackSettingsRequest extends Request-{- /**- * Determine if the user is authorized to make this request.- *- * @return bool- */- public function authorize()- {- return true;- }-- /**- * Get the validation rules that apply to the request.- *- * @return array- */- public function rules()- {- return [- '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',- ];- }---}diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.phpindex 6562f41b33..0335b6d0cc 100644--- a/resources/views/livewire/slack-settings-form.blade.php+++ b/resources/views/livewire/slack-settings-form.blade.php@@ -1,11 +1,26 @@<div class="col-md-12" style="border-top: 0px;">- @if (session()->has('message'))+ @if (session()->has('save'))<div class="alert alert-success">- {{session('message')}}+ {{session('save')}}</div>@endif+ @if(session()->has('success'))+ <div class="alert alert-success">+ {{session('success')}}+ </div>+ @endif+ @if(session()->has('error'))+ <div class="alert alert-danger">+ {{session('error')}}+ </div>+ @endif+ @if(session()->has('message'))+ <div class="alert alert-danger">+ {{session('message')}}+ </div>+ @endif<form wire:submit.prevent ="submit">{{csrf_field()}}@@ -34,11 +49,11 @@</div><div class="col-md-10">@if (config('app.lock_passwords')===true)- <input type="text" wire:model.lazy="slack_channel" id="slack_channel" class= 'form-control' placeholder="'#IT-Ops'" {{old('slack_channel', $slack_channel)}} ><br>+ <input type="text" wire:model.lazy="slack_channel" id="slack_channel" class='form-control' placeholder="#IT-Ops" value="{{old('slack_channel', $slack_channel)}}" ><br><p class="text-warning"><i class="fas fa-lock"></i> {{ trans('general.feature_disabled') }}</p>@else- <input type="text" wire:model.lazy="slack_channel" id="slack_channel" class= 'form-control' placeholder="'#IT-Ops'" {{old('slack_channel', $slack_channel)}} ><br>+ <input type="text" wire:model.lazy="slack_channel" id="slack_channel" class= 'form-control' placeholder="#IT-Ops" value="{{old('slack_channel', $slack_channel)}}" ><br>@endif{!! $errors->first('slack_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}</div>@@ -64,33 +79,21 @@<!--Slack Integration Test-->@if($slack_endpoint != null && $slack_channel != null && $slack_botname != null)-<div class="form-group">+ <div class="form-group"><div class="col-md-2">{{ Form::label('test_slack', 'Test Slack') }}</div><div class="col-md-10">- <button wire:submit.prevent="testSlack({{$slack_channel,$slack_endpoint,$slack_botname}})" id="test_slack" class="btn btn-default btn-sm pull-left"><span>{!! trans('admin/settings/general.slack_test') !!}</span></button>+ <a href="#" wire:click.prevent="testSlack" id="test_slack" class="btn btn-default btn-sm pull-left"><span>{!! trans('admin/settings/general.slack_test') !!}</span></a><div wire:loading><i class="fas fa-spinner spin"></i></div>- @if($response == 'success')- message here- @endif- @if($response == 'error')- message here- @endif</div>-</div>+ </div>@endif-{{-- <div class="col-md-10 col-md-offset-2">--}}-{{-- <span id="slacktesticon"></span>--}}-{{-- <span id="slacktestresult"></span>--}}-{{-- <span id="slackteststatus"></span>--}}-{{-- </div>--}}- <div class="box-footer">- <div class="text-left col-md-6">+ <div class="box-footer" style="margin-top: 45px;">++ <div class="text-right col-md-12"><a class="btn btn-link text-left" href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a>- </div>- <div class="text-right col-md-6"><button type="submit" id="save_slack" class="btn btn-primary"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.save') }}</button></div></div><!--box-footer-->