1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\JobPoster; |
7
|
|
|
use App\Policies\BasePolicy; |
8
|
|
|
|
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 |
|
|
|
|
16
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
17
|
|
|
* @return mixed |
|
|
|
|
18
|
|
|
*/ |
19
|
14 |
|
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
|
14 |
|
return $jobPoster->published || |
24
|
|
|
( |
25
|
6 |
|
$user && |
26
|
14 |
|
$jobPoster->manager->user->id == $user->id |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Determine whether the user can create job posters. |
32
|
|
|
* |
33
|
|
|
* @param \App\Models\User $user |
|
|
|
|
34
|
|
|
* @return mixed |
|
|
|
|
35
|
|
|
*/ |
36
|
4 |
|
public function create(User $user) |
37
|
|
|
{ |
38
|
|
|
//Any manager can create a new job poster |
39
|
4 |
|
return $user->user_role->name == 'manager'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Determine whether the user can update the job poster. |
44
|
|
|
* |
45
|
|
|
* @param \App\Models\User $user |
|
|
|
|
46
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
47
|
|
|
* @return mixed |
|
|
|
|
48
|
|
|
*/ |
49
|
4 |
|
public function update(User $user, JobPoster $jobPoster) |
50
|
|
|
{ |
51
|
|
|
//Only managers can edit jobs, and only their own |
52
|
4 |
|
return $user->user_role->name == 'manager' && |
53
|
4 |
|
$jobPoster->manager->user->id == $user->id; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Determine whether the user can delete the job poster. |
58
|
|
|
* |
59
|
|
|
* @param \App\Models\User $user |
|
|
|
|
60
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
61
|
|
|
* @return mixed |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
public function delete(User $user, JobPoster $jobPoster) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
// |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Determine whether the user can restore the job poster. |
70
|
|
|
* |
71
|
|
|
* @param \App\Models\User $user |
|
|
|
|
72
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
73
|
|
|
* @return mixed |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
public function restore(User $user, JobPoster $jobPoster) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
// |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Determine whether the user can permanently delete the job poster. |
82
|
|
|
* |
83
|
|
|
* @param \App\Models\User $user |
|
|
|
|
84
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
85
|
|
|
* @return mixed |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function forceDelete(User $user, JobPoster $jobPoster) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
// |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|