| Total Complexity | 20 | 
| Total Lines | 120 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 10 | class JobPolicy extends BasePolicy  | 
            ||
| 11 | { | 
            ||
| 12 | |||
| 13 | /**  | 
            ||
| 14 | * Determine whether the user can view the job poster.  | 
            ||
| 15 | *  | 
            ||
| 16 | * @param \App\Models\User $user  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 17 | * @param \App\Models\JobPoster $jobPoster  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 18 | * @return mixed  | 
            ||
| 19 | */  | 
            ||
| 20 | public function view(?User $user, JobPoster $jobPoster)  | 
            ||
| 29 | );  | 
            ||
| 30 | }  | 
            ||
| 31 | |||
| 32 | /**  | 
            ||
| 33 | * Determine whether the user can create job posters.  | 
            ||
| 34 | *  | 
            ||
| 35 | * @param \App\Models\User $user User to test against.  | 
            ||
| 36 | * @return mixed  | 
            ||
| 37 | */  | 
            ||
| 38 | public function create(User $user)  | 
            ||
| 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 | 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 | return $user->isManager() &&  | 
            ||
| 55 | $jobPoster->manager->user->id == $user->id &&  | 
            ||
| 56 | !$jobPoster->published;  | 
            ||
| 57 | }  | 
            ||
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * Determine whether the user can delete the job poster.  | 
            ||
| 61 | *  | 
            ||
| 62 | * @param \App\Models\User $user User object making the request.  | 
            ||
| 63 | * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon.  | 
            ||
| 64 | *  | 
            ||
| 65 | * @return boolean  | 
            ||
| 66 | */  | 
            ||
| 67 | public function delete(User $user, JobPoster $jobPoster) : bool  | 
            ||
| 68 |     { | 
            ||
| 69 | // Jobs can only be deleted when they're in the 'draft'  | 
            ||
| 70 | // state, and only by managers that created them.  | 
            ||
| 71 | return $user->isManager() &&  | 
            ||
| 72 | $jobPoster->manager->user->id == $user->id &&  | 
            ||
| 73 | !$jobPoster->published;  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * Determine whether the user can submit a job poster for review.  | 
            ||
| 78 | *  | 
            ||
| 79 | * @param \App\Models\User $user  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 80 | * @param \App\Models\JobPoster $jobPoster  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 81 | * @return mixed  | 
            ||
| 82 | */  | 
            ||
| 83 | public function submitForReview(User $user, JobPoster $jobPoster)  | 
            ||
| 84 |     { | 
            ||
| 85 | // Only upgradedManagers can submit jobs for review, only their own jobs, and only if they're still drafts.  | 
            ||
| 86 | // NOTE: this is one of the only permissions to require an upgradedManager, as opposed to a demoManager.var  | 
            ||
| 87 | return $user->isUpgradedManager() &&  | 
            ||
| 88 | $jobPoster->manager->user->id == $user->id &&  | 
            ||
| 89 | $jobPoster->status() === 'draft';  | 
            ||
| 90 | }  | 
            ||
| 91 | /**  | 
            ||
| 92 | * Determine whether the user can review applications to 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 reviewApplicationsFor(User $user, JobPoster $jobPoster)  | 
            ||
| 104 | }  | 
            ||
| 105 | |||
| 106 | /**  | 
            ||
| 107 | * Determine whether the user can view the comments.  | 
            ||
| 108 | *  | 
            ||
| 109 | * @param \App\Models\User $user  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 110 | * @param \App\Models\Comment $comment  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 111 | * @return bool  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 112 | */  | 
            ||
| 113 | public function viewComments(User $user)  | 
            ||
| 114 |     { | 
            ||
| 115 | // Only the manager that created a comment can view the comment.  | 
            ||
| 116 | // Only Hr advisors who have claimed a job can view the comments.  | 
            ||
| 117 | return true;  | 
            ||
| 118 | }  | 
            ||
| 119 | |||
| 120 | /**  | 
            ||
| 121 | * Determine whether the user can create a comment  | 
            ||
| 122 | *  | 
            ||
| 123 | * @param \App\Models\User $user User to test against  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 124 | * @return bool  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 125 | */  | 
            ||
| 126 | public function storeComment(User $user)  | 
            ||
| 130 | }  | 
            ||
| 131 | }  | 
            ||
| 132 |