mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Various code cleanup and sorting.
This commit is contained in:
		| @@ -23,6 +23,7 @@ declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\User; | ||||
| 
 | ||||
| use Exception; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\BudgetLimit; | ||||
| use FireflyIII\Models\GroupMembership; | ||||
| @@ -34,6 +35,7 @@ use Illuminate\Contracts\Auth\Authenticatable; | ||||
| use Illuminate\Database\QueryException; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Str; | ||||
| use Override; | ||||
| 
 | ||||
| /** | ||||
|  * Class UserRepository. | ||||
| @@ -44,17 +46,17 @@ class UserRepository implements UserRepositoryInterface | ||||
|      * This updates the users email address and records some things so it can be confirmed or undone later. | ||||
|      * The user is blocked until the change is confirmed. | ||||
|      * | ||||
|      * @throws \Exception | ||||
|      * @throws Exception | ||||
|      * | ||||
|      * @see updateEmail | ||||
|      */ | ||||
|     public function changeEmail(User $user, string $newEmail): bool | ||||
|     { | ||||
|         $oldEmail           = $user->email; | ||||
|         $oldEmail = $user->email; | ||||
| 
 | ||||
|         // save old email as pref
 | ||||
|         app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail); | ||||
|         app('preferences')->setForUser($user, 'previous_email_'.date('Y-m-d-H-i-s'), $oldEmail); | ||||
|         app('preferences')->setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail); | ||||
| 
 | ||||
|         // set undo and confirm token:
 | ||||
|         app('preferences')->setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16))); | ||||
| @@ -99,7 +101,7 @@ class UserRepository implements UserRepositoryInterface | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @throws \Exception | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     public function destroy(User $user): bool | ||||
|     { | ||||
| @@ -171,7 +173,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)); | ||||
|         } | ||||
| @@ -197,7 +199,7 @@ class UserRepository implements UserRepositoryInterface | ||||
|      */ | ||||
|     public function getUserData(User $user): array | ||||
|     { | ||||
|         $return                        = []; | ||||
|         $return = []; | ||||
| 
 | ||||
|         // two factor:
 | ||||
|         $return['has_2fa']             = null !== $user->mfa_secret; | ||||
| @@ -213,12 +215,11 @@ class UserRepository implements UserRepositoryInterface | ||||
|         $return['categories']          = $user->categories()->count(); | ||||
|         $return['budgets']             = $user->budgets()->count(); | ||||
|         $return['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') | ||||
|         ; | ||||
|                                                     ->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'); | ||||
|         $return['rule_groups']         = $user->ruleGroups()->count(); | ||||
|         $return['rules']               = $user->rules()->count(); | ||||
|         $return['tags']                = $user->tags()->count(); | ||||
| @@ -226,7 +227,7 @@ class UserRepository implements UserRepositoryInterface | ||||
|         return $return; | ||||
|     } | ||||
| 
 | ||||
|     public function hasRole(null|Authenticatable|User $user, string $role): bool | ||||
|     public function hasRole(null | Authenticatable | User $user, string $role): bool | ||||
|     { | ||||
|         if (null === $user) { | ||||
|             return false; | ||||
| @@ -243,7 +244,7 @@ class UserRepository implements UserRepositoryInterface | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     #[\Override]
 | ||||
|     #[Override]
 | ||||
|     public function getUserGroups(User $user): Collection | ||||
|     { | ||||
|         $memberships = $user->groupMemberships()->get(); | ||||
| @@ -255,7 +256,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; | ||||
|                 } | ||||
| @@ -267,14 +268,14 @@ class UserRepository implements UserRepositoryInterface | ||||
|         return $collection; | ||||
|     } | ||||
| 
 | ||||
|     public function inviteUser(null|Authenticatable|User $user, string $email): InvitedUser | ||||
|     public function inviteUser(null | Authenticatable | User $user, string $email): InvitedUser | ||||
|     { | ||||
|         if (!$user instanceof User) { | ||||
|             throw new FireflyException('User is not a User object.'); | ||||
|         } | ||||
|         $now                  = today(config('app.timezone')); | ||||
|         $now = today(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; | ||||
| @@ -385,11 +386,11 @@ class UserRepository implements UserRepositoryInterface | ||||
|         if ('' === $newEmail) { | ||||
|             return true; | ||||
|         } | ||||
|         $oldEmail    = $user->email; | ||||
|         $oldEmail = $user->email; | ||||
| 
 | ||||
|         // save old email as pref
 | ||||
|         app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail); | ||||
|         app('preferences')->setForUser($user, 'admin_previous_email_'.date('Y-m-d-H-i-s'), $oldEmail); | ||||
|         app('preferences')->setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail); | ||||
| 
 | ||||
|         $user->email = $newEmail; | ||||
|         $user->save(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user