| Total Complexity | 19 |
| Total Lines | 178 |
| Duplicated Lines | 0 % |
| Coverage | 38.1% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 42 | class User extends BaseModel implements |
||
| 43 | // Laravel contracts for native login. |
||
| 44 | AuthenticatableContract, |
||
| 45 | CanResetPasswordContract, |
||
| 46 | // Contract for use with Gates and Policies. |
||
| 47 | AuthorizableContract |
||
| 48 | // Custom contract for use with openid login. |
||
| 49 | // \App\Services\Auth\Contracts\OidcAuthenticatable. |
||
| 50 | { |
||
| 51 | |||
| 52 | // Traits for Laravel basic authentication. |
||
| 53 | use Authenticatable; |
||
| 54 | use CanResetPassword; |
||
| 55 | // Trait for working with Gates and Policies. |
||
| 56 | use Authorizable; |
||
| 57 | // Trait for notifications. |
||
| 58 | use Notifiable; |
||
|
|
|||
| 59 | // Trait for Backpack. |
||
| 60 | use CrudTrait; |
||
| 61 | |||
| 62 | protected $casts = [ |
||
|
1 ignored issue
–
show
|
|||
| 63 | 'is_confirmed' => 'boolean', |
||
| 64 | 'is_priority' => 'boolean', |
||
| 65 | 'user_role_id' => 'int', |
||
| 66 | 'email' => 'string', |
||
| 67 | 'gov_email' => 'string', |
||
| 68 | 'not_in_gov' => 'boolean', |
||
| 69 | ]; |
||
| 70 | |||
| 71 | protected $fillable = [ |
||
|
1 ignored issue
–
show
|
|||
| 72 | 'name', 'email', 'password', 'is_priority', 'gov_email', 'not_in_gov' |
||
| 73 | ]; |
||
| 74 | |||
| 75 | protected $with = ['user_role']; |
||
|
1 ignored issue
–
show
|
|||
| 76 | |||
| 77 | protected $hidden = [ |
||
|
1 ignored issue
–
show
|
|||
| 78 | 'password', 'remember_token', |
||
| 79 | ]; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The event map for the model. |
||
| 83 | * |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | 22 | protected $dispatchesEvents = [ |
|
| 87 | 'created' => UserCreated::class, |
||
| 88 | 22 | 'updated' => UserUpdated::class, |
|
| 89 | ]; |
||
| 90 | |||
| 91 | 37 | public function applicant() //phpcs:ignore |
|
| 92 | { |
||
| 93 | 37 | return $this->hasOne(\App\Models\Applicant::class); |
|
| 94 | } |
||
| 95 | |||
| 96 | public function manager() //phpcs:ignore |
||
| 97 | { |
||
| 98 | return $this->hasOne(\App\Models\Manager::class); |
||
| 99 | } |
||
| 100 | |||
| 101 | 72 | public function profile_pic() //phpcs:ignore |
|
| 102 | { |
||
| 103 | 72 | return $this->hasOne(\App\Models\ProfilePic::class); |
|
| 104 | } |
||
| 105 | |||
| 106 | public function user_role() //phpcs:ignore |
||
| 107 | { |
||
| 108 | return $this->belongsTo(\App\Models\UserRole::class); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Role related functions |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Returns true if this user has the Applicant role. |
||
| 115 | * |
||
| 116 | * @return boolean |
||
| 117 | */ |
||
| 118 | public function isApplicant(): bool |
||
| 119 | { |
||
| 120 | // Currently, every user can create an Applicant profile and apply to jobs. |
||
| 121 | return true; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Returns true if this user has the upgradedManager role. |
||
| 126 | * |
||
| 127 | * @return boolean |
||
| 128 | */ |
||
| 129 | public function isUpgradedManager(): bool |
||
| 130 | { |
||
| 131 | return $this->isAdmin() || $this->user_role->name === 'upgradedManager'; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Returns true this user has the demoManager role. |
||
| 136 | 47 | * |
|
| 137 | * @return boolean |
||
| 138 | 47 | */ |
|
| 139 | public function isDemoManager(): bool |
||
| 140 | { |
||
| 141 | // Currently, every non-upgradedManager user can be considered a demoManager. |
||
| 142 | return !$this->isUpgradedManager(); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Returns true if this user has the demoManager or upgradedManager role. |
||
| 147 | * |
||
| 148 | * @return boolean |
||
| 149 | */ |
||
| 150 | public function isManager(): bool |
||
| 151 | { |
||
| 152 | // Currently, every user can use the Manager portal as a demoManager. |
||
| 153 | return $this->isDemoManager() || $this->isUpgradedManager(); |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Returns true if this user has the Admin role. |
||
| 158 | * |
||
| 159 | * @return boolean |
||
| 160 | */ |
||
| 161 | public function isAdmin(): bool |
||
| 162 | { |
||
| 163 | return $this->user_role->name === 'admin'; |
||
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Check if the user has the specified role. |
||
| 168 | * @param string $role This may be either 'applicant', 'manager' or 'admin'. |
||
| 169 | * @return boolean |
||
| 170 | */ |
||
| 171 | public function hasRole($role) |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Set this user to the specified role. |
||
| 187 | * |
||
| 188 | * @param string $role Must be either 'applicant', 'manager' or 'admin. |
||
| 189 | * @return void |
||
| 190 | */ |
||
| 191 | public function setRole(string $role): void |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * OVERRIDE |
||
| 198 | * Send the password reset notification. |
||
| 199 | * |
||
| 200 | * @param string $token |
||
|
2 ignored issues
–
show
|
|||
| 201 | * |
||
| 202 | * @return void |
||
| 203 | */ |
||
| 204 | public function sendPasswordResetNotification($token) |
||
|
1 ignored issue
–
show
|
|||
| 205 | { |
||
| 206 | $this->notify(new ResetPasswordNotification($token)); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Gov identity has been confirmed either if: |
||
| 211 | * - they have confirmed to NOT be in government, |
||
| 212 | * - OR they've added a gov email. |
||
| 213 | * |
||
| 214 | * @param [type] $user |
||
|
2 ignored issues
–
show
|
|||
| 215 | * @return boolean |
||
| 216 | */ |
||
| 217 | public function isGovIdentityConfirmed() |
||
| 220 | } |
||
| 221 | } |
||
| 222 |