Total Complexity | 16 |
Total Lines | 104 |
Duplicated Lines | 0 % |
Coverage | 40.91% |
Changes | 0 |
1 | <?php |
||
9 | class JobPolicy extends BasePolicy |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Determine whether the user can view the job poster. |
||
14 | * |
||
15 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
16 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
17 | * @return mixed |
||
18 | */ |
||
19 | 11 | public function view(?User $user, JobPoster $jobPoster) |
|
20 | { |
||
21 | //Anyone can view a published job |
||
22 | //Only the manager that created it can view an unpublished job |
||
23 | 11 | return $jobPoster->published || |
|
24 | ( |
||
25 | 6 | $user && |
|
26 | 6 | $user->hasRole('manager') && |
|
27 | 11 | $jobPoster->manager_id == $user->manager->id |
|
28 | ); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Determine whether the user can create job posters. |
||
33 | * |
||
34 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
35 | * @return mixed |
||
36 | */ |
||
37 | public function create(User $user) |
||
38 | { |
||
39 | //Any manager can create a new job poster |
||
40 | //TODO: for now, only Admins can create posters. This will change soon. |
||
41 | return $user->hasRole('admin'); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Determine whether the user can update the job poster. |
||
46 | * |
||
47 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
48 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
49 | * @return mixed |
||
50 | */ |
||
51 | 14 | public function update(User $user, JobPoster $jobPoster) |
|
52 | { |
||
53 | //Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs |
||
54 | 14 | return $user->user_role->name == 'manager' && |
|
55 | 14 | $jobPoster->manager->user->id == $user->id && |
|
56 | 14 | !$jobPoster->published; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Determine whether the user can review applications to the job poster. |
||
61 | * |
||
62 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
63 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
64 | * @return mixed |
||
65 | */ |
||
66 | public function review(User $user, JobPoster $jobPoster) |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Determine whether the user can delete the job poster. |
||
77 | * |
||
78 | * @param \App\Models\User $user User object making the request. |
||
79 | * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon. |
||
80 | * |
||
81 | * @return boolean |
||
82 | */ |
||
83 | public function delete(User $user, JobPoster $jobPoster) : bool |
||
84 | { |
||
85 | // Jobs can only be deleted when they're in the 'draft' |
||
86 | // state, and only by managers that created them. |
||
87 | return $user->user_role->name == 'manager' && |
||
88 | $jobPoster->manager->user->id == $user->id && |
||
89 | !$jobPoster->published; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Determine whether the user can restore the job poster. |
||
94 | * |
||
95 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
96 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
97 | * @return mixed |
||
98 | */ |
||
99 | public function restore(User $user, JobPoster $jobPoster) |
||
101 | // |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Determine whether the user can permanently delete the job poster. |
||
106 | * |
||
107 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
108 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
109 | * @return mixed |
||
110 | */ |
||
111 | public function forceDelete(User $user, JobPoster $jobPoster) |
||
116 |