| 
									
										
										
										
											2016-01-08 16:02:15 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2018-05-11 10:08:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * User.php | 
					
						
							| 
									
										
										
										
											2020-02-16 14:00:57 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-11 10:08:34 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-08 16:02:15 +01:00
										 |  |  | namespace FireflyIII; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  | use Eloquent; | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  | use FireflyIII\Enums\UserRoleEnum; | 
					
						
							| 
									
										
										
										
											2016-11-22 21:21:11 +01:00
										 |  |  | use FireflyIII\Events\RequestedNewPassword; | 
					
						
							| 
									
										
										
										
											2023-01-29 07:00:26 +01:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2018-06-06 21:23:00 +02:00
										 |  |  | use FireflyIII\Models\Account; | 
					
						
							|  |  |  | use FireflyIII\Models\Attachment; | 
					
						
							|  |  |  | use FireflyIII\Models\AvailableBudget; | 
					
						
							|  |  |  | use FireflyIII\Models\Bill; | 
					
						
							|  |  |  | use FireflyIII\Models\Budget; | 
					
						
							|  |  |  | use FireflyIII\Models\Category; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:47:59 +02:00
										 |  |  | use FireflyIII\Models\CurrencyExchangeRate; | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | use FireflyIII\Models\GroupMembership; | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  | use FireflyIII\Models\ObjectGroup; | 
					
						
							| 
									
										
										
										
											2018-06-06 21:23:00 +02:00
										 |  |  | use FireflyIII\Models\PiggyBank; | 
					
						
							|  |  |  | use FireflyIII\Models\Preference; | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  | use FireflyIII\Models\Recurrence; | 
					
						
							| 
									
										
										
										
											2018-06-06 21:23:00 +02:00
										 |  |  | use FireflyIII\Models\Role; | 
					
						
							|  |  |  | use FireflyIII\Models\Rule; | 
					
						
							|  |  |  | use FireflyIII\Models\RuleGroup; | 
					
						
							|  |  |  | use FireflyIII\Models\Tag; | 
					
						
							|  |  |  | use FireflyIII\Models\Transaction; | 
					
						
							| 
									
										
										
										
											2023-10-22 06:56:46 +02:00
										 |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							| 
									
										
										
										
											2019-01-28 20:00:40 +01:00
										 |  |  | use FireflyIII\Models\TransactionGroup; | 
					
						
							| 
									
										
										
										
											2018-06-06 21:23:00 +02:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  | use FireflyIII\Models\UserGroup; | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  | use FireflyIII\Models\UserRole; | 
					
						
							| 
									
										
										
										
											2020-11-29 18:35:49 +01:00
										 |  |  | use FireflyIII\Models\Webhook; | 
					
						
							| 
									
										
										
										
											2022-09-24 12:14:27 +02:00
										 |  |  | use FireflyIII\Notifications\Admin\TestNotification; | 
					
						
							| 
									
										
										
										
											2022-10-01 12:21:42 +02:00
										 |  |  | use FireflyIII\Notifications\Admin\UserInvitation; | 
					
						
							| 
									
										
										
										
											2022-09-24 12:14:27 +02:00
										 |  |  | use FireflyIII\Notifications\Admin\UserRegistration; | 
					
						
							|  |  |  | use FireflyIII\Notifications\Admin\VersionCheckResult; | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Builder; | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsTo; | 
					
						
							| 
									
										
										
										
											2016-02-12 05:49:53 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsToMany; | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\HasMany; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Relations\HasManyThrough; | 
					
						
							| 
									
										
										
										
											2016-01-08 16:02:15 +01:00
										 |  |  | use Illuminate\Foundation\Auth\User as Authenticatable; | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  | use Illuminate\Notifications\DatabaseNotification; | 
					
						
							|  |  |  | use Illuminate\Notifications\DatabaseNotificationCollection; | 
					
						
							| 
									
										
										
										
											2016-09-16 06:19:40 +02:00
										 |  |  | use Illuminate\Notifications\Notifiable; | 
					
						
							| 
									
										
										
										
											2022-09-18 15:48:28 +02:00
										 |  |  | use Illuminate\Notifications\Notification; | 
					
						
							| 
									
										
										
										
											2018-07-22 18:50:27 +02:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2022-09-18 15:48:28 +02:00
										 |  |  | use Illuminate\Support\Str; | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  | use Laravel\Passport\Client; | 
					
						
							| 
									
										
										
										
											2018-02-04 08:14:03 +01:00
										 |  |  | use Laravel\Passport\HasApiTokens; | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  | use Laravel\Passport\Token; | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
					
						
							| 
									
										
										
										
											2015-02-06 05:04:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-09 08:20:55 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class User. | 
					
						
							| 
									
										
										
										
											2018-06-06 21:23:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-12-22 20:12:38 +01:00
										 |  |  |  * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * @property int|string                                                      $id | 
					
						
							|  |  |  |  * @property string                                                          $email | 
					
						
							|  |  |  |  * @property bool                                                            $isAdmin | 
					
						
							|  |  |  |  * @property bool                                                            $has2FA | 
					
						
							|  |  |  |  * @property array                                                           $prefs | 
					
						
							|  |  |  |  * @property string                                                          $password | 
					
						
							|  |  |  |  * @property string                                                          $mfa_secret | 
					
						
							|  |  |  |  * @property Collection                                                      $roles | 
					
						
							|  |  |  |  * @property string                                                          $blocked_code | 
					
						
							|  |  |  |  * @property bool                                                            $blocked | 
					
						
							|  |  |  |  * @property null|Carbon                                                     $created_at | 
					
						
							|  |  |  |  * @property null|Carbon                                                     $updated_at | 
					
						
							|  |  |  |  * @property null|string                                                     $remember_token | 
					
						
							|  |  |  |  * @property null|string                                                     $reset | 
					
						
							|  |  |  |  * @property Account[]|\Illuminate\Database\Eloquent\Collection              $accounts | 
					
						
							|  |  |  |  * @property Attachment[]|\Illuminate\Database\Eloquent\Collection           $attachments | 
					
						
							|  |  |  |  * @property AvailableBudget[]|\Illuminate\Database\Eloquent\Collection      $availableBudgets | 
					
						
							|  |  |  |  * @property Bill[]|\Illuminate\Database\Eloquent\Collection                 $bills | 
					
						
							|  |  |  |  * @property Budget[]|\Illuminate\Database\Eloquent\Collection               $budgets | 
					
						
							|  |  |  |  * @property Category[]|\Illuminate\Database\Eloquent\Collection             $categories | 
					
						
							|  |  |  |  * @property Client[]|\Illuminate\Database\Eloquent\Collection               $clients | 
					
						
							|  |  |  |  * @property CurrencyExchangeRate[]|\Illuminate\Database\Eloquent\Collection $currencyExchangeRates | 
					
						
							|  |  |  |  * @property DatabaseNotification[]|DatabaseNotificationCollection           $notifications | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|PiggyBank[]            $piggyBanks | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Preference[]           $preferences | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Recurrence[]           $recurrences | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|RuleGroup[]            $ruleGroups | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Rule[]                 $rules | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Tag[]                  $tags | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Token[]                $tokens | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|TransactionGroup[]     $transactionGroups | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|TransactionJournal[]   $transactionJournals | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Transaction[]          $transactions | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-08-17 10:46:32 +02:00
										 |  |  |  * @method static Builder|User newModelQuery() | 
					
						
							|  |  |  |  * @method static Builder|User newQuery() | 
					
						
							|  |  |  |  * @method static Builder|User query() | 
					
						
							|  |  |  |  * @method static Builder|User whereBlocked($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereBlockedCode($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereCreatedAt($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereEmail($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereId($value) | 
					
						
							|  |  |  |  * @method static Builder|User wherePassword($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereRememberToken($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereReset($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereUpdatedAt($value) | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property null|string $objectguid | 
					
						
							|  |  |  |  * @property null|int    $accounts_count | 
					
						
							|  |  |  |  * @property null|int    $attachments_count | 
					
						
							|  |  |  |  * @property null|int    $available_budgets_count | 
					
						
							|  |  |  |  * @property null|int    $bills_count | 
					
						
							|  |  |  |  * @property null|int    $budgets_count | 
					
						
							|  |  |  |  * @property null|int    $categories_count | 
					
						
							|  |  |  |  * @property null|int    $clients_count | 
					
						
							|  |  |  |  * @property null|int    $currency_exchange_rates_count | 
					
						
							|  |  |  |  * @property null|int    $notifications_count | 
					
						
							|  |  |  |  * @property null|int    $piggy_banks_count | 
					
						
							|  |  |  |  * @property null|int    $preferences_count | 
					
						
							|  |  |  |  * @property null|int    $recurrences_count | 
					
						
							|  |  |  |  * @property null|int    $roles_count | 
					
						
							|  |  |  |  * @property null|int    $rule_groups_count | 
					
						
							|  |  |  |  * @property null|int    $rules_count | 
					
						
							|  |  |  |  * @property null|int    $tags_count | 
					
						
							|  |  |  |  * @property null|int    $tokens_count | 
					
						
							|  |  |  |  * @property null|int    $transaction_groups_count | 
					
						
							|  |  |  |  * @property null|int    $transaction_journals_count | 
					
						
							|  |  |  |  * @property null|int    $transactions_count | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-05-24 08:22:41 +02:00
										 |  |  |  * @method static Builder|User whereMfaSecret($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereObjectguid($value) | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property null|string $provider | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-05-24 08:22:41 +02:00
										 |  |  |  * @method static Builder|User whereProvider($value) | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|ObjectGroup[] $objectGroups | 
					
						
							|  |  |  |  * @property null|int                                               $object_groups_count | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection|Webhook[]     $webhooks | 
					
						
							|  |  |  |  * @property null|int                                               $webhooks_count | 
					
						
							|  |  |  |  * @property null|string                                            $two_factor_secret | 
					
						
							|  |  |  |  * @property null|string                                            $two_factor_recovery_codes | 
					
						
							|  |  |  |  * @property null|string                                            $guid | 
					
						
							|  |  |  |  * @property null|string                                            $domain | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |  * @method static Builder|User whereDomain($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereGuid($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereTwoFactorRecoveryCodes($value) | 
					
						
							|  |  |  |  * @method static Builder|User whereTwoFactorSecret($value) | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property null|int                                                   $user_group_id | 
					
						
							|  |  |  |  * @property GroupMembership[]|\Illuminate\Database\Eloquent\Collection $groupMemberships | 
					
						
							|  |  |  |  * @property null|int                                                   $group_memberships_count | 
					
						
							|  |  |  |  * @property null|UserGroup                                             $userGroup | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-09-18 10:08:10 +02:00
										 |  |  |  * @method static Builder|User whereUserGroupId($value) | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property \Illuminate\Database\Eloquent\Collection<int, TransactionCurrency> $currencies | 
					
						
							|  |  |  |  * @property null|int                                                           $currencies_count | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-03-09 06:33:23 +01:00
										 |  |  |  * @mixin Eloquent | 
					
						
							| 
									
										
										
										
											2016-01-09 08:20:55 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-01-08 16:02:15 +01:00
										 |  |  | class User extends Authenticatable | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-30 14:24:10 +01:00
										 |  |  |     use HasApiTokens; | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |     use Notifiable; | 
					
						
							| 
									
										
										
										
											2016-01-09 08:51:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 08:12:18 +01:00
										 |  |  |     protected $casts | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |                         = [ | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |                             'created_at' => 'datetime', | 
					
						
							|  |  |  |                             'updated_at' => 'datetime', | 
					
						
							|  |  |  |                             'blocked'    => 'boolean', | 
					
						
							|  |  |  |                         ]; | 
					
						
							| 
									
										
										
										
											2015-07-26 15:51:07 +02:00
										 |  |  |     protected $fillable = ['email', 'password', 'blocked', 'blocked_code']; | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |     protected $hidden   = ['password', 'remember_token']; | 
					
						
							|  |  |  |     protected $table    = 'users'; | 
					
						
							| 
									
										
										
										
											2015-02-06 05:04:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-02 14:17:11 +02:00
										 |  |  |      * @throws NotFoundHttpException | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |     public static function routeBinder(string $value): self | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-10 08:21:20 +01:00
										 |  |  |         if (auth()->check()) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |             $userId = (int)$value; | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |             $user   = self::find($userId); | 
					
						
							| 
									
										
										
										
											2018-04-02 14:17:11 +02:00
										 |  |  |             if (null !== $user) { | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |                 return $user; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 14:24:10 +01:00
										 |  |  |         throw new NotFoundHttpException(); | 
					
						
							| 
									
										
										
										
											2018-01-10 07:51:47 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to accounts. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function accounts(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:04:06 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(Account::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:04:06 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-06 05:01:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to attachments | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function attachments(): HasMany | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(Attachment::class); | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-18 09:49:19 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to available budgets | 
					
						
							| 
									
										
										
										
											2015-07-18 09:49:19 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function availableBudgets(): HasMany | 
					
						
							| 
									
										
										
										
											2015-07-18 09:49:19 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(AvailableBudget::class); | 
					
						
							| 
									
										
										
										
											2015-07-18 09:49:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 18:35:49 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to bills. | 
					
						
							| 
									
										
										
										
											2020-11-29 18:35:49 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function bills(): HasMany | 
					
						
							| 
									
										
										
										
											2020-11-29 18:35:49 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(Bill::class); | 
					
						
							| 
									
										
										
										
											2020-11-29 18:35:49 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-07 06:44:01 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to budgets. | 
					
						
							| 
									
										
										
										
											2020-05-07 06:44:01 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function budgets(): HasMany | 
					
						
							| 
									
										
										
										
											2020-05-07 06:44:01 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(Budget::class); | 
					
						
							| 
									
										
										
										
											2020-05-07 06:44:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 13:47:23 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to categories | 
					
						
							| 
									
										
										
										
											2016-12-30 13:47:23 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function categories(): HasMany | 
					
						
							| 
									
										
										
										
											2016-12-30 13:47:23 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(Category::class); | 
					
						
							| 
									
										
										
										
											2016-12-30 13:47:23 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-28 15:03:33 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Link to currencies | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function currencies(): BelongsToMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsToMany(TransactionCurrency::class)->withTimestamps()->withPivot('user_default'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to currency exchange rates | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function currencyExchangeRates(): HasMany | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(CurrencyExchangeRate::class); | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Generates access token. | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @throws \Exception | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function generateAccessToken(): string | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         $bytes = random_bytes(16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return bin2hex($bytes); | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 18:14:14 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * A safe method that returns the user's current administration ID (group ID). | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getAdministrationId(): int | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $groupId = (int)$this->user_group_id; | 
					
						
							|  |  |  |         if (0 === $groupId) { | 
					
						
							|  |  |  |             throw new FireflyException('User has no administration ID.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 18:14:14 +01:00
										 |  |  |         return $groupId; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Get the models LDAP domain. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function getLdapDomain() | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->{$this->getLdapDomainColumn()}; | 
					
						
							| 
									
										
										
										
											2020-06-20 10:22:07 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Get the database column name of the domain. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function getLdapDomainColumn() | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return 'domain'; | 
					
						
							| 
									
										
										
										
											2016-01-12 21:37:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Get the models LDAP GUID. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function getLdapGuid() | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->{$this->getLdapGuidColumn()}; | 
					
						
							| 
									
										
										
										
											2021-08-30 06:37:55 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get the models LDAP GUID database column name. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function getLdapGuidColumn() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return 'objectguid'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |      * Does the user have role X in group Y, or is the user the group owner of has full rights to the group? | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * If $allowOverride is set to true, then the roles FULL or OWNER will also be checked, | 
					
						
							|  |  |  |      * which means that in most cases the user DOES have access, regardless of the original role submitted in $role. | 
					
						
							| 
									
										
										
										
											2023-11-30 17:28:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |     public function hasRoleInGroupOrOwner(UserGroup $userGroup, UserRoleEnum $role): bool | 
					
						
							| 
									
										
										
										
											2023-11-30 17:28:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |         $roles = [$role->value, UserRoleEnum::OWNER->value, UserRoleEnum::FULL->value]; | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |         return $this->hasAnyRoleInGroup($userGroup, $roles); | 
					
						
							| 
									
										
										
										
											2023-11-30 17:28:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |      * Does the user have role X in group Y? | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |     public function hasSpecificRoleInGroup(UserGroup $userGroup, UserRoleEnum $role): bool | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |         return $this->hasAnyRoleInGroup($userGroup, [$role]); | 
					
						
							| 
									
										
										
										
											2023-11-30 17:28:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function groupMemberships(): HasMany | 
					
						
							| 
									
										
										
										
											2017-04-13 20:47:59 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(GroupMembership::class)->with(['userGroup', 'userRole']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-29 07:00:26 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to object groups. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function objectGroups(): HasMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasMany(ObjectGroup::class); | 
					
						
							| 
									
										
										
										
											2017-09-14 18:27:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to piggy banks. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function piggyBanks(): HasManyThrough | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasManyThrough(PiggyBank::class, Account::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to preferences. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function preferences(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(Preference::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-10 16:59:03 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Link to recurring transactions. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function recurrences(): HasMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasMany(Recurrence::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the notification routing information for the given driver. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string            $driver | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @param null|Notification $notification | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |      * @return mixed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function routeNotificationFor($driver, $notification = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         $method = 'routeNotificationFor'.Str::studly($driver); | 
					
						
							| 
									
										
										
										
											2023-11-26 12:50:54 +01:00
										 |  |  |         if (method_exists($this, $method)) { | 
					
						
							| 
									
										
										
										
											2023-11-04 19:20:07 +01:00
										 |  |  |             return $this->{$method}($notification); // @phpstan-ignore-line
 | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $email  = $this->email; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         // see if user has alternative email address:
 | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $pref   = app('preferences')->getForUser($this, 'remote_guard_alt_email'); | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         if (null !== $pref) { | 
					
						
							|  |  |  |             $email = $pref->data; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // if user is demo user, send to owner:
 | 
					
						
							|  |  |  |         if ($this->hasRole('demo')) { | 
					
						
							|  |  |  |             $email = config('firefly.site_owner'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return match ($driver) { | 
					
						
							|  |  |  |             'database' => $this->notifications(), | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |             'mail'     => $email, | 
					
						
							|  |  |  |             default    => null, | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This method refers to the "global" role a user can have, outside of any group they may be part of. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function hasRole(string $role): bool | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         return 1 === $this->roles()->where('name', $role)->count(); | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Link to roles. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function roles(): BelongsToMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsToMany(Role::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Route notifications for the Slack channel. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function routeNotificationForSlack(Notification $notification): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // this check does not validate if the user is owner, Should be done by notification itself.
 | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $res  = app('fireflyconfig')->get('slack_webhook_url', '')->data; | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |         if (is_array($res)) { | 
					
						
							|  |  |  |             $res = ''; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $res  = (string)$res; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         if ($notification instanceof TestNotification) { | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |             return $res; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-16 08:44:20 +02:00
										 |  |  |         if ($notification instanceof UserInvitation) { | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |             return $res; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-16 08:44:20 +02:00
										 |  |  |         if ($notification instanceof UserRegistration) { | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |             return $res; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-16 08:44:20 +02:00
										 |  |  |         if ($notification instanceof VersionCheckResult) { | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |             return $res; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |         $pref = app('preferences')->getForUser($this, 'slack_webhook_url', '')->data; | 
					
						
							|  |  |  |         if (is_array($pref)) { | 
					
						
							|  |  |  |             return ''; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-28 17:18:31 +01:00
										 |  |  |         return (string)$pref; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to rule groups. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function ruleGroups(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(RuleGroup::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to rules. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function rules(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(Rule::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-20 06:17:56 +02:00
										 |  |  |     // start LDAP related code
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Send the password reset notification. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $token | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function sendPasswordResetNotification($token): void | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         $ipAddress = \Request::ip(); | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-07 11:13:04 +02:00
										 |  |  |         event(new RequestedNewPassword($this, $token, $ipAddress)); | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Set the models LDAP domain. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param string $domain | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-12-21 04:59:23 +01:00
										 |  |  |     public function setLdapDomain($domain): void | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->{$this->getLdapDomainColumn()} = $domain; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set the models LDAP GUID. | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param string $guid | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-29 15:01:12 +02:00
										 |  |  |      * @deprecated | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-12-21 04:59:23 +01:00
										 |  |  |     public function setLdapGuid($guid): void | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->{$this->getLdapGuidColumn()} = $guid; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-29 18:28:49 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to tags. | 
					
						
							| 
									
										
										
										
											2015-03-29 18:28:49 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function tags(): HasMany | 
					
						
							| 
									
										
										
										
											2015-03-29 18:28:49 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(Tag::class); | 
					
						
							| 
									
										
										
										
											2015-03-29 18:28:49 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 20:00:40 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Link to transaction groups. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function transactionGroups(): HasMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasMany(TransactionGroup::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to transaction journals. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-08-26 09:30:52 +02:00
										 |  |  |     public function transactionJournals(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(TransactionJournal::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-25 20:27:53 +01:00
										 |  |  |      * Link to transactions. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 10:11:06 +01:00
										 |  |  |     public function transactions(): HasManyThrough | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasManyThrough(Transaction::class, TransactionJournal::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function userGroup(): BelongsTo | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         return $this->belongsTo(UserGroup::class); | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |      * Link to webhooks | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     public function webhooks(): HasMany | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |         return $this->hasMany(Webhook::class); | 
					
						
							| 
									
										
										
										
											2021-06-12 06:28:17 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Does the user have role X, Y or Z in group A? | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function hasAnyRoleInGroup(UserGroup $userGroup, array $roles): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         app('log')->debug(sprintf('in hasAnyRoleInGroup(%s)', implode(', ', $roles))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var Collection $dbRoles */ | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $dbRoles          = UserRole::whereIn('title', $roles)->get(); | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         if (0 === $dbRoles->count()) { | 
					
						
							|  |  |  |             app('log')->error(sprintf('Could not find role(s): %s. Probably migration mishap.', implode(', ', $roles))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $dbRolesIds       = $dbRoles->pluck('id')->toArray(); | 
					
						
							|  |  |  |         $dbRolesTitles    = $dbRoles->pluck('title')->toArray(); | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /** @var Collection $groupMemberships */ | 
					
						
							|  |  |  |         $groupMemberships = $this->groupMemberships() | 
					
						
							|  |  |  |             ->whereIn('user_role_id', $dbRolesIds) | 
					
						
							|  |  |  |             ->where('user_group_id', $userGroup->id)->get() | 
					
						
							|  |  |  |         ; | 
					
						
							|  |  |  |         if (0 === $groupMemberships->count()) { | 
					
						
							|  |  |  |             app('log')->error(sprintf( | 
					
						
							|  |  |  |                 'User #%d "%s" does not have roles %s in user group #%d "%s"', | 
					
						
							|  |  |  |                 $this->id, | 
					
						
							|  |  |  |                 $this->email, | 
					
						
							|  |  |  |                 implode(', ', $roles), | 
					
						
							|  |  |  |                 $userGroup->id, | 
					
						
							|  |  |  |                 $userGroup->title | 
					
						
							|  |  |  |             )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         foreach ($groupMemberships as $membership) { | 
					
						
							|  |  |  |             app('log')->debug(sprintf( | 
					
						
							|  |  |  |                 'User #%d "%s" has role "%s" in user group #%d "%s"', | 
					
						
							|  |  |  |                 $this->id, | 
					
						
							|  |  |  |                 $this->email, | 
					
						
							|  |  |  |                 $membership->userRole->title, | 
					
						
							|  |  |  |                 $userGroup->id, | 
					
						
							|  |  |  |                 $userGroup->title | 
					
						
							|  |  |  |             )); | 
					
						
							|  |  |  |             if (in_array($membership->userRole->title, $dbRolesTitles, true)) { | 
					
						
							|  |  |  |                 app('log')->debug(sprintf('Return true, found role "%s"', $membership->userRole->title)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         app('log')->error(sprintf( | 
					
						
							|  |  |  |             'User #%d "%s" does not have roles %s in user group #%d "%s"', | 
					
						
							|  |  |  |             $this->id, | 
					
						
							|  |  |  |             $this->email, | 
					
						
							|  |  |  |             implode(', ', $roles), | 
					
						
							|  |  |  |             $userGroup->id, | 
					
						
							|  |  |  |             $userGroup->title | 
					
						
							|  |  |  |         )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | } |