Add slack support to Firefly III

This commit is contained in:
James Cole
2022-09-24 12:14:27 +02:00
parent 2945f5fcde
commit 45d7042405
10 changed files with 138 additions and 17 deletions

View File

@@ -75,8 +75,9 @@ class HomeController extends Controller
foreach (config('firefly.admin_notifications') as $item) {
$notifications[$item] = FireflyConfig::get(sprintf('notification_%s', $item), true)->data;
}
$slackUrl = FireflyConfig::get('slack_webhook_url', '')->data;
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications'));
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications', 'slackUrl'));
}
public function notifications(Request $request): RedirectResponse
@@ -86,7 +87,14 @@ class HomeController extends Controller
if ($request->has(sprintf('notification_%s', $item))) {
$value = true;
}
FireflyConfig::set(sprintf('notification_%s',$item), $value);
FireflyConfig::set(sprintf('notification_%s', $item), $value);
}
$url = (string) $request->get('slackUrl');
if ('' === $url) {
FireflyConfig::delete('slack_webhook_url');
}
if (str_starts_with($url, 'https://hooks.slack.com/services/')) {
FireflyConfig::set('slack_webhook_url', $url);
}
session()->flash('success', (string) trans('firefly.notification_settings_saved'));

View File

@@ -101,6 +101,7 @@ class PreferencesController extends Controller
$languages = config('firefly.languages');
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
$slackUrl = app('preferences')->get('slack_webhook_url', '')->data;
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
@@ -139,6 +140,7 @@ class PreferencesController extends Controller
'frontPageAccounts',
'languages',
'notifications',
'slackUrl',
'locales',
'locale',
'tjOptionalFields',
@@ -173,12 +175,12 @@ class PreferencesController extends Controller
// extract notifications:
$all = $request->all();
foreach(config('firefly.available_notifications') as $option) {
foreach (config('firefly.available_notifications') as $option) {
$key = sprintf('notification_%s', $option);
if(array_key_exists($key, $all)) {
if (array_key_exists($key, $all)) {
app('preferences')->set($key, true);
}
if(!array_key_exists($key, $all)) {
if (!array_key_exists($key, $all)) {
app('preferences')->set($key, false);
}
}
@@ -190,6 +192,16 @@ class PreferencesController extends Controller
session()->forget('end');
session()->forget('range');
// slack URL:
$url = (string) $request->get('slackUrl');
if(str_starts_with($url, 'https://hooks.slack.com/services/')){
app('preferences')->set('slack_webhook_url', $url);
}
if('' === $url) {
app('preferences')->delete('slack_webhook_url');
}
// custom fiscal year
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
$string = strtotime((string) $request->get('fiscalYearStart'));