1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\Applicant; |
7
|
|
|
use App\Models\JobPoster; |
8
|
|
|
use App\Policies\BasePolicy; |
9
|
|
|
|
10
|
|
|
class ApplicantPolicy extends BasePolicy |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Returns true if $user owns a job to which $applicant has applied. |
15
|
|
|
* |
16
|
|
|
* @param \App\Models\User $user Generic User object for checking Manager relationship to Job Poster. |
17
|
|
|
* @param \App\Models\Applicant $applicant Applicant object used within applications submitted to Job Poster. |
18
|
|
|
* @return boolean |
19
|
|
|
*/ |
20
|
1 |
|
protected function ownsJobApplicantAppliedTo(User $user, Applicant $applicant) |
21
|
1 |
|
{ |
22
|
1 |
|
$applicant_id = $applicant->id; |
23
|
|
|
$user_id = $user->id; |
24
|
1 |
|
return JobPoster::whereHas( |
25
|
1 |
|
'manager', |
26
|
1 |
|
function ($q) use ($user_id) { |
27
|
|
|
$q->where('user_id', $user_id); |
28
|
|
|
} |
29
|
|
|
)->whereHas( |
30
|
|
|
'submitted_applications', |
31
|
|
|
function ($q) use ($applicant_id) { |
32
|
|
|
$q->where('applicant_id', $applicant_id); |
33
|
|
|
} |
34
|
|
|
)->get()->isNotEmpty(); |
35
|
|
|
} |
36
|
3 |
|
|
37
|
|
|
/** |
38
|
3 |
|
* Determine whether the user can view the applicant. |
39
|
3 |
|
* |
40
|
3 |
|
* @param \App\Models\User $user User object making the view request. |
41
|
3 |
|
* @param \App\Models\Applicant $applicant Applicant object to be viewed. |
42
|
|
|
* @return boolean |
43
|
|
|
*/ |
44
|
|
|
public function view(User $user, Applicant $applicant) |
45
|
|
|
{ |
46
|
|
|
$authApplicant = $user->isApplicant() && |
47
|
|
|
$applicant->user->is($user); |
48
|
|
|
$authManager = $user->isManager() && $this->ownsJobApplicantAppliedTo($user, $applicant); |
49
|
|
|
return $authApplicant || $authManager; |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
/** |
53
|
|
|
* Determine whether the user can create applicants. |
54
|
|
|
* |
55
|
|
|
* @param \App\Models\User $user User object making the create request. |
56
|
|
|
* @return boolean |
57
|
|
|
*/ |
58
|
|
|
public function create(User $user) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
return false; |
61
|
|
|
} |
62
|
1 |
|
|
63
|
|
|
/** |
64
|
1 |
|
* Determine whether the user can update the applicant. |
65
|
1 |
|
* |
66
|
|
|
* @param \App\Models\User $user User object making the update request. |
67
|
|
|
* @param \App\Models\Applicant $applicant Applicant object being updated. |
68
|
|
|
* @return boolean |
69
|
|
|
*/ |
70
|
|
|
public function update(User $user, Applicant $applicant) |
71
|
|
|
{ |
72
|
|
|
return $user->isApplicant() && |
73
|
|
|
$applicant->user_id === $user->id; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Determine whether the user can delete the applicant. |
78
|
|
|
* |
79
|
|
|
* @param \App\Models\User $user User object making the delete request. |
80
|
|
|
* @param \App\Models\Applicant $applicant Applicant object being deleted. |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function delete(User $user, Applicant $applicant) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Determine whether the user can restore the applicant. |
89
|
|
|
* |
90
|
|
|
* @param \App\Models\User $user User object making the restore request. |
91
|
|
|
* @param \App\Models\Applicant $applicant Applicant object being restored. |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public function restore(User $user, Applicant $applicant) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Determine whether the user can permanently delete the applicant. |
100
|
|
|
* |
101
|
|
|
* @param \App\Models\User $user User object making the forceDelete request. |
102
|
|
|
* @param \App\Models\Applicant $applicant Applicant object being forceDeleted. |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function forceDelete(User $user, Applicant $applicant) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.