Total Complexity | 17 |
Total Lines | 102 |
Duplicated Lines | 0 % |
Coverage | 50% |
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 User to test against. |
||
35 | * @return mixed |
||
36 | */ |
||
37 | 1 | public function create(User $user) |
|
38 | { |
||
39 | // Any manager or admin can create a new job poster. |
||
40 | 1 | return $user->hasRole('manager') || $user->hasRole('admin'); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Determine whether the user can update the job poster. |
||
45 | * |
||
46 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
47 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
48 | * @return mixed |
||
49 | */ |
||
50 | 14 | public function update(User $user, JobPoster $jobPoster) |
|
51 | { |
||
52 | // Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs |
||
53 | 14 | return $user->user_role->name == 'manager' && |
|
54 | 14 | $jobPoster->manager->user->id == $user->id && |
|
55 | 14 | !$jobPoster->published; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Determine whether the user can review applications to the job poster. |
||
60 | * |
||
61 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
62 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
63 | * @return mixed |
||
64 | */ |
||
65 | public function review(User $user, JobPoster $jobPoster) |
||
66 | { |
||
67 | // Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs |
||
68 | return $user->user_role->name == 'manager' && |
||
69 | $jobPoster->manager->user->id == $user->id && |
||
70 | $jobPoster->isClosed(); |
||
71 | } |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Determine whether the user can delete the job poster. |
||
76 | * |
||
77 | * @param \App\Models\User $user User object making the request. |
||
78 | * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon. |
||
79 | * |
||
80 | * @return boolean |
||
81 | */ |
||
82 | public function delete(User $user, JobPoster $jobPoster) : bool |
||
83 | { |
||
84 | // Jobs can only be deleted when they're in the 'draft' |
||
85 | // state, and only by managers that created them. |
||
86 | return $user->user_role->name == 'manager' && |
||
87 | $jobPoster->manager->user->id == $user->id && |
||
88 | !$jobPoster->published; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Determine whether the user can restore the job poster. |
||
93 | * |
||
94 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
95 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
96 | * @return mixed |
||
97 | */ |
||
98 | public function restore(User $user, JobPoster $jobPoster) |
||
99 | { |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Determine whether the user can permanently delete the job poster. |
||
104 | * |
||
105 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
106 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
107 | * @return mixed |
||
108 | */ |
||
109 | public function forceDelete(User $user, JobPoster $jobPoster) |
||
111 | } |
||
112 | } |
||
113 |