Completed
Push — master ( 26ea5b...d16af1 )
by Patrick
01:54
created

ProfilesAdminAPI::validateIsAdmin()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 2
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
class ProfilesAdminAPI extends Http\Rest\RestAPI
3
{
4
    protected $user;
5
6
    public function validateIsAdmin($request, $nonFatal = false)
7
    {
8
        $this->user = $request->getAttribute('user');
9
        if($this->user === false)
10
        {
11
            throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED);
12
        }
13
        if(!$this->user->isInGroupNamed('LDAPAdmins'))
14
        {
15
            if($nonFatal)
16
            {
17
                return false;
18
            }
19
            throw new Exception('Must be Admin', \Http\Rest\ACCESS_DENIED);
20
        }
21
        return true;
22
    }
23
}
24