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