1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\RatingGuideQuestion; |
7
|
|
|
use App\Policies\BasePolicy; |
8
|
|
|
|
9
|
|
|
class RatingGuideQuestionPolicy extends BasePolicy |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Determine whether the user can view the RatingGuideQuestion. |
14
|
|
|
* |
15
|
|
|
* @param \App\Models\User $user |
|
|
|
|
16
|
|
|
* @param \App\Models\RatingGuideQuestion $question |
|
|
|
|
17
|
|
|
* @return boolean |
18
|
|
|
*/ |
19
|
|
|
public function view(User $user, RatingGuideQuestion $question): bool |
20
|
|
|
{ |
21
|
|
|
// Managers can view questions tied to Jobs they own. |
22
|
|
|
return $user->hasRole('manager') && |
23
|
|
|
$question->job_poster->manager->user_id === $user->id; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Determine whether the user can create RatingGuideQuestions. |
28
|
|
|
* |
29
|
|
|
* @param \App\Models\User $user |
|
|
|
|
30
|
|
|
* @return boolean |
31
|
|
|
*/ |
32
|
|
|
public function create(User $user): bool |
33
|
|
|
{ |
34
|
|
|
//Any manager can create a new RatingGuideQuestion, but only for jobs they own. |
|
|
|
|
35
|
|
|
return $user->hasRole('manager'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine whether the user can update the RatingGuideQuestion |
40
|
|
|
* |
41
|
|
|
* @param \App\Models\User $user |
|
|
|
|
42
|
|
|
* @param \App\Models\RatingGuideQuestion $question |
|
|
|
|
43
|
|
|
* @return boolean |
44
|
|
|
*/ |
45
|
|
|
public function update(User $user, RatingGuideQuestion $question): bool |
46
|
|
|
{ |
47
|
|
|
// Managers can edit questions tied to Jobs they own. |
48
|
|
|
return $user->hasRole('manager') && |
49
|
|
|
$question->job_poster->manager->user_id === $user->id; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Determine whether the user can delete the job poster. |
54
|
|
|
* |
55
|
|
|
* @param \App\Models\User $user |
|
|
|
|
56
|
|
|
* @param \App\Models\RatingGuideQuestion $question |
|
|
|
|
57
|
|
|
* |
58
|
|
|
* @return boolean |
59
|
|
|
*/ |
60
|
|
|
public function delete(User $user, RatingGuideQuestion $question) : bool |
61
|
|
|
{ |
62
|
|
|
// Managers can delete questions tied to Jobs they own. |
63
|
|
|
return $user->hasRole('manager') && |
64
|
|
|
$question->job_poster->manager->user_id === $user->id; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|