Autoformat lol

This commit is contained in:
James Cole
2026-01-23 15:09:50 +01:00
parent ae1347c550
commit 8f15a32bd6
1071 changed files with 21111 additions and 21687 deletions

View File

@@ -23,8 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use FireflyIII\Support\Facades\Preferences;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@@ -33,10 +31,12 @@ use FireflyIII\Models\GroupMembership;
use FireflyIII\Models\InvitedUser;
use FireflyIII\Models\Role;
use FireflyIII\Models\UserGroup;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Override;
use SensitiveParameter;
@@ -56,19 +56,19 @@ class UserRepository implements UserRepositoryInterface
*/
public function changeEmail(User $user, string $newEmail): bool
{
$oldEmail = $user->email;
$oldEmail = $user->email;
// save old email as pref
Preferences::setForUser($user, 'previous_email_latest', $oldEmail);
Preferences::setForUser($user, 'previous_email_'.Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
Preferences::setForUser($user, 'previous_email_' . Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token:
Preferences::setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16)));
Preferences::setForUser($user, 'email_change_confirm_token', bin2hex(random_bytes(16)));
// update user
$user->email = $newEmail;
$user->blocked = true;
$user->email = $newEmail;
$user->blocked = true;
$user->blocked_code = 'email_changed';
$user->save();
@@ -86,7 +86,7 @@ class UserRepository implements UserRepositoryInterface
public function changeStatus(User $user, bool $isBlocked, string $code): bool
{
// change blocked status and code:
$user->blocked = $isBlocked;
$user->blocked = $isBlocked;
$user->blocked_code = $code;
$user->save();
@@ -95,7 +95,7 @@ class UserRepository implements UserRepositoryInterface
public function createRole(string $name, string $displayName, string $description): Role
{
return Role::create(['name' => $name, 'display_name' => $displayName, 'description' => $description]);
return Role::create(['name' => $name, 'display_name' => $displayName, 'description' => $description]);
}
public function deleteInvite(InvitedUser $invite): void
@@ -142,7 +142,7 @@ class UserRepository implements UserRepositoryInterface
return User::orderBy('id', 'DESC')->get(['users.*']);
}
public function findByEmail(string $email): ?User
public function findByEmail(string $email): null|User
{
return User::where('email', $email)->first();
}
@@ -150,7 +150,7 @@ class UserRepository implements UserRepositoryInterface
/**
* Returns the first user in the DB. Generally only works when there is just one.
*/
public function first(): ?User
public function first(): null|User
{
return User::orderBy('id', 'ASC')->first();
}
@@ -160,13 +160,12 @@ class UserRepository implements UserRepositoryInterface
return InvitedUser::with('user')->get();
}
public function getRoleByUser(User $user): ?string
public function getRoleByUser(User $user): null|string
{
/** @var null|Role $role */
$role = $user->roles()->first();
return $role?->name;
}
/**
@@ -175,7 +174,7 @@ class UserRepository implements UserRepositoryInterface
public function getRolesInGroup(User $user, int $groupId): array
{
/** @var null|UserGroup $group */
$group = UserGroup::find($groupId);
$group = UserGroup::find($groupId);
if (null === $group) {
throw new FireflyException(sprintf('Could not find group #%d', $groupId));
}
@@ -184,14 +183,14 @@ class UserRepository implements UserRepositoryInterface
/** @var GroupMembership $membership */
foreach ($memberships as $membership) {
$role = $membership->userRole;
$role = $membership->userRole;
$roles[] = $role->title;
}
return $roles;
}
public function find(int $userId): ?User
public function find(int $userId): null|User
{
return User::find($userId);
}
@@ -201,12 +200,29 @@ class UserRepository implements UserRepositoryInterface
*/
public function getUserData(User $user): array
{
return ['has_2fa' => null !== $user->mfa_secret, 'is_admin' => $this->hasRole($user, 'owner'), 'blocked' => 1 === (int) $user->blocked, 'blocked_code' => $user->blocked_code, 'accounts' => $user->accounts()->count(), 'journals' => $user->transactionJournals()->count(), 'transactions' => $user->transactions()->count(), 'attachments' => $user->attachments()->count(), 'attachments_size' => $user->attachments()->sum('size'), 'bills' => $user->bills()->count(), 'categories' => $user->categories()->count(), 'budgets' => $user->budgets()->count(), 'budgets_with_limits' => BudgetLimit::distinct()
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->where('amount', '>', 0)
->whereNull('budgets.deleted_at')
->where('budgets.user_id', $user->id)
->count('budget_limits.budget_id'), 'rule_groups' => $user->ruleGroups()->count(), 'rules' => $user->rules()->count(), 'tags' => $user->tags()->count()];
return [
'has_2fa' => null !== $user->mfa_secret,
'is_admin' => $this->hasRole($user, 'owner'),
'blocked' => 1 === (int) $user->blocked,
'blocked_code' => $user->blocked_code,
'accounts' => $user->accounts()->count(),
'journals' => $user->transactionJournals()->count(),
'transactions' => $user->transactions()->count(),
'attachments' => $user->attachments()->count(),
'attachments_size' => $user->attachments()->sum('size'),
'bills' => $user->bills()->count(),
'categories' => $user->categories()->count(),
'budgets' => $user->budgets()->count(),
'budgets_with_limits' => BudgetLimit::distinct()
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->where('amount', '>', 0)
->whereNull('budgets.deleted_at')
->where('budgets.user_id', $user->id)
->count('budget_limits.budget_id'),
'rule_groups' => $user->ruleGroups()->count(),
'rules' => $user->rules()->count(),
'tags' => $user->tags()->count()
];
}
public function hasRole(Authenticatable|User|null $user, string $role): bool
@@ -238,7 +254,7 @@ class UserRepository implements UserRepositoryInterface
/** @var null|UserGroup $group */
$group = $membership->userGroup()->first();
if (null !== $group) {
$groupId = $group->id;
$groupId = $group->id;
if (in_array($groupId, array_keys($set), true)) {
continue;
}
@@ -255,15 +271,15 @@ class UserRepository implements UserRepositoryInterface
if (!$user instanceof User) {
throw new FireflyException('User is not a User object.');
}
$now = now(config('app.timezone'));
$now = now(config('app.timezone'));
$now->addDays(2);
$invitee = new InvitedUser();
$invitee = new InvitedUser();
$invitee->user()->associate($user);
$invitee->invite_code = Str::random(64);
$invitee->email = $email;
$invitee->redeemed = false;
$invitee->expires = $now;
$invitee->expires_tz = $now->format('e');
$invitee->email = $email;
$invitee->redeemed = false;
$invitee->expires = $now;
$invitee->expires_tz = $now->format('e');
$invitee->save();
return $invitee;
@@ -281,7 +297,7 @@ class UserRepository implements UserRepositoryInterface
/**
* Set MFA code.
*/
public function setMFACode(User $user, ?string $code): void
public function setMFACode(User $user, null|string $code): void
{
$user->mfa_secret = $code;
$user->save();
@@ -289,14 +305,12 @@ class UserRepository implements UserRepositoryInterface
public function store(array $data): User
{
$user = User::create(
[
'blocked' => $data['blocked'] ?? false,
'blocked_code' => $data['blocked_code'] ?? null,
'email' => $data['email'],
'password' => Str::random(24),
]
);
$user = User::create([
'blocked' => $data['blocked'] ?? false,
'blocked_code' => $data['blocked_code'] ?? null,
'email' => $data['email'],
'password' => Str::random(24)
]);
$role = $data['role'] ?? '';
if ('' !== $role) {
$this->attachRole($user, $role);
@@ -326,7 +340,7 @@ class UserRepository implements UserRepositoryInterface
public function unblockUser(User $user): void
{
$user->blocked = false;
$user->blocked = false;
$user->blocked_code = '';
$user->save();
}
@@ -366,11 +380,11 @@ class UserRepository implements UserRepositoryInterface
if ('' === $newEmail) {
return true;
}
$oldEmail = $user->email;
$oldEmail = $user->email;
// save old email as pref
Preferences::setForUser($user, 'admin_previous_email_latest', $oldEmail);
Preferences::setForUser($user, 'admin_previous_email_'.Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
Preferences::setForUser($user, 'admin_previous_email_' . Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
$user->email = $newEmail;
$user->save();
@@ -390,7 +404,7 @@ class UserRepository implements UserRepositoryInterface
$user->roles()->detach($roleObj->id);
}
public function getRole(string $role): ?Role
public function getRole(string $role): null|Role
{
return Role::where('name', $role)->first();
}
@@ -398,7 +412,10 @@ class UserRepository implements UserRepositoryInterface
public function validateInviteCode(string $code): bool
{
$now = today(config('app.timezone'));
$invitee = InvitedUser::where('invite_code', $code)->where('expires', '>', $now->format('Y-m-d H:i:s'))->where('redeemed', 0)->first();
$invitee = InvitedUser::where('invite_code', $code)
->where('expires', '>', $now->format('Y-m-d H:i:s'))
->where('redeemed', 0)
->first();
return null !== $invitee;
}