You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?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]]);
|
|
}
|
|
|
|
}
|