A free open source IT asset/license management system
refactor webhook livewire component and blade for reusable company settings
Godfrey M1cb227b0e462
diff --git a/app/Livewire/SlackSettingsForm.php b/app/Livewire/SlackSettingsForm.phpindex 9bd2fcefbf..3f8933b226 100644--- a/app/Livewire/SlackSettingsForm.php+++ b/app/Livewire/SlackSettingsForm.php@@ -4,6 +4,7 @@ namespace App\Livewire;use App\Helpers\Helper;use App\Models\Setting;+use App\Models\Company;use App\Rules\ExternalUrl;use GuzzleHttp\Client;use Illuminate\Support\Facades\Http;@@ -38,9 +39,10 @@ class SlackSettingsForm extends Componentpublic array $webhook_text;- public Setting $setting;+ public ?Company $company = null;public $save_button;+ public array $savedWebhook = [];public $webhook_endpoint_rules;@@ -79,8 +81,11 @@ class SlackSettingsForm extends Component}}- public function mount()+ public function mount(?Company $company = null){+ $this->authorizeWebhookManagement();++$this->webhook_text = ['slack' => ['name' => trans('admin/settings/general.slack'),@@ -108,23 +113,15 @@ class SlackSettingsForm extends Component],];- $this->setting = Setting::getSettings();- $this->save_button = trans('general.save');- if (!$this->webhook_selected) {- $this->webhook_selected = 'slack';- }-+ $this->loadWebhookSettings();+ $this->updatedWebhookSelected();- $this->webhook_options = $this->setting->webhook_selected ? $this->setting->webhook_selected : 'slack';+ $this->save_button = trans('general.save');- $this->updatedWebhookSelected();- $this->webhook_endpoint = $this->setting->webhook_endpoint;- $this->webhook_channel = $this->setting->webhook_channel;- $this->webhook_botname = $this->setting->webhook_botname;$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); // consider moving this to webhook_link updated? (updatedWebhookLink?)- if ($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null) {+ if ($this->webhook_endpoint != null && $this->webhook_channel != null) {$this->isDisabled = '';}if ($this->webhook_selected === 'microsoft' && $this->teams_webhook_deprecated) { //since this is URL-aware, maybe also move this?@@ -134,7 +131,7 @@ class SlackSettingsForm extends Componentpublic function updated($field){- //anything changes; then clear the succcess message (and error message)+ //anything changes; then clear the success message (and error message)$this->success = null;$this->error = null;$this->validateOnly($field);@@ -146,20 +143,41 @@ class SlackSettingsForm extends Component$this->webhook_name = $this->webhook_text[$this->webhook_selected]['name'];$this->webhook_icon = $this->webhook_text[$this->webhook_selected]['icon'];$this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]['placeholder'];- $this->webhook_endpoint = null; // TODO - do we really want to blank this?$this->webhook_link = $this->webhook_text[$this->webhook_selected]['link'];++ if ($this->webhook_selected === $this->savedWebhook['selected']) {+ $this->webhook_endpoint = $this->savedWebhook['endpoint'];+ $this->webhook_channel = $this->savedWebhook['channel'];+ $this->webhook_botname = $this->savedWebhook['botname'];+ } else {+ $this->webhook_endpoint = null;+ $this->webhook_channel = null;+ $this->webhook_botname = null;++ if (in_array($this->webhook_selected, ['microsoft', 'google'])) {+ $this->webhook_channel = '#NA';+ }+ }if ($this->webhook_selected != 'slack') { // TODO: hrm. Wouldn't we want to test all of them? Or at least some of them? Maybe not "generic webhook"?$this->isDisabled = '';$this->save_button = trans('general.save');}- if ($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google') {- $this->webhook_channel = '#NA';- }}- public function updatedwebhookEndpoint()+ public function updatedWebhookEndpoint(){- $this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');+ if ($this->webhook_selected !== 'microsoft') {+ $this->teams_webhook_deprecated = false;+ $this->warning = null;+ return;+ }++ $this->teams_webhook_deprecated = filled($this->webhook_endpoint)+ && !Str::contains($this->webhook_endpoint, 'workflows');++ $this->warning = $this->webhook_selected === 'microsoft' && $this->teams_webhook_deprecated+ ? trans('admin/settings/message.webhook.ms_teams_deprecation')+ : null;}public function render()@@ -182,11 +200,14 @@ class SlackSettingsForm extends Component$this->webhook_endpoint = '';$this->webhook_channel = '';$this->webhook_botname = '';- $this->setting->webhook_endpoint = '';- $this->setting->webhook_channel = '';- $this->setting->webhook_botname = '';- $this->setting->save();+ $source = $this->webhookSource();++ $source->webhook_endpoint = '';+ $source->webhook_channel = '';+ $source->webhook_botname = '';++ $source->save();$this->success = trans('admin/settings/message.update.success');}@@ -198,13 +219,20 @@ class SlackSettingsForm extends Component$this->error = trans('general.feature_disabled');} else {$this->validate();+ $source = $this->webhookSource();- $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;+ $source->webhook_selected = $this->webhook_selected;+ $source->webhook_endpoint = $this->webhook_endpoint;+ $source->webhook_channel = $this->webhook_channel;+ $source->webhook_botname = $this->webhook_botname;+ $source->save();- $this->setting->save();+ $this->savedWebhook = [+ 'selected' => $this->webhook_selected,+ 'endpoint' => $this->webhook_endpoint,+ 'channel' => $this->webhook_channel,+ 'botname' => $this->webhook_botname,+ ];$this->success = trans('admin/settings/message.update.success');}@@ -316,4 +344,34 @@ class SlackSettingsForm extends Component$this->addError('connection', trans('admin/settings/general.rate_limited'));}}++ protected function webhookSource(): Company|Setting+ {+ return $this->company ?? Setting::getSettings();+ }++ protected function authorizeWebhookManagement(): void+ {+ if ($this->company) {+ $this->authorize('update', $this->company);+ }+ }++ protected function loadWebhookSettings(): void+ {+ $source = $this->webhookSource();++ $this->webhook_selected = $source->webhook_selected ?: 'slack';+ $this->webhook_endpoint = $source->webhook_endpoint;+ $this->webhook_channel = $source->webhook_channel;+ $this->webhook_botname = $source->webhook_botname;++ $this->savedWebhook = [+ 'selected' => $this->webhook_selected,+ 'endpoint' => $this->webhook_endpoint,+ 'channel' => $this->webhook_channel,+ 'botname' => $this->webhook_botname,+ ];++ }}\ No newline at end of filediff --git a/database/migrations/2026_09_17_183342_add_fmcs_webhook_settings_to_companies_table.php b/database/migrations/2026_09_17_183342_add_fmcs_webhook_settings_to_companies_table.phpnew file mode 100644index 0000000000..7b49930945--- /dev/null+++ b/database/migrations/2026_09_17_183342_add_fmcs_webhook_settings_to_companies_table.php@@ -0,0 +1,33 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration {+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('companies', function (Blueprint $table) {+ $table->string('webhook_selected')->nullable();+ $table->text('webhook_endpoint')->nullable();+ $table->string('webhook_channel')->nullable();+ $table->string('webhook_botname')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('companies', function (Blueprint $table) {+ $table->dropColumn('webhook_selected');+ $table->dropColumn('webhook_endpoint');+ $table->dropColumn('webhook_channel');+ $table->dropColumn('webhook_botname');+ });+ }+};diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.phpindex 0df64f0d6b..95f033ed36 100644--- a/resources/views/livewire/slack-settings-form.blade.php+++ b/resources/views/livewire/slack-settings-form.blade.php@@ -1,17 +1,3 @@-{{-- 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><!-- livewire div - do not remove --><form class="form-horizontal" role="form" wire:submit.prevent="submit">{{csrf_field()}}@@ -87,7 +73,7 @@<label for="webhook_endpoint">{{ trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ]) }}</label></div><div class="col-md-9 required">- <input type="url" wire:model.change.live="webhook_endpoint" class="form-control" placeholder="{{$webhook_placeholder}}" value="{{old('webhook_endpoint', $webhook_endpoint)}}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>+ <input type="url" wire:model.change.live="webhook_endpoint" class="form-control" placeholder="{{$webhook_placeholder}}"{{ Helper::isDemoMode() ? ' disabled' : ''}}><x-form.error name="webhook_endpoint" /></div></div>@@ -104,7 +90,7 @@<label for="webhook_channel">{{ trans('admin/settings/general.webhook_channel',['app' => $webhook_name ]) }}</label></div><div class="col-md-9 required">- <input type="text" wire:model.change.live="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>+ <input type="text" wire:model.change.live="webhook_channel" class="form-control" placeholder="#IT-Ops" {{ Helper::isDemoMode() ? ' disabled' : ''}}><x-form.error name="webhook_channel" /></div>@@ -122,7 +108,7 @@<label for="webhook_botname">{{ trans('admin/settings/general.webhook_botname',['app' => $webhook_name ]) }}</label></div><div class="col-md-9">- <input type="text" wire:model.change.live="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>+ <input type="text" wire:model.change.live="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ Helper::isDemoMode() ? ' disabled' : ''}}><x-form.error name="webhook_botname" /></div><!--col-md-10--></div>diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.phpindex 43b6456111..71540674b9 100644--- a/resources/views/settings/slack.blade.php+++ b/resources/views/settings/slack.blade.php@@ -1,4 +1,15 @@@extends('layouts/default')+{{-- 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')@livewire('slack-settings-form')@stop