mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update packages and notification settings
This commit is contained in:
parent
0e5eb036b0
commit
abad7cdf16
@ -46,13 +46,11 @@ class NotificationController extends Controller
|
||||
$slackUrl = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
|
||||
$pushoverAppToken = app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;
|
||||
$pushoverUserToken = app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;
|
||||
|
||||
$ntfyServer = app('fireflyconfig')->getEncrypted('ntfy_server', 'https://ntfy.sh')->data;
|
||||
$ntfyTopic = app('fireflyconfig')->getEncrypted('ntfy_topic', '')->data;
|
||||
$ntfyAuth = app('fireflyconfig')->get('ntfy_auth', false)->data;
|
||||
$ntfyUser = app('fireflyconfig')->getEncrypted('ntfy_user', '')->data;
|
||||
$ntfyPass = app('fireflyconfig')->getEncrypted('ntfy_pass', '')->data;
|
||||
|
||||
$channels = config('notifications.channels');
|
||||
$forcedAvailability = [];
|
||||
|
||||
|
@ -49,7 +49,7 @@ class PreferencesController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.preferences'));
|
||||
app('view')->share('title', (string) trans('firefly.preferences'));
|
||||
app('view')->share('mainTitleIcon', 'fa-gear');
|
||||
|
||||
return $next($request);
|
||||
@ -66,14 +66,14 @@ class PreferencesController extends Controller
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$isDocker = env('IS_DOCKER', false);
|
||||
$groupedAccounts = [];
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$isDocker = env('IS_DOCKER', false);
|
||||
$groupedAccounts = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$type = $account->accountType->type;
|
||||
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
|
||||
$type = $account->accountType->type;
|
||||
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
|
||||
|
||||
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) {
|
||||
$role = sprintf('opt_group_l_%s', $type);
|
||||
@ -82,7 +82,7 @@ class PreferencesController extends Controller
|
||||
if ('opt_group_' === $role) {
|
||||
$role = 'opt_group_defaultAsset';
|
||||
}
|
||||
$groupedAccounts[(string)trans(sprintf('firefly.%s', $role))][$account->id] = $account->name;
|
||||
$groupedAccounts[(string) trans(sprintf('firefly.%s', $role))][$account->id] = $account->name;
|
||||
}
|
||||
ksort($groupedAccounts);
|
||||
|
||||
@ -94,26 +94,40 @@ class PreferencesController extends Controller
|
||||
if (!is_array($frontpageAccounts)) {
|
||||
$frontpageAccounts = $accountIds;
|
||||
}
|
||||
$language = app('steam')->getLanguage();
|
||||
$languages = config('firefly.languages');
|
||||
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
|
||||
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
|
||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||
$slackUrl = app('preferences')->get('slack_webhook_url', '')->data;
|
||||
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
||||
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
||||
$language = app('steam')->getLanguage();
|
||||
$languages = config('firefly.languages');
|
||||
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
|
||||
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
|
||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
||||
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
||||
if (is_array($fiscalYearStartStr)) {
|
||||
$fiscalYearStartStr = '01-01';
|
||||
}
|
||||
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string)$fiscalYearStartStr);
|
||||
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$availableDarkModes = config('firefly.available_dark_modes');
|
||||
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string) $fiscalYearStartStr);
|
||||
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$availableDarkModes = config('firefly.available_dark_modes');
|
||||
|
||||
// notifications settings
|
||||
$slackUrl = app('preferences')->getEncrypted('slack_webhook_url', '')->data;
|
||||
$pushoverAppToken = app('preferences')->getEncrypted('pushover_app_token', '')->data;
|
||||
$pushoverUserToken = app('preferences')->getEncrypted('pushover_user_token', '')->data;
|
||||
$ntfyServer = app('preferences')->getEncrypted('ntfy_server', 'https://ntfy.sh')->data;
|
||||
$ntfyTopic = app('preferences')->getEncrypted('ntfy_topic', '')->data;
|
||||
$ntfyAuth = app('preferences')->get('ntfy_auth', false)->data;
|
||||
$ntfyUser = app('preferences')->getEncrypted('ntfy_user', '')->data;
|
||||
$ntfyPass = app('preferences')->getEncrypted('ntfy_pass', '')->data;
|
||||
|
||||
|
||||
// notification preferences (single value for each):
|
||||
$notifications = [];
|
||||
$notifications = [];
|
||||
foreach (config('notifications.notifications.user') as $key => $info) {
|
||||
if($info['enabled']) {
|
||||
$notifications[$key] = app('preferences')->get(sprintf('notification_%s', $key), true)->data;
|
||||
if ($info['enabled']) {
|
||||
$notifications[$key]
|
||||
= [
|
||||
'enabled' => app('preferences')->get(sprintf('notification_%s', $key), true)->data,
|
||||
'configurable' => $info['configurable'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,26 +136,34 @@ class PreferencesController extends Controller
|
||||
// list of locales also has "equal" which makes it equal to whatever the language is.
|
||||
|
||||
try {
|
||||
$locales = json_decode((string)file_get_contents(resource_path(sprintf('locales/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
|
||||
$locales = json_decode((string) file_get_contents(resource_path(sprintf('locales/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (\JsonException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
$locales = [];
|
||||
}
|
||||
$locales = ['equal' => (string)trans('firefly.equal_to_language')] + $locales;
|
||||
$locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales;
|
||||
// an important fallback is that the frontPageAccount array gets refilled automatically
|
||||
// when it turns up empty.
|
||||
if (0 === count($frontpageAccounts)) {
|
||||
$frontpageAccounts = $accountIds;
|
||||
}
|
||||
|
||||
// for the demo user, the slackUrl is automatically emptied.
|
||||
// this isn't really secure, but it means that the demo site has a semi-secret
|
||||
// slackUrl.
|
||||
// for the demo user, the notification settings are automatically emptied.
|
||||
// this isn't really secure, but it means that the demo site has semi-secret notification settings.
|
||||
if (auth()->user()->hasRole('demo')) {
|
||||
$slackUrl = '';
|
||||
$pushoverAppToken = '';
|
||||
$pushoverUserToken = '';
|
||||
$ntfyServer = '';
|
||||
$ntfyTopic = '';
|
||||
$ntfyAuth = false;
|
||||
$ntfyUser = '';
|
||||
$ntfyPass = '';
|
||||
}
|
||||
|
||||
return view('preferences.index', compact('language', 'groupedAccounts', 'isDocker', 'frontpageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart'));
|
||||
return view('preferences.index', compact('language', 'pushoverAppToken', 'pushoverUserToken',
|
||||
'ntfyServer', 'ntfyTopic', 'ntfyAuth', 'ntfyUser', 'ntfyPass',
|
||||
'groupedAccounts', 'isDocker', 'frontpageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,13 +182,13 @@ class PreferencesController extends Controller
|
||||
$frontpageAccounts = [];
|
||||
if (is_array($request->get('frontpageAccounts')) && count($request->get('frontpageAccounts')) > 0) {
|
||||
foreach ($request->get('frontpageAccounts') as $id) {
|
||||
$frontpageAccounts[] = (int)$id;
|
||||
$frontpageAccounts[] = (int) $id;
|
||||
}
|
||||
app('preferences')->set('frontpageAccounts', $frontpageAccounts);
|
||||
}
|
||||
|
||||
// extract notifications:
|
||||
$all = $request->all();
|
||||
$all = $request->all();
|
||||
die('fix the reference to the available notifications.');
|
||||
foreach (config('firefly.available_notifications') as $option) {
|
||||
$key = sprintf('notification_%s', $option);
|
||||
@ -187,7 +209,7 @@ class PreferencesController extends Controller
|
||||
|
||||
// slack URL:
|
||||
if (!auth()->user()->hasRole('demo')) {
|
||||
$url = (string)$request->get('slackUrl');
|
||||
$url = (string) $request->get('slackUrl');
|
||||
if (UrlValidator::isValidWebhookURL($url)) {
|
||||
app('preferences')->set('slack_webhook_url', $url);
|
||||
}
|
||||
@ -197,8 +219,8 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// custom fiscal year
|
||||
$customFiscalYear = 1 === (int)$request->get('customFiscalYear');
|
||||
$string = strtotime((string)$request->get('fiscalYearStart'));
|
||||
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
|
||||
$string = strtotime((string) $request->get('fiscalYearStart'));
|
||||
if (false !== $string) {
|
||||
$fiscalYearStart = date('m-d', $string);
|
||||
app('preferences')->set('customFiscalYear', $customFiscalYear);
|
||||
@ -207,15 +229,15 @@ class PreferencesController extends Controller
|
||||
|
||||
// save page size:
|
||||
app('preferences')->set('listPageSize', 50);
|
||||
$listPageSize = (int)$request->get('listPageSize');
|
||||
$listPageSize = (int) $request->get('listPageSize');
|
||||
if ($listPageSize > 0 && $listPageSize < 1337) {
|
||||
app('preferences')->set('listPageSize', $listPageSize);
|
||||
}
|
||||
|
||||
// language:
|
||||
/** @var Preference $currentLang */
|
||||
$currentLang = app('preferences')->get('language', 'en_US');
|
||||
$lang = $request->get('language');
|
||||
$currentLang = app('preferences')->get('language', 'en_US');
|
||||
$lang = $request->get('language');
|
||||
if (array_key_exists($lang, config('firefly.languages'))) {
|
||||
app('preferences')->set('language', $lang);
|
||||
}
|
||||
@ -232,8 +254,8 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// optional fields for transactions:
|
||||
$setOptions = $request->get('tj') ?? [];
|
||||
$optionalTj = [
|
||||
$setOptions = $request->get('tj') ?? [];
|
||||
$optionalTj = [
|
||||
'interest_date' => array_key_exists('interest_date', $setOptions),
|
||||
'book_date' => array_key_exists('book_date', $setOptions),
|
||||
'process_date' => array_key_exists('process_date', $setOptions),
|
||||
@ -250,12 +272,12 @@ class PreferencesController extends Controller
|
||||
app('preferences')->set('transaction_journal_optional_fields', $optionalTj);
|
||||
|
||||
// dark mode
|
||||
$darkMode = $request->get('darkMode') ?? 'browser';
|
||||
$darkMode = $request->get('darkMode') ?? 'browser';
|
||||
if (in_array($darkMode, config('firefly.available_dark_modes'), true)) {
|
||||
app('preferences')->set('darkMode', $darkMode);
|
||||
}
|
||||
|
||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||
session()->flash('success', (string) trans('firefly.saved_preferences'));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect(route('preferences.index'));
|
||||
|
@ -56,13 +56,13 @@ class FireflyConfig
|
||||
return null;
|
||||
}
|
||||
if ('' === $result->data) {
|
||||
Log::warning(sprintf('Empty encrypted preference found: "%s"', $name));
|
||||
Log::warning(sprintf('Empty encrypted configuration value found: "%s"', $name));
|
||||
return $result;
|
||||
}
|
||||
try {
|
||||
$result->data = decrypt($result->data);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
Log::error(sprintf('Could not decrypt configuration value "%s": %s', $name, $e->getMessage()));
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
@ -105,8 +105,8 @@ class FireflyConfig
|
||||
try {
|
||||
$encrypted = encrypt($value);
|
||||
} catch (EncryptException $e) {
|
||||
Log::error(sprintf('Could not encrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not encrypt preference "%s". Cowardly refuse to continue.', $name));
|
||||
Log::error(sprintf('Could not encrypt configuration value "%s": %s', $name, $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not encrypt configuration value "%s". Cowardly refuse to continue.', $name));
|
||||
}
|
||||
return $this->set($name, $encrypted);
|
||||
}
|
||||
|
@ -26,9 +26,12 @@ namespace FireflyIII\Support;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Encryption\EncryptException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
/**
|
||||
@ -53,6 +56,37 @@ class Preferences
|
||||
;
|
||||
}
|
||||
|
||||
public function getEncrypted(string $name, $default = null): ?Preference
|
||||
{
|
||||
$result = $this->get($name, $default);
|
||||
if (null === $result) {
|
||||
return null;
|
||||
}
|
||||
if ('' === $result->data) {
|
||||
Log::warning(sprintf('Empty encrypted preference found: "%s"', $name));
|
||||
return $result;
|
||||
}
|
||||
try {
|
||||
$result->data = decrypt($result->data);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setEncrypted(string $name, mixed $value): Preference
|
||||
{
|
||||
try {
|
||||
$encrypted = encrypt($value);
|
||||
} catch (EncryptException $e) {
|
||||
Log::error(sprintf('Could not encrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not encrypt preference "%s". Cowardly refuse to continue.', $name));
|
||||
}
|
||||
return $this->set($name, $encrypted);
|
||||
}
|
||||
|
||||
|
||||
public function get(string $name, null|array|bool|int|string $default = null): ?Preference
|
||||
{
|
||||
/** @var null|User $user */
|
||||
|
1004
composer.lock
generated
1004
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -31,11 +31,15 @@ return [
|
||||
],
|
||||
'notifications' => [
|
||||
'user' => [
|
||||
// normal reminders
|
||||
'bill_reminder' => ['enabled' => true, 'configurable' => true],
|
||||
'new_access_token' => ['enabled' => true, 'configurable' => true],
|
||||
'transaction_creation' => ['enabled' => true, 'configurable' => true],
|
||||
'user_login' => ['enabled' => true, 'configurable' => true],
|
||||
'rule_action_failures' => ['enabled' => true, 'configurable' => true],
|
||||
|
||||
// security reminders
|
||||
'new_access_token' => ['enabled' => true, 'configurable' => true],
|
||||
'user_login' => ['enabled' => true, 'configurable' => true],
|
||||
'login_failure' => ['enabled' => true, 'configurable' => true],
|
||||
'new_password' => ['enabled' => true, 'configurable' => false],
|
||||
'enabled_mfa' => ['enabled' => true, 'configurable' => false],
|
||||
'disabled_mfa' => ['enabled' => true, 'configurable' => false],
|
||||
|
@ -1372,6 +1372,7 @@ return [
|
||||
'optional_field_attachments' => 'Attachments',
|
||||
'optional_field_meta_data' => 'Optional meta data',
|
||||
'external_url' => 'External URL',
|
||||
'pref_notification_login_failure' => 'Login failure',
|
||||
'pref_notification_bill_reminder' => 'Reminder about expiring bills',
|
||||
'pref_notification_new_access_token' => 'Alert when a new API access token is created',
|
||||
'pref_notification_transaction_creation' => 'Alert when a transaction is created automatically',
|
||||
@ -1386,8 +1387,8 @@ return [
|
||||
'pref_notification_new_backup_codes' => 'New backup codes have been generated',
|
||||
'pref_notifications' => 'Notifications',
|
||||
'pref_notifications_help' => 'Indicate if these are notifications you would like to get. Some notifications may contain sensitive financial information.',
|
||||
'slack_webhook_url' => 'Slack Webhook URL',
|
||||
'slack_webhook_url_help' => 'If you want Firefly III to notify you using Slack, enter the webhook URL here. Otherwise leave the field blank. If you are an admin, you need to set this URL in the administration as well.',
|
||||
'pref_notifications_settings' => 'Notifications settings',
|
||||
'pref_notifications_settings_help' => 'Use these settings to configure your notification channels. Please note that notifications will be sent to ALL channels.',
|
||||
'slack_url_label' => 'Slack "incoming webhook" URL',
|
||||
'discord_url_label' => 'Discord webhook URL',
|
||||
|
||||
|
@ -308,14 +308,13 @@
|
||||
<div class="preferences-box">
|
||||
<h3>{{ 'pref_notifications'|_ }}</h3>
|
||||
<p class="text-info">{{ 'pref_notifications_help'|_ }}</p>
|
||||
{% for id, enabled in notifications %}
|
||||
{% for id, info in notifications %}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="notification_{{ id }}" {{ enabled == true ? 'checked' : '' }} value="1">
|
||||
<input {% if not info.configurable %}disabled{% endif %} type="checkbox" name="notification_{{ id }}" {{ info.enabled == true ? 'checked' : '' }} value="1">
|
||||
{{ trans('firefly.pref_notification_' ~ id) }}
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@ -325,9 +324,19 @@
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<div class="preferences-box">
|
||||
<h3>{{ 'slack_webhook_url'|_ }}</h3>
|
||||
<p class="text-info">{{ 'slack_webhook_url_help'|_ }}</p>
|
||||
{{ ExpandedForm.text('slackUrl',slackUrl,{'label' : 'slack_url_label'|_}) }}
|
||||
<h3>{{ 'pref_notifications_settings'|_ }}</h3>
|
||||
<p class="text-info">{{ 'pref_notifications_settings_help'|_ }}</p>
|
||||
{{ ExpandedForm.text('slackUrl',slackUrl,{'label' : 'slack_url_label'|_, helpText: 'slack_discord_double'|_}) }}
|
||||
|
||||
{{ ExpandedForm.text('pushover_app_token', pushoverAppToken, {}) }}
|
||||
{{ ExpandedForm.text('pushover_user_token', pushoverUserToken, {}) }}
|
||||
|
||||
{{ ExpandedForm.text('ntfy_server', ntfyServer, {}) }}
|
||||
{{ ExpandedForm.text('ntfy_topic', ntfyTopic, {}) }}
|
||||
{{ ExpandedForm.checkbox('ntfy_auth','1', ntfyAuth, {}) }}
|
||||
{{ ExpandedForm.text('ntfy_user', ntfyUser, {}) }}
|
||||
{{ ExpandedForm.passwordWithValue('ntfy_pass', ntfyPass, {}) }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user