Passed
Push — dev6 ( 77ef26...6e2ff7 )
by Ron
16:42
created

UserPolicy::view()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 0
c 2
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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 HandlesAuthorization;
14
    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...
15
16
    /**
17 22
     * Determine whether the user can create models
18
     */
19 22
    public function create(User $user)
20
    {
21 22
        return $this->checkPermission($user, 'Manage Users');
22 22
    }
23
24 22
    /**
25
     * Determine whether the user can update the user profile
26 22
     */
27
    public function update(User $user, User $model)
28 11
    {
29
        if($this->checkPermission($user, 'Manage Users'))
30 11
        {
31
            //  If they user has permission to Manage Users, they cannot manage anyone with a higher role than themselves
32
            if($user->role_id > $model->role_id)
33
            {
34
                return Response::deny('You cannot modify a user with higher permissions than yourself');
35
            }
36
37
            return true;
38
        }
39
40
        return $user->user_id === $model->user_id;
41
    }
42
43 4
    /**
44
     * Determine whether the user can delete the model
45 4
     */
46
    public function delete(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function delete(User $user, /** @scrutinizer ignore-unused */ User $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        $this->checkPermission($user, 'Manage Users');
49
    }
50
51 6
    /**
52
     * Determine whether the user can restore the model
53 6
     */
54
    public function restore(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public function restore(User $user, /** @scrutinizer ignore-unused */ User $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        $this->checkPermission($user, 'Manage Users');
57
    }
58
}
59