Completed
Push — master ( b8fc4b...08375c )
by Mohamed
10:19
created

UserPolicy::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Microboard\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 any models.
14
     *
15
     * @param  \App\User  $user
16
     * @return mixed
17
     */
18
    public function viewAny(User $user)
19
    {
20
        return $user->permissions()->contains('name', 'users-viewAny');
21
    }
22
23
    /**
24
     * Determine whether the user can view the model.
25
     *
26
     * @param  \App\User  $user
27
     * @param  \App\User  $model
28
     * @return mixed
29
     */
30
    public function view(User $user, User $model)
31
    {
32
        return $user->is($model) || $user->permissions()->contains('name', 'users-view');
33
    }
34
35
    /**
36
     * Determine whether the user can create models.
37
     *
38
     * @param  \App\User  $user
39
     * @return mixed
40
     */
41
    public function create(User $user)
42
    {
43
        return $user->permissions()->contains('name', 'users-create');
44
    }
45
46
    /**
47
     * Determine whether the user can update the model.
48
     *
49
     * @param  \App\User  $user
50
     * @param  \App\User  $model
51
     * @return mixed
52
     */
53
    public function update(User $user, User $model)
54
    {
55
        return $user->is($model) || $user->permissions()->contains('name', 'users-update');
56
    }
57
58
    /**
59
     * Determine whether the user can delete the model.
60
     *
61
     * @param  \App\User  $user
62
     * @param  \App\User  $model
63
     * @return mixed
64
     */
65
    public function delete(User $user, User $model)
66
    {
67
        return $user->isNot($model) ? $user->permissions()->contains('name', 'users-delete') : false;
68
    }
69
}
70