Merge pull request #16968 from marcusmoore/bug/sc-29233

Fixed potential slack webhook setting inconsistencies
This commit is contained in:
snipe
2025-05-23 14:05:01 +02:00
committed by GitHub
3 changed files with 43 additions and 21 deletions
+1 -2
View File
@@ -71,7 +71,7 @@ class SlackSettingsForm extends Component
$this->setting = Setting::getSettings();
$this->save_button = trans('general.save');
$this->webhook_selected = $this->setting->webhook_selected ?? 'slack';
$this->webhook_selected = ($this->setting->webhook_selected !== '') ? $this->setting->webhook_selected : 'slack';
$this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"] ?? $this->webhook_text['slack']["name"];
$this->webhook_icon = $this->webhook_text[$this->setting->webhook_selected]["icon"] ?? $this->webhook_text['slack']["icon"];
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"] ?? $this->webhook_text['slack']["placeholder"];
@@ -191,7 +191,6 @@ class SlackSettingsForm extends Component
$this->setting->webhook_endpoint = '';
$this->setting->webhook_channel = '';
$this->setting->webhook_botname = '';
$this->setting->webhook_selected = '';
$this->setting->save();
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
$settings = DB::table('settings')->first();
if ($settings) {
/** If webhook settings were cleared via the integration settings page,
* the webhook_selected was cleared as well when it should have reset to "slack".
*/
if (
empty($settings->webhook_selected) &&
(empty($settings->webhook_botname) && empty($settings->webhook_channel) && empty($settings->webhook_endpoint))
) {
DB::table('settings')->update(['webhook_selected' => 'slack']);
}
/** If webhook settings were cleared via the integration settings page,
* then slack settings were re-added; then webhook_selected was not being set to "slack" as needed.
*/
if (str_contains($settings->webhook_endpoint, 'slack.com')) {
DB::table('settings')->update(['webhook_selected' => 'slack']);
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
@@ -72,6 +72,7 @@
:options="['slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'),'google' => trans('admin/settings/general.google_workspaces'), 'microsoft' => trans('admin/settings/general.ms_teams')]"
:selected="old('webhook_selected', $webhook_selected)"
:disabled="Helper::isDemoMode()"
:for-livewire="true"
data-minimum-results-for-search="-1"
class="form-control"
style="width:100%"
@@ -174,22 +175,3 @@
</div> <!-- /.row -->
</form>
</div> <!-- /livewire div -->
@section('moar_scripts')
<script>
$(document).ready(function () {
$('#select2').select2();
$('#select2').on('change', function (e) {
var data = $('#select2').select2("val");
@this.set('webhook_selected', data);
});
});
</script>
@endsection