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