Completed
Pull Request — master (#134)
by
unknown
05:19
created

UserPolicy::show()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 6
loc 6
ccs 0
cts 4
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Policies;
4
5
use App\User;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
8
class UserPolicy
9
{
10
    use HandlesAuthorization;
11
    
12
    /**
13
     * Determine whether the user can view the list of users.
14
     *
15
     * @param  \App\User  $user
16
     * @return mixed
17
     */
18
    public function index(User $user)
19
    {
20
        return $user->isAdmin();
21
    }
22
    
23
    /**
24
     * Determine whether the user can view the create users page.
25
     *
26
     * @param  \App\User  $user
27
     * @return boolean
28
     */
29
    public function create(User $user)
30
    {
31
        return $user->isAdmin();
32
    }
33
    
34
    /**
35
     * Determine whether the user can create a user.
36
     *
37
     * @param  \App\User  $user
38
     * @return boolean
39
     */
40
    public function store(User $user)
41
    {
42
        return $user->isAdmin();
43
    }
44
45
    /**
46
     * Determine whether the user can view the user.
47
     *
48
     * @param  \App\User  $user the current user
49
     * @param  \App\User  $user2 the user to be viewed
50
     * @return boolean
51
     */
52 View Code Duplication
    public function show(User $user, User $user2)
53
    {
54
        if ($user->isAdmin())
55
            return true;
56
        else
57
            return $user->isUser() && $user->id === $user2->id;
58
    }
59
    
60
    /**
61
     * Determine whether the user can view the edit page for a user.
62
     *
63
     * @param  \App\User  $user
64
     * @param  \App\User  $user2 the user to be edited
65
     * @return mixed
66
     */
67 View Code Duplication
    public function edit(User $user, User $user2)
68
    {
69
        if ($user->isAdmin())
70
            return true;
71
        else
72
            return $user->isUser() && $user->id === $user2->id;
73
    }
74
75
    /**
76
     * Determine whether the user can update user2.
77
     *
78
     * @param  \App\User  $user
79
     * @param  \App\User  $user2
80
     * @return boolean
81
     */
82 View Code Duplication
    public function update(User $user, User $user2)
83
    {
84
        if ($user->isAdmin())
85
            return true;
86
        else
87
            return $user->isUser() && $user->id === $user2->id;
88
    }
89
    
90
    /**
91
     * Determine whether the user can update a user's role.
92
     *
93
     * @param  \App\User  $user
94
     * @return boolean
95
     */
96
    public function updateRole(User $user)
97
    {
98
        return $user->isAdmin();
99
    }
100
101
    /**
102
     * Determine whether the user can delete the user.
103
     *
104
     * @param  \App\User  $user
105
     * @return boolean
106
     */
107
    public function destroy(User $user)
108
    {
109
        return $user->isAdmin();
110
    }
111
    
112
    /**
113
     * Determine whether the user can restore the user.
114
     *
115
     * @param  \App\User  $user
116
     * @return mixed
117
     */
118
    public function restore(User $user)
119
    {
120
        return $user->isAdmin();
121
    }
122
}
123