Add roles/permissions for API keys, add "os" column to machines
parent
71f109470c
commit
9aac47f516
Binary file not shown.
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class Roles {
|
||||
|
||||
const ROLE_VIEWBYID = 1;
|
||||
const ROLE_ADDEDIT = 2;
|
||||
const ROLE_ADDHIST = 3;
|
||||
const ROLE_VIEWBULK = 4;
|
||||
|
||||
public static function has($apikey, $roleid) {
|
||||
global $database;
|
||||
return $database->has('permissions', ["AND" => ['apikey' => $apikey, 'roleid' => $roleid]]) === true;
|
||||
}
|
||||
|
||||
public static function add($apikey, $roleid) {
|
||||
global $database;
|
||||
if (!$database->has('apikeys', ['apikey' => $apikey])) {
|
||||
throw new Exception("No such API key found.");
|
||||
}
|
||||
if (!$database->has('roles', ['roleid' => $roleid])) {
|
||||
throw new Exception("No such role ID found.");
|
||||
}
|
||||
if (!$database->has('permissions', ["AND" => ['apikey' => $apikey, 'roleid' => $roleid]])) {
|
||||
$database->insert('permissions', ['apikey' => $apikey, 'roleid' => $roleid]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function remove($apikey, $roleid) {
|
||||
global $database;
|
||||
if (!$database->has('apikeys', ['apikey' => $apikey])) {
|
||||
throw new Exception("No such API key found.");
|
||||
}
|
||||
if (!$database->has('roles', ['roleid' => $roleid])) {
|
||||
throw new Exception("No such role ID found.");
|
||||
}
|
||||
$database->delete('permissions', ["AND" => ['apikey' => $apikey, 'roleid' => $roleid]]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue