Properly handle if the API is disabled
This commit is contained in:
parent
d0475b22c1
commit
6af93506f1
@ -9,6 +9,7 @@ use BusinessLogic\Emails\EmailTemplateRetriever;
|
||||
use BusinessLogic\Emails\MailgunEmailSender;
|
||||
use BusinessLogic\Security\BanRetriever;
|
||||
use BusinessLogic\Security\UserContextBuilder;
|
||||
use BusinessLogic\Settings\ApiChecker;
|
||||
use BusinessLogic\Tickets\Autoassigner;
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
use BusinessLogic\Tickets\TicketCreator;
|
||||
@ -34,6 +35,9 @@ class ApplicationContext {
|
||||
// Settings
|
||||
$this->get[ModsForHeskSettingsGateway::class] = new ModsForHeskSettingsGateway();
|
||||
|
||||
// API Checker
|
||||
$this->get[ApiChecker::class] = new ApiChecker($this->get[ModsForHeskSettingsGateway::class]);
|
||||
|
||||
// Verified Email Checker
|
||||
$this->get[VerifiedEmailGateway::class] = new VerifiedEmailGateway();
|
||||
$this->get[VerifiedEmailChecker::class] = new VerifiedEmailChecker($this->get[VerifiedEmailGateway::class]);
|
||||
|
21
api/BusinessLogic/Settings/ApiChecker.php
Normal file
21
api/BusinessLogic/Settings/ApiChecker.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Settings;
|
||||
|
||||
|
||||
use DataAccess\Settings\ModsForHeskSettingsGateway;
|
||||
|
||||
class ApiChecker {
|
||||
/* @var $modsForHeskSettingsGateway ModsForHeskSettingsGateway */
|
||||
private $modsForHeskSettingsGateway;
|
||||
|
||||
function __construct($modsForHeskSettingsGateway) {
|
||||
$this->modsForHeskSettingsGateway = $modsForHeskSettingsGateway;
|
||||
}
|
||||
|
||||
function isApiEnabled($heskSettings) {
|
||||
$modsForHeskSettings = $this->modsForHeskSettingsGateway->getAllSettings($heskSettings);
|
||||
|
||||
return intval($modsForHeskSettings['public_api']) === 1;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers\Category;
|
||||
namespace Controllers\Categories;
|
||||
|
||||
use BusinessLogic\Categories\CategoryRetriever;
|
||||
|
||||
|
@ -23,9 +23,17 @@ function before() {
|
||||
}
|
||||
|
||||
function assertApiIsEnabled() {
|
||||
global $applicationContext;
|
||||
global $applicationContext, $hesk_settings;
|
||||
|
||||
return true;
|
||||
/* @var $apiChecker \BusinessLogic\Settings\ApiChecker */
|
||||
$apiChecker = $applicationContext->get[\BusinessLogic\Settings\ApiChecker::class];
|
||||
|
||||
if (!$apiChecker->isApiEnabled($hesk_settings)) {
|
||||
http_response_code(404);
|
||||
die();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function buildUserContext($xAuthToken) {
|
||||
@ -83,8 +91,8 @@ Link::before('before');
|
||||
|
||||
Link::all(array(
|
||||
// Categories
|
||||
'/v1/categories' => '\Controllers\Category\CategoryController::printAllCategories',
|
||||
'/v1/categories/{i}' => '\Controllers\Category\CategoryController',
|
||||
'/v1/categories' => '\Controllers\Categories\CategoryController::printAllCategories',
|
||||
'/v1/categories/{i}' => '\Controllers\Categories\CategoryController',
|
||||
// Tickets
|
||||
'/v1/tickets/{i}' => '\Controllers\Tickets\TicketController',
|
||||
'/v1/tickets' => '\Controllers\Tickets\TicketController',
|
||||
|
Loading…
x
Reference in New Issue
Block a user