diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 62380b2212..26d380353f 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -143,21 +143,11 @@ class SettingsController extends Controller } - public function slacktest(SlackSettingsRequest $request) + public function slacktest($slack_endpoint,$slack_channel,$slack_botname) { - - $validator = Validator::make($request->all(), [ - 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', - 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', - ]); - - if ($validator->fails()) { - return response()->json(['message' => 'Validation failed', 'errors' => $validator->errors()], 422); - } - // If validation passes, continue to the curl request $slack = new Client([ - 'base_url' => e($request->input('slack_endpoint')), + 'base_url' => e($slack_endpoint), 'defaults' => [ 'exceptions' => false, ], @@ -165,18 +155,18 @@ class SettingsController extends Controller $payload = json_encode( [ - 'channel' => e($request->input('slack_channel')), + 'channel' => e($slack_channel), 'text' => trans('general.slack_test_msg'), - 'username' => e($request->input('slack_botname')), + 'username' => e($slack_botname), 'icon_emoji' => ':heart:', ]); try { - $slack->post($request->input('slack_endpoint'), ['body' => $payload]); + $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($request->input('slack_endpoint')).'). Slack responded with: '.$e->getMessage()], 400); + return response()->json(['message' => 'Please check the channel name and webhook endpoint URL ('.e($slack_endpoint).'). Slack responded with: '.$e->getMessage()], 400); } //} diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 9a7c2cc7d5..6daaabdc9f 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -688,15 +688,15 @@ class SettingsController extends Controller * * @return View */ - public function postSlack(SlackSettingsRequest $request) + public function postSlack($slack_endpoint,$slack_channel,$slack_botname) { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } - $setting->slack_endpoint = $request->input('slack_endpoint'); - $setting->slack_channel = $request->input('slack_channel'); - $setting->slack_botname = $request->input('slack_botname'); + $setting->slack_endpoint = $slack_endpoint; + $setting->slack_channel = $slack_channel; + $setting->slack_botname = $slack_botname; if ($setting->save()) { return redirect()->route('settings.index') diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 2cb153734c..fbc54a0517 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -4,28 +4,16 @@ namespace App\Http\Livewire; use Livewire\Component; use App\Models\Setting; +use App\Http\Controllers\Api\SettingsController; class SlackSettingsForm extends Component { public $slack_endpoint; public $slack_channel; public $slack_botname; - public $successMessage; public Setting $setting; - protected $rules = [ - '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', - ]; - protected $messages = [ - 'slack_endpoint.required_with' => 'Slack endpoint is required', - 'slack_endpoint.starts_with' => 'Slack endpoint must start with https://hooks.slack.com', - - - ]; - public function mount(){ $this->setting = Setting::getSettings(); @@ -40,6 +28,11 @@ class SlackSettingsForm extends Component return view('livewire.slack-settings-form'); } + public function testSlack($slack_endpoint, $slack_channel, $slack_botname){ + SettingsController::testSlack($slack_endpoint,$slack_channel,$slack_botname); + + + } public function submit() { $this->validate([ diff --git a/app/Http/Requests/SlackSettingsRequest.php b/app/Http/Requests/SlackSettingsRequest.php index 1f44215198..e8f7d2f0ea 100644 --- a/app/Http/Requests/SlackSettingsRequest.php +++ b/app/Http/Requests/SlackSettingsRequest.php @@ -25,7 +25,6 @@ class SlackSettingsRequest extends Request '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.php index b01ffa867f..6562f41b33 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -8,6 +8,7 @@ @endif