diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 1913c86286..541d4070ff 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1147,4 +1147,39 @@ class Helper return $age; } + + + /* + * This is a shorter way to see if the app is in demo mode. + * + * This makes it cleanly available in blades and in controllers, e.g. + * + * Blade: + * {{ Helper::isDemoMode() ? ' disabled' : ''}} for form blades where we need to disable a form + * + * Controller: + * if (Helper::isDemoMode()) { + * // don't allow the thing + * } + * @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff + */ + public function isDemoMode() { + if (config('app.lock_passwords') === true) { + return true; + \Log::debug('app locked!'); + } + + return false; + } + + + /* + * I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time, + * it seemed pretty safe to do here. Don't you judge me. + */ + public function showDemoModeFieldWarning() { + if (Helper::isDemoMode()) { + return "
" . trans('general.feature_disabled') . "
"; + } + } } diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 6ba3b5b1a9..bb3a7bd7f6 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -5,6 +5,7 @@ namespace App\Http\Livewire; use GuzzleHttp\Client; use Livewire\Component; use App\Models\Setting; +use App\Helpers\Helper; class SlackSettingsForm extends Component { @@ -27,7 +28,7 @@ class SlackSettingsForm extends Component 'webhook_botname' => 'string|nullable', ]; - public function mount(){ + public function mount() { $this->webhook_text= [ "slack" => array( "name" => trans('admin/settings/general.slack') , @@ -62,12 +63,14 @@ class SlackSettingsForm extends Component } } - public function updated($field){ + public function updated($field) { + if($this->webhook_selected != 'general') { $this->validateOnly($field, $this->rules); } } - public function updatedWebhookSelected(){ + + public function updatedWebhookSelected() { $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"]; @@ -78,7 +81,7 @@ class SlackSettingsForm extends Component } } - private function isButtonDisabled(){ + private function isButtonDisabled() { if($this->webhook_selected == 'slack') { if (empty($this->webhook_endpoint)) { $this->isDisabled = 'disabled'; @@ -91,6 +94,7 @@ class SlackSettingsForm extends Component } } + public function render() { $this->isButtonDisabled(); @@ -115,48 +119,59 @@ class SlackSettingsForm extends Component ]); try { + $webhook->post($this->webhook_endpoint, ['body' => $payload]); $this->isDisabled=''; $this->save_button = trans('general.save'); return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!'); } catch (\Exception $e) { + $this->isDisabled= 'disabled'; return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); } - //} - return session()->flash('message' , trans('admin/settings/message.webhook.error_misc')); + return session()->flash('error' , trans('admin/settings/message.webhook.error_misc')); } public function clearSettings(){ - $this->webhook_endpoint = ''; - $this->webhook_channel = ''; - $this->webhook_botname = ''; - $this->setting->webhook_endpoint = ''; - $this->setting->webhook_channel = ''; - $this->setting->webhook_botname = ''; - $this->setting->save(); + if (Helper::isDemoMode()) { + session()->flash('error',trans('general.feature_disabled')); + } else { + $this->webhook_endpoint = ''; + $this->webhook_channel = ''; + $this->webhook_botname = ''; + $this->setting->webhook_endpoint = ''; + $this->setting->webhook_channel = ''; + $this->setting->webhook_botname = ''; - session()->flash('save',trans('admin/settings/message.update.success')); + $this->setting->save(); + + session()->flash('success', trans('admin/settings/message.update.success')); + } } public function submit() { - if($this->webhook_selected != 'general') { - $this->validate($this->rules); + if (Helper::isDemoMode()) { + session()->flash('error',trans('general.feature_disabled')); + } else { + if ($this->webhook_selected != 'general') { + $this->validate($this->rules); + } + + $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('success',trans('admin/settings/message.update.success')); + } - $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/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index 8ab77c6631..ed5bd48dd2 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -150,6 +150,7 @@ class SettingsServiceProvider extends ServiceProvider // Set the monetary locale to the configured locale to make helper::parseFloat work. setlocale(LC_MONETARY, config('app.locale')); setlocale(LC_NUMERIC, config('app.locale')); + } /** diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 8b6063f421..48e61d540e 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -417,6 +417,6 @@ return [ 'merged' => 'merged', 'merged_log_this_user_into' => 'Merged this user (ID :to_id - :to_username) into user ID :from_id (:from_username) ', 'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)', - + 'clear_and_save' => 'Clear & Save', ]; \ No newline at end of file diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index b94d273176..a1df7ef242 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -12,33 +12,33 @@ {{-- Page content --}} @section('content') -