mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-11 09:29:34 +00:00
Auto commit for release 'develop' on 2024-04-02
This commit is contained in:
@@ -54,9 +54,11 @@ class UpdateController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function useUserGroup(UserGroup $userGroup): JsonResponse {
|
||||
public function useUserGroup(UserGroup $userGroup): JsonResponse
|
||||
{
|
||||
// group validation is already in place, so can just update the user.
|
||||
$this->repository->useUserGroup($userGroup);
|
||||
|
||||
return response()->json([], 204);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class CorrectDatabase extends Command
|
||||
// new!
|
||||
'firefly-iii:unify-group-accounts',
|
||||
'firefly-iii:trigger-credit-recalculation',
|
||||
'firefly-iii:migrate-preferences'
|
||||
'firefly-iii:migrate-preferences',
|
||||
];
|
||||
foreach ($commands as $command) {
|
||||
$this->friendlyLine(sprintf('Now executing command "%s"', $command));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* MigratePreferences.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -33,7 +35,7 @@ class MigratePreferences extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:migrate-preferences';
|
||||
protected $signature = 'firefly-iii:migrate-preferences';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -49,26 +51,26 @@ class MigratePreferences extends Command
|
||||
{
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
$users = User::get();
|
||||
|
||||
/** @var User $user */
|
||||
foreach($users as $user) {
|
||||
foreach ($users as $user) {
|
||||
$count = 0;
|
||||
foreach($items as $item) {
|
||||
foreach ($items as $item) {
|
||||
$preference = Preference::where('name', $item)->where('user_id', $user->id)->first();
|
||||
if(null === $preference) {
|
||||
if (null === $preference) {
|
||||
continue;
|
||||
}
|
||||
if(null !== $preference->user_group_id) {
|
||||
if (null !== $preference->user_group_id) {
|
||||
$preference->user_group_id = $user->user_group_id;
|
||||
$preference->save();
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
if($count > 0) {
|
||||
if ($count > 0) {
|
||||
$this->info(sprintf('Migrated %d preference(s) for user #%d ("%s").', $count, $user->id, $user->email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ class CreateGroupMemberships extends Command
|
||||
use ShowsFriendlyMessages;
|
||||
|
||||
public const string CONFIG_NAME = '560_create_group_memberships';
|
||||
protected $description = 'Update group memberships';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
protected $description = 'Update group memberships';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -78,19 +78,20 @@ class CreateGroupMemberships extends Command
|
||||
public static function createGroupMembership(User $user): void
|
||||
{
|
||||
// check if membership exists
|
||||
$userGroup = UserGroup::where('title', $user->email)->first();
|
||||
$userGroup = UserGroup::where('title', $user->email)->first();
|
||||
if (null === $userGroup) {
|
||||
$userGroup = UserGroup::create(['title' => $user->email, 'default_administration' => true]);
|
||||
}
|
||||
|
||||
$userRole = UserRole::where('title', UserRoleEnum::OWNER->value)->first();
|
||||
$userRole = UserRole::where('title', UserRoleEnum::OWNER->value)->first();
|
||||
|
||||
if (null === $userRole) {
|
||||
throw new FireflyException('Firefly III could not find a user role. Please make sure all migrations have run.');
|
||||
}
|
||||
$membership = GroupMembership::where('user_id', $user->id)
|
||||
->where('user_group_id', $userGroup->id)
|
||||
->where('user_role_id', $userRole->id)->first();
|
||||
->where('user_group_id', $userGroup->id)
|
||||
->where('user_role_id', $userRole->id)->first()
|
||||
;
|
||||
if (null === $membership) {
|
||||
GroupMembership::create(
|
||||
[
|
||||
@@ -105,5 +106,4 @@ class CreateGroupMemberships extends Command
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -94,23 +94,23 @@ 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;
|
||||
$slackUrl = app('preferences')->get('slack_webhook_url', '')->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');
|
||||
|
||||
// notification preferences (single value for each):
|
||||
$notifications = [];
|
||||
$notifications = [];
|
||||
foreach (config('firefly.available_notifications') as $notification) {
|
||||
$notifications[$notification] = app('preferences')->get(sprintf('notification_%s', $notification), true)->data;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class PreferencesController extends Controller
|
||||
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)) {
|
||||
@@ -164,7 +164,7 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// extract notifications:
|
||||
$all = $request->all();
|
||||
$all = $request->all();
|
||||
foreach (config('firefly.available_notifications') as $option) {
|
||||
$key = sprintf('notification_%s', $option);
|
||||
if (array_key_exists($key, $all)) {
|
||||
@@ -194,8 +194,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);
|
||||
@@ -204,15 +204,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);
|
||||
}
|
||||
@@ -229,8 +229,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),
|
||||
@@ -247,7 +247,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @method static Builder|Preference whereUpdatedAt($value)
|
||||
* @method static Builder|Preference whereUserId($value)
|
||||
*
|
||||
* @property mixed $user_group_id
|
||||
* @property mixed $user_group_id
|
||||
*
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ class Preference extends Model
|
||||
use ReturnsIntegerUserIdTrait;
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'data' => 'array',
|
||||
@@ -81,15 +81,16 @@ class Preference extends Model
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
// some preferences do not have an administration ID.
|
||||
// some need it, to make sure the correct one is selected.
|
||||
$userGroupId = (int)$user->user_group_id;
|
||||
$userGroupId = $userGroupId === 0 ? null : $userGroupId;
|
||||
/** @var Preference|null $preference */
|
||||
$preference = null;
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
$userGroupId = 0 === $userGroupId ? null : $userGroupId;
|
||||
|
||||
/** @var null|Preference $preference */
|
||||
$preference = null;
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
if (null !== $userGroupId && in_array($value, $items, true)) {
|
||||
// find a preference with a specific user_group_id
|
||||
$preference = $user->preferences()->where('user_group_id', $userGroupId)->where('name', $value)->first();
|
||||
@@ -106,7 +107,7 @@ class Preference extends Model
|
||||
if (null !== $preference) {
|
||||
return $preference;
|
||||
}
|
||||
$default = config('firefly.default_preferences');
|
||||
$default = config('firefly.default_preferences');
|
||||
if (array_key_exists($value, $default)) {
|
||||
$preference = new self();
|
||||
$preference->name = $value;
|
||||
|
||||
@@ -289,7 +289,8 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
return $roles;
|
||||
}
|
||||
|
||||
#[\Override] public function useUserGroup(UserGroup $userGroup): void
|
||||
#[\Override]
|
||||
public function useUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->user->user_group_id = $userGroup->id;
|
||||
$this->user->save();
|
||||
|
||||
@@ -24,12 +24,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Repositories\UserGroup\UserGroupRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use FireflyIII\Validation\AccountValidator;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
/**
|
||||
@@ -38,8 +35,10 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
||||
class IsDefaultUserGroupName implements ValidationRule
|
||||
{
|
||||
private UserGroup $userGroup;
|
||||
public function __construct(UserGroup $userGroup) {
|
||||
$this->userGroup =$userGroup;
|
||||
|
||||
public function __construct(UserGroup $userGroup)
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,12 +50,13 @@ class IsDefaultUserGroupName implements ValidationRule
|
||||
|
||||
// are you owner of this group and the name is the same? fail.
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var UserRepositoryInterface $userRepos */
|
||||
$userRepos = app(UserRepositoryInterface::class);
|
||||
|
||||
$roles = $userRepos->getRolesInGroup($user, $this->userGroup->id);
|
||||
if($this->userGroup->title === $user->email && in_array('owner', $roles, true)) {
|
||||
$roles = $userRepos->getRolesInGroup($user, $this->userGroup->id);
|
||||
if ($this->userGroup->title === $user->email && in_array('owner', $roles, true)) {
|
||||
$fail('validation.administration_owner_rename')->translate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,15 @@ class Preferences
|
||||
}
|
||||
|
||||
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();
|
||||
->where(function (Builder $q) use ($user): void {
|
||||
$q->whereNull('user_group_id');
|
||||
$q->orWhere('user_group_id', $user->user_group_id);
|
||||
})
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function get(string $name, null | array | bool | int | string $default = null): ?Preference
|
||||
public function get(string $name, null|array|bool|int|string $default = null): ?Preference
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
@@ -65,11 +66,11 @@ class Preferences
|
||||
return $this->getForUser($user, $name, $default);
|
||||
}
|
||||
|
||||
public function getForUser(User $user, string $name, null | array | bool | int | string $default = null): ?Preference
|
||||
public function getForUser(User $user, string $name, null|array|bool|int|string $default = null): ?Preference
|
||||
{
|
||||
// don't care about user group ID, except for some specific preferences.
|
||||
$userGroupId = $this->getUserGroupId($user, $name);
|
||||
$preference = Preference::where('user_group_id', $userGroupId)->where('user_id', $user->id)->where('name', $name)->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']);
|
||||
$preference = Preference::where('user_group_id', $userGroupId)->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();
|
||||
@@ -106,14 +107,14 @@ class Preferences
|
||||
Cache::put($key, '', 5);
|
||||
}
|
||||
|
||||
public function setForUser(User $user, string $name, null | array | bool | int | string $value): Preference
|
||||
public function setForUser(User $user, string $name, null|array|bool|int|string $value): Preference
|
||||
{
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
$groupId = $this->getUserGroupId($user, $name);
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
$groupId = $this->getUserGroupId($user, $name);
|
||||
Cache::forget($fullName);
|
||||
|
||||
/** @var null|Preference $pref */
|
||||
$pref = Preference::where('user_group_id', $groupId)->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();
|
||||
@@ -138,7 +139,7 @@ class Preferences
|
||||
|
||||
public function beginsWith(User $user, string $search): Collection
|
||||
{
|
||||
return Preference::where('user_id', $user->id)->where('name', 'LIKE', $search . '%')->get();
|
||||
return Preference::where('user_id', $user->id)->where('name', 'LIKE', $search.'%')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,14 +153,14 @@ class Preferences
|
||||
public function getArrayForUser(User $user, array $list): array
|
||||
{
|
||||
$result = [];
|
||||
$preferences = Preference
|
||||
::where('user_id', $user->id)
|
||||
->where(function (Builder $q) use ($user) {
|
||||
$preferences = Preference::where('user_id', $user->id)
|
||||
->where(function (Builder $q) use ($user): void {
|
||||
$q->whereNull('user_group_id');
|
||||
$q->orWhere('user_group_id', $user->user_group_id);
|
||||
})
|
||||
->whereIn('name', $list)
|
||||
->get(['id', 'name', 'data']);
|
||||
->get(['id', 'name', 'data'])
|
||||
;
|
||||
|
||||
/** @var Preference $preference */
|
||||
foreach ($preferences as $preference) {
|
||||
@@ -174,7 +175,7 @@ class Preferences
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFresh(string $name, null | array | bool | int | string $default = null): ?Preference
|
||||
public function getFresh(string $name, null|array|bool|int|string $default = null): ?Preference
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
@@ -212,7 +213,7 @@ class Preferences
|
||||
Session::forget('first');
|
||||
}
|
||||
|
||||
public function set(string $name, null | array | bool | int | string $value): Preference
|
||||
public function set(string $name, null|array|bool|int|string $value): Preference
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
@@ -235,6 +236,7 @@ class Preferences
|
||||
if (in_array($preferenceName, $items, true)) {
|
||||
$groupId = (int)$user->user_group_id;
|
||||
}
|
||||
|
||||
return $groupId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ class PreferenceTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(Preference $preference): array
|
||||
{
|
||||
$userGroupId = $preference->user_group_id === 0 ? null : $preference->user_group_id;
|
||||
$userGroupId = 0 === $preference->user_group_id ? null : $preference->user_group_id;
|
||||
|
||||
return [
|
||||
'id' => $preference->id,
|
||||
'created_at' => $preference->created_at->toAtomString(),
|
||||
|
||||
Reference in New Issue
Block a user