mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Add slack support to Firefly III
This commit is contained in:
@@ -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'));
|
||||
|
@@ -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'));
|
||||
|
Reference in New Issue
Block a user