info('User visits notifications index.'); $title = (string) trans('firefly.administration'); $mainTitleIcon = 'fa-hand-spock-o'; $subTitle = (string) trans('firefly.title_owner_notifications'); $subTitleIcon = 'envelope-o'; $slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data; $channels = config('notifications.channels'); $forcedAvailability = []; // admin notification settings: $notifications = []; foreach (config('notifications.notifications.owner') as $key => $info) { if ($info['enabled']) { $notifications[$key] = app('fireflyconfig')->get(sprintf('notification_%s', $key), true)->data; } } // loop all channels foreach ($channels as $channel => $info) { $forcedAvailability[$channel] = true; } // validate presence of of Ntfy settings. if('' === (string)config('ntfy-notification-channel.topic')) { Log::warning('No topic name for Ntfy, channel is disabled.'); $forcedAvailability['ntfy'] = false; } return view('admin.notifications.index', compact('title', 'subTitle', 'forcedAvailability', 'mainTitleIcon', 'subTitleIcon', 'channels', 'slackUrl', 'notifications')); } public function postIndex(NotificationRequest $request): RedirectResponse { $all = $request->getAll(); foreach (config('notifications.notifications.owner') as $key => $info) { if (array_key_exists($key, $all)) { app('fireflyconfig')->set(sprintf('notification_%s', $key), $all[$key]); } } if ('' === $all['slack_url']) { app('fireflyconfig')->delete('slack_webhook_url'); } if ('' !== $all['slack_url']) { app('fireflyconfig')->set('slack_webhook_url', $all['slack_url']); } session()->flash('success', (string) trans('firefly.notification_settings_saved')); return redirect(route('admin.notification.index')); } public function testNotification(Request $request): RedirectResponse { $all = $request->all(); $channel = $all['test_submit'] ?? ''; switch ($channel) { default: session()->flash('error', (string) trans('firefly.notification_test_failed', ['channel' => $channel])); break; case 'email': case 'slack': case 'ntfy': /** @var User $user */ $user = auth()->user(); app('log')->debug(sprintf('Now in testNotification("%s") controller.', $channel)); event(new TestNotificationChannel($channel, $user)); session()->flash('success', (string) trans('firefly.notification_test_executed', ['channel' => $channel])); } return redirect(route('admin.notification.index')); } }