Total Complexity | 17 |
Total Lines | 94 |
Duplicated Lines | 0 % |
Coverage | 52.38% |
Changes | 2 | ||
Bugs | 0 | Features | 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 | 12 | 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 | 12 | return $jobPoster->published || |
|
24 | ( |
||
25 | 6 | $user && |
|
26 | 6 | $user->isManager() && |
|
27 | 12 | $jobPoster->manager->user_id == $user->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 can create a new job poster. |
||
40 | 1 | return $user->isManager(); |
|
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 | 19 | public function update(User $user, JobPoster $jobPoster) |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Determine whether the user can delete the job poster. |
||
60 | * |
||
61 | * @param \App\Models\User $user User object making the request. |
||
62 | * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon. |
||
63 | * |
||
64 | * @return boolean |
||
65 | */ |
||
66 | public function delete(User $user, JobPoster $jobPoster) : bool |
||
67 | { |
||
68 | // Jobs can only be deleted when they're in the 'draft' |
||
69 | // state, and only by managers that created them. |
||
70 | return $user->isManager() && |
||
71 | $jobPoster->manager->user->id == $user->id && |
||
72 | !$jobPoster->published; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Determine whether the user can submit a job poster for review. |
||
77 | * |
||
78 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
79 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
80 | * @return mixed |
||
81 | */ |
||
82 | public function submitForReview(User $user, JobPoster $jobPoster) |
||
83 | { |
||
84 | // Only upgradedManagers can submit jobs for review, only their own jobs, and only if they're still drafts. |
||
85 | // NOTE: this is one of the only permissions to require an upgradedManager, as opposed to a demoManager.var |
||
86 | return $user->isUpgradedManager() && |
||
87 | $jobPoster->manager->user->id == $user->id && |
||
88 | $jobPoster->status() === 'draft'; |
||
89 | } |
||
90 | /** |
||
91 | * Determine whether the user can review applications to the job poster. |
||
92 | * |
||
93 | * @param \App\Models\User $user |
||
2 ignored issues
–
show
|
|||
94 | * @param \App\Models\JobPoster $jobPoster |
||
2 ignored issues
–
show
|
|||
95 | * @return mixed |
||
96 | */ |
||
97 | public function reviewApplicationsFor(User $user, JobPoster $jobPoster) |
||
103 | } |
||
104 | } |
||
105 |