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

UserPolicy::manage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 1
crap 1
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