aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Users/Authority.php
blob: e8aef0049b59a5c80db8827b8b45430b4cba3032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace JsonApi\Routes\Users;

use User;

class Authority
{
    /**
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    public static function canIndexUsers(User $user)
    {
        return true;
    }

    /**
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    public static function canShowUser(User $user, User $userToShow)
    {
        if ($userToShow->id === $user->id || $GLOBALS['perm']->have_perm('root', $user->id)) {
            return true;
        }

        if ($userToShow->locked) {
            return false;
        }

        if (get_visibility_by_id($userToShow->id)) {
            return true;
        }

        return false;
    }

    public static function canEditUser(User $user, User $userToShow)
    {
        return $user->id === $userToShow->id;
    }

    /**
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    public static function canDeleteUser(User $user, User $userToDelete)
    {
        if (!$GLOBALS['perm']->have_perm('root', $user->id)) {
            return false;
        }

        if ($userToDelete->id === $user->id) {
            return false;
        }

        return true;
    }
}