diff --git a/api/BusinessLogic/Security/UserContext.php b/api/BusinessLogic/Security/UserContext.php index 30baf47b..27318d14 100644 --- a/api/BusinessLogic/Security/UserContext.php +++ b/api/BusinessLogic/Security/UserContext.php @@ -64,7 +64,7 @@ class UserContext { $userContext = new UserContext(); $userContext->id = $dataRow['id']; $userContext->username = $dataRow['user']; - $userContext->admin = $dataRow['isadmin']; + $userContext->admin = $dataRow['isadmin'] === '1'; $userContext->name = $dataRow['name']; $userContext->email = $dataRow['email']; $userContext->signature = $dataRow['signature']; diff --git a/api/BusinessLogic/Security/UserContextBuilder.php b/api/BusinessLogic/Security/UserContextBuilder.php index 064968c2..65c4972e 100644 --- a/api/BusinessLogic/Security/UserContextBuilder.php +++ b/api/BusinessLogic/Security/UserContextBuilder.php @@ -33,7 +33,7 @@ class UserContextBuilder { throw new InvalidAuthenticationTokenException(); } - return $this->fromDataRow($userRow); + return UserContext::fromDataRow($userRow); } /** diff --git a/api/BusinessLogic/Tickets/Ticket.php b/api/BusinessLogic/Tickets/Ticket.php index 73442104..2d7ba879 100644 --- a/api/BusinessLogic/Tickets/Ticket.php +++ b/api/BusinessLogic/Tickets/Ticket.php @@ -42,6 +42,10 @@ class Ticket { $attachments = explode(',', $row['attachments']); $attachmentArray = array(); foreach ($attachments as $attachment) { + if (trim($attachment) === '') { + continue; + } + $attachmentRow = explode('#', $attachment); $attachmentModel = new Attachment(); diff --git a/api/DataAccess/Files/FileReader.php b/api/DataAccess/Files/FileReader.php index 296c966d..c4ef2eb0 100644 --- a/api/DataAccess/Files/FileReader.php +++ b/api/DataAccess/Files/FileReader.php @@ -3,6 +3,8 @@ namespace DataAccess\Files; +use BusinessLogic\Exceptions\ApiFriendlyException; + class FileReader { /** * @param $name string - The file name (including extension) @@ -13,6 +15,11 @@ class FileReader { function readFromFile($name, $folder) { // __DIR__ === '/{ROOT}/api/DataAccess/Files $location = __DIR__ . "/../../../{$folder}/{$name}"; + + if (!file_exists($location)) { + throw new ApiFriendlyException("The file '{$name}' does not exist on the server", "File Not Found", 404); + } + $fileContents = file_get_contents($location); if ($fileContents === false) {