Passed
Push — dev6 ( b01572...e24a5d )
by Ron
19:01
created

UserPolicy::update()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.125

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 14
rs 10
ccs 2
cts 4
cp 0.5
cc 3
nc 3
nop 2
crap 4.125
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\User;
6
use App\Traits\AllowTrait;
7
8
use Illuminate\Auth\Access\Response;
9
use Illuminate\Auth\Access\HandlesAuthorization;
10
11
class UserPolicy
12
{
13
    use AllowTrait;
1 ignored issue
show
introduced by
The trait App\Traits\AllowTrait requires some properties which are not provided by App\Policies\UserPolicy: $role_id, $username, $allow
Loading history...
14
    use HandlesAuthorization;
15
16
    public function manage(User $user)
17 22
    {
18
        return $this->checkPermission($user, 'Manage Users');
19 22
    }
20
21 22
    /**
22 22
     * Determine whether the user can create models
23
     */
24 22
    public function create(User $user)
25
    {
26 22
        return $this->checkPermission($user, 'Manage Users');
27
    }
28 11
29
    /**
30 11
     * Determine whether the user can update the user profile
31
     */
32
    public function update(User $user, User $model)
33
    {
34
        if($this->checkPermission($user, 'Manage Users'))
35
        {
36
            //  If they user has permission to Manage Users, they cannot manage anyone with a higher role than themselves
37
            if($user->role_id > $model->role_id)
38
            {
39
                return Response::deny('You cannot modify a user with higher permissions than yourself');
40
            }
41
42
            return true;
43 4
        }
44
45 4
        return $user->user_id === $model->user_id;
46
    }
47
}
48