Add UserPrivilege enum, provide better 404 information
This commit is contained in:
parent
25929d82f4
commit
d0475b22c1
15
api/BusinessLogic/Security/UserPrivilege.php
Normal file
15
api/BusinessLogic/Security/UserPrivilege.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: mkoch
|
||||||
|
* Date: 3/12/2017
|
||||||
|
* Time: 12:11 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BusinessLogic\Security;
|
||||||
|
|
||||||
|
|
||||||
|
class UserPrivilege {
|
||||||
|
const CAN_VIEW_TICKETS = 'can_view_tickets';
|
||||||
|
const CAN_REPLY_TO_TICKETS = 'can_reply_tickets';
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace BusinessLogic\Tickets;
|
|||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Security\UserContext;
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\Security\UserPrivilege;
|
||||||
use DataAccess\Categories\CategoryGateway;
|
use DataAccess\Categories\CategoryGateway;
|
||||||
use DataAccess\Security\UserGateway;
|
use DataAccess\Security\UserGateway;
|
||||||
|
|
||||||
@ -34,8 +35,8 @@ class Autoassigner {
|
|||||||
foreach ($potentialUsers as $potentialUser) {
|
foreach ($potentialUsers as $potentialUser) {
|
||||||
if ($potentialUser->admin ||
|
if ($potentialUser->admin ||
|
||||||
(in_array($categoryId, $potentialUser->categories) &&
|
(in_array($categoryId, $potentialUser->categories) &&
|
||||||
in_array('can_view_tickets', $potentialUser->permissions) &&
|
in_array(UserPrivilege::CAN_VIEW_TICKETS, $potentialUser->permissions) &&
|
||||||
in_array('can_reply_tickets', $potentialUser->permissions))) {
|
in_array(UserPrivilege::CAN_REPLY_TO_TICKETS, $potentialUser->permissions))) {
|
||||||
return $potentialUser;
|
return $potentialUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,10 @@ register_shutdown_function('fatalErrorShutdownHandler');
|
|||||||
$userContext = null;
|
$userContext = null;
|
||||||
|
|
||||||
function handle404() {
|
function handle404() {
|
||||||
http_response_code(404);
|
print output(array(
|
||||||
print json_encode('404 found');
|
'message' => "The endpoint '{$_SERVER['REQUEST_URI']}' was not found. Double-check your request and submit again.",
|
||||||
|
'uri' => $_SERVER['REQUEST_URI']
|
||||||
|
), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
function before() {
|
function before() {
|
||||||
@ -21,6 +23,8 @@ function before() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assertApiIsEnabled() {
|
function assertApiIsEnabled() {
|
||||||
|
global $applicationContext;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,13 +38,7 @@ function buildUserContext($xAuthToken) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) {
|
function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) {
|
||||||
if ($errorNumber === E_WARNING) {
|
exceptionHandler(new Exception(sprintf("%s:%d\n\n%s", $errorFile, $errorLine, $errorMessage)));
|
||||||
//-- TODO log a warning
|
|
||||||
} elseif ($errorNumber === E_NOTICE || $errorNumber === E_USER_NOTICE) {
|
|
||||||
//-- TODO log an info
|
|
||||||
} else {
|
|
||||||
exceptionHandler(new Exception(sprintf("%s:%d\n\n%s", $errorFile, $errorLine, $errorMessage)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,15 +51,12 @@ function exceptionHandler($exception) {
|
|||||||
$castedException = $exception;
|
$castedException = $exception;
|
||||||
|
|
||||||
print_error($castedException->title, $castedException->getMessage(), $castedException->httpResponseCode);
|
print_error($castedException->title, $castedException->getMessage(), $castedException->httpResponseCode);
|
||||||
|
} elseif (exceptionIsOfType($exception, \Core\Exceptions\SQLException::class)) {
|
||||||
|
/* @var $castedException \Core\Exceptions\SQLException */
|
||||||
|
$castedException = $exception;
|
||||||
|
print_error("Fought an uncaught SQL exception", sprintf("%s\n\n%s", $castedException->failingQuery, $exception->getTraceAsString()));
|
||||||
} else {
|
} else {
|
||||||
if (exceptionIsOfType($exception, \Core\Exceptions\SQLException::class)) {
|
print_error("Fought an uncaught exception of type " . get_class($exception), sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
||||||
/* @var $castedException \Core\Exceptions\SQLException */
|
|
||||||
$castedException = $exception;
|
|
||||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $castedException->failingQuery, $exception->getTraceAsString()));
|
|
||||||
} else {
|
|
||||||
print_error("Fought an uncaught exception of type " . get_class($exception), sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// Log more stuff to logging table if possible; we'll catch any exceptions from this
|
// Log more stuff to logging table if possible; we'll catch any exceptions from this
|
||||||
die();
|
die();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user