1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\Manager; |
7
|
|
|
use App\Models\Applicant; |
8
|
|
|
use App\Models\JobPoster; |
9
|
|
|
use App\Policies\BasePolicy; |
10
|
|
|
|
11
|
|
|
class ApplicantPolicy extends BasePolicy |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Returns true if $manager owns a job to which $applicant has applied |
16
|
|
|
* @param Manager $manager [description] |
|
|
|
|
17
|
|
|
* @param Applicant $applicant [description] |
18
|
|
|
* @return [type] [description] |
|
|
|
|
19
|
|
|
*/ |
20
|
2 |
|
protected function managerCanViewApplicant(Manager $manager, Applicant $applicant) { |
21
|
2 |
|
$applicant_id = $applicant->id; |
22
|
2 |
|
return JobPoster::where('manager_id', $manager->id) |
23
|
|
|
->whereHas('submitted_applications', function ($q) use ($applicant_id){ |
|
|
|
|
24
|
2 |
|
$q->where('applicant_id', $applicant_id); |
25
|
2 |
|
}) |
|
|
|
|
26
|
2 |
|
->get()->isNotEmpty(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Determine whether the user can view the applicant. |
31
|
|
|
* |
32
|
|
|
* @param \App\Models\User $user |
|
|
|
|
33
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
34
|
|
|
* @return mixed |
|
|
|
|
35
|
|
|
*/ |
36
|
2 |
|
public function view(User $user, Applicant $applicant) |
37
|
|
|
{ |
38
|
2 |
|
$authApplicant = $user->hasRole('applicant') && |
39
|
2 |
|
$applicant->user->is($user); |
40
|
2 |
|
$authManager = $user->hasRole('manager') && $this->managerCanViewApplicant($user->manager, $applicant); |
41
|
2 |
|
return $authApplicant || $authManager; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Determine whether the user can create applicants. |
46
|
|
|
* |
47
|
|
|
* @param \App\Models\User $user |
|
|
|
|
48
|
|
|
* @return mixed |
|
|
|
|
49
|
|
|
*/ |
50
|
2 |
|
public function create(User $user) |
|
|
|
|
51
|
|
|
{ |
52
|
2 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Determine whether the user can update the applicant. |
57
|
|
|
* |
58
|
|
|
* @param \App\Models\User $user |
|
|
|
|
59
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
60
|
|
|
* @return mixed |
|
|
|
|
61
|
|
|
*/ |
62
|
|
|
public function update(User $user, Applicant $applicant) |
63
|
|
|
{ |
64
|
|
|
return $user->user_role->name === "applicant" && |
65
|
|
|
$applicant->user_id === $user->id; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Determine whether the user can delete the applicant. |
70
|
|
|
* |
71
|
|
|
* @param \App\Models\User $user |
|
|
|
|
72
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
73
|
|
|
* @return mixed |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
public function delete(User $user, Applicant $applicant) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
// |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Determine whether the user can restore the applicant. |
82
|
|
|
* |
83
|
|
|
* @param \App\Models\User $user |
|
|
|
|
84
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
85
|
|
|
* @return mixed |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function restore(User $user, Applicant $applicant) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
// |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Determine whether the user can permanently delete the applicant. |
94
|
|
|
* |
95
|
|
|
* @param \App\Models\User $user |
|
|
|
|
96
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
97
|
|
|
* @return mixed |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
public function forceDelete(User $user, Applicant $applicant) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
// |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|