Skip to content

Commit b6eb318

Browse files
authored
Merge pull request #16968 from marcusmoore/bug/sc-29233
Fixed potential slack webhook setting inconsistencies
2 parents 286f787 + 5739393 commit b6eb318

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

app/Livewire/SlackSettingsForm.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function mount() {
7171

7272
$this->setting = Setting::getSettings();
7373
$this->save_button = trans('general.save');
74-
$this->webhook_selected = $this->setting->webhook_selected ?? 'slack';
74+
$this->webhook_selected = ($this->setting->webhook_selected !== '') ? $this->setting->webhook_selected : 'slack';
7575
$this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"] ?? $this->webhook_text['slack']["name"];
7676
$this->webhook_icon = $this->webhook_text[$this->setting->webhook_selected]["icon"] ?? $this->webhook_text['slack']["icon"];
7777
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"] ?? $this->webhook_text['slack']["placeholder"];
@@ -191,7 +191,6 @@ public function clearSettings(){
191191
$this->setting->webhook_endpoint = '';
192192
$this->setting->webhook_channel = '';
193193
$this->setting->webhook_botname = '';
194-
$this->setting->webhook_selected = '';
195194

196195
$this->setting->save();
197196

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class extends Migration {
7+
/**
8+
* Run the migrations.
9+
*/
10+
public function up(): void
11+
{
12+
$settings = DB::table('settings')->first();
13+
14+
if ($settings) {
15+
/** If webhook settings were cleared via the integration settings page,
16+
* the webhook_selected was cleared as well when it should have reset to "slack".
17+
*/
18+
if (
19+
empty($settings->webhook_selected) &&
20+
(empty($settings->webhook_botname) && empty($settings->webhook_channel) && empty($settings->webhook_endpoint))
21+
) {
22+
DB::table('settings')->update(['webhook_selected' => 'slack']);
23+
}
24+
25+
/** If webhook settings were cleared via the integration settings page,
26+
* then slack settings were re-added; then webhook_selected was not being set to "slack" as needed.
27+
*/
28+
if (str_contains($settings->webhook_endpoint, 'slack.com')) {
29+
DB::table('settings')->update(['webhook_selected' => 'slack']);
30+
}
31+
}
32+
}
33+
34+
/**
35+
* Reverse the migrations.
36+
*/
37+
public function down(): void
38+
{
39+
//
40+
}
41+
};

resources/views/livewire/slack-settings-form.blade.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
: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')]"
7373
:selected="old('webhook_selected', $webhook_selected)"
7474
:disabled="Helper::isDemoMode()"
75+
:for-livewire="true"
7576
data-minimum-results-for-search="-1"
7677
class="form-control"
7778
style="width:100%"
@@ -174,22 +175,3 @@ class="btn btn-default btn-sm pull-left">
174175
</div> <!-- /.row -->
175176
</form>
176177
</div> <!-- /livewire div -->
177-
178-
179-
180-
181-
@section('moar_scripts')
182-
<script>
183-
$(document).ready(function () {
184-
$('#select2').select2();
185-
$('#select2').on('change', function (e) {
186-
var data = $('#select2').select2("val");
187-
@this.set('webhook_selected', data);
188-
});
189-
});
190-
191-
192-
</script>
193-
@endsection
194-
195-

0 commit comments

Comments
 (0)