Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

UserPolicy::before()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.2
c 0
b 0
f 0
cc 4
eloc 3
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Policies;
13
14
use Illuminate\Auth\Access\HandlesAuthorization;
15
use Tinyissue\Model\User;
16
17
class UserPolicy
18
{
19
    use HandlesAuthorization;
20
21
    /**
22
     * @param User $user
23
     *
24
     * @return bool
25
     */
26
    public function before(User $user)
27
    {
28
        if ($user instanceof User && ($user->isAdmin() || $user->isManager())) {
29
            return true;
30
        }
31
    }
32
33
    /**
34
     * Determine if the given user can manages administrator area.
35
     *
36
     * @param User $loggedUser
37
     * @param User $user
38
     *
39
     * @return bool
40
     */
41
    public function viewName(User $loggedUser, User $user)
42
    {
43
        if (!$user->private || (int) $loggedUser->id === (int) $user->id) {
44
            return true;
45
        }
46
47
        return false;
48
    }
49
}
50