-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPermissionManager.class.php
More file actions
54 lines (47 loc) · 1.39 KB
/
PermissionManager.class.php
File metadata and controls
54 lines (47 loc) · 1.39 KB
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
<?php
/**
* This class handles permissions of users in groups
*/
abstract class PermissionManager
{
private $DB;
private $userID;
/**
* Check if the provided role is allowed to perform the action associated with the permission key
*/
//TODO: Delete or reimplement this method
static function check ($context, $permissionKey, $role) {
if ($context == "team")
return teamPermission::check($permissionKey, $role);
else if ($context == "system")
return systemPermission::check($permissionKey, $role);
}
//Checks if the given user is an admin
public static function isAdmin($userID) {
$DB = Flight::DB();
$parameters = Array();
$parameters[":userID"] = $userID;
$result = $DB->getRow("SELECT * FROM " . ADMIN_TABLE . " WHERE UserID = :userID", $parameters);
return is_array($result);
}
//Checks if a the left user has a higher level than right user
public static function isSuperior($userID1, $userID2) {
if (self::isAdmin($userID1)) {
if (!self::isDeleteable($userID1)) {
return true;
} else {
return !self::isAdmin($userID2);
}
} else {
return false;
}
}
//Checks if an administrator is deletable
public static function isDeleteable($userID) {
$DB = Flight::DB();
$parameters = Array();
$parameters[":userID"] = $userID;
return array_values($DB->getRow("SELECT Deleteable FROM " . ADMIN_TABLE . " WHERE UserID = :userID",$parameters))[0];
}
}
?>