Skip to content

Firefly III: a personal finances manager

Preferences can be administration specific. Not yet really working.

James Cole75ea03563098
diff --git a/app/Console/Commands/Correction/MigratePreferences.php b/app/Console/Commands/Correction/MigratePreferences.php
index 0999f2ff5d..a9f208d402 100644
--- a/app/Console/Commands/Correction/MigratePreferences.php
+++ b/app/Console/Commands/Correction/MigratePreferences.php
@@ -47,7 +47,7 @@ class MigratePreferences extends Command
*/
public function handle(): int
{
- $items = ['frontpageAccounts'];
+ $items = config('firefly.admin_specific_prefs');
$users = User::get();
/** @var User $user */
foreach($users as $user) {
diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php
index 4b7c326a79..e1795e64b7 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Preference;
use FireflyIII\User;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
/**
@@ -40,7 +41,12 @@ class Preferences
return new Collection();
}
- return Preference::where('user_id', $user->id)->get();
+ return Preference::where('user_id', $user->id)
+ ->where(function(Builder $q) use($user) {
+ $q->whereNull('user_group_id');
+ $q->orWhere('user_group_id', $user->user_group_id);
+ })
+ ->get();
}
/**
@@ -74,7 +80,12 @@ class Preferences
if ('currencyPreference' === $name) {
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
}
- $preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']);
+ $preference = Preference::
+ where(function(Builder $q) use($user) {
+ $q->whereNull('user_group_id');
+ $q->orWhere('user_group_id', $user->user_group_id);
+ })
+ ->where('user_id', $user->id)->where('name', $name)->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']);
if (null !== $preference && null === $preference->data) {
$preference->delete();
$preference = null;
@@ -132,8 +143,14 @@ class Preferences
$fullName = sprintf('preference%s%s', $user->id, $name);
\Cache::forget($fullName);
+ $groupId = null;
+ $items = config('firefly.admin_specific_prefs');
+ if(in_array($name, $items, true)) {
+ $groupId = (int)$user->user_group_id;
+ }
+
/** @var null|Preference $pref */
- $pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);
+ $pref = Preference::where('user_group_id', $groupId)->where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);
if (null !== $pref && null === $value) {
$pref->delete();
@@ -146,6 +163,7 @@ class Preferences
if (null === $pref) {
$pref = new Preference();
$pref->user_id = (int)$user->id;
+ $pref->user_group_id = $groupId;
$pref->name = $name;
}
$pref->data = $value;
@@ -275,6 +293,6 @@ class Preferences
return $pref;
}
- return $this->setForUser(auth()->user(), $name, $value);
+ return $this->setForUser($user, $name, $value);
}
}
diff --git a/config/firefly.php b/config/firefly.php
index 8a785c0a09..0d541533df 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -215,6 +215,9 @@ return [
'zoom_level' => env('MAP_DEFAULT_ZOOM', '6'),
],
+ // administration specific preferences
+ 'admin_specific_prefs' => ['frontpageAccounts'],
+
// default user-related values
'darkMode' => 'browser',
'list_length' => 10, // to be removed if v1 is cancelled.