AssessmentPlanNotificationPolicy   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 8
dl 0
loc 56
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A delete() 0 5 2
A update() 0 5 2
A view() 0 5 2
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\User;
6
use App\Models\AssessmentPlanNotification;
7
use App\Policies\BasePolicy;
8
9
class AssessmentPlanNotificationPolicy extends BasePolicy
10
{
11
12
    /**
13
     * Determine whether the user can view the AssessmentPlanNotification.
14
     *
15
     * @param  \App\Models\User       $user
16
     * @param  \App\Models\AssessmentPlanNotification $notification
17
     * @return boolean
18
     */
19
    public function view(User $user, AssessmentPlanNotification $notification): bool
20
    {
21
        // Managers can view notifications tied to Jobs they own.
22
        return $user->isManager() &&
23
            $notification->job_poster->manager->user_id === $user->id;
24
    }
25
26
    /**
27
     * Determine whether the user can create AssessmentPlanNotifications.
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 AssessmentPlanNotification, but only for job posters they own.
35
        return $user->isManager();
36
    }
37
38
    /**
39
     * Determine whether the user can update the AssessmentPlanNotification
40
     *
41
     * @param  \App\Models\User       $user
42
     * @param  \App\Models\AssessmentPlanNotification $notification
43
     * @return boolean
44
     */
45
    public function update(User $user, AssessmentPlanNotification $notification): bool
46
    {
47
        // Managers can edit notifications tied to Jobs they own.
48
        return $user->isManager() &&
49
            $notification->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       User object making the request.
56
     * @param \App\Models\AssessmentPlanNotification $notification Job Poster object being acted upon.
57
     *
58
     * @return boolean
59
     */
60
    public function delete(User $user, AssessmentPlanNotification $notification) : bool
61
    {
62
        // Managers can delete notifications tied to Jobs they own.
63
        return $user->isManager() &&
64
            $notification->job_poster->manager->user_id === $user->id;
65
    }
66
}
67