Properly handle if the API is disabled

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent d0475b22c1
commit 6af93506f1

@ -9,6 +9,7 @@ use BusinessLogic\Emails\EmailTemplateRetriever;
use BusinessLogic\Emails\MailgunEmailSender; use BusinessLogic\Emails\MailgunEmailSender;
use BusinessLogic\Security\BanRetriever; use BusinessLogic\Security\BanRetriever;
use BusinessLogic\Security\UserContextBuilder; use BusinessLogic\Security\UserContextBuilder;
use BusinessLogic\Settings\ApiChecker;
use BusinessLogic\Tickets\Autoassigner; use BusinessLogic\Tickets\Autoassigner;
use BusinessLogic\Tickets\TicketRetriever; use BusinessLogic\Tickets\TicketRetriever;
use BusinessLogic\Tickets\TicketCreator; use BusinessLogic\Tickets\TicketCreator;
@ -34,6 +35,9 @@ class ApplicationContext {
// Settings // Settings
$this->get[ModsForHeskSettingsGateway::class] = new ModsForHeskSettingsGateway(); $this->get[ModsForHeskSettingsGateway::class] = new ModsForHeskSettingsGateway();
// API Checker
$this->get[ApiChecker::class] = new ApiChecker($this->get[ModsForHeskSettingsGateway::class]);
// Verified Email Checker // Verified Email Checker
$this->get[VerifiedEmailGateway::class] = new VerifiedEmailGateway(); $this->get[VerifiedEmailGateway::class] = new VerifiedEmailGateway();
$this->get[VerifiedEmailChecker::class] = new VerifiedEmailChecker($this->get[VerifiedEmailGateway::class]); $this->get[VerifiedEmailChecker::class] = new VerifiedEmailChecker($this->get[VerifiedEmailGateway::class]);

@ -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 <?php
namespace Controllers\Category; namespace Controllers\Categories;
use BusinessLogic\Categories\CategoryRetriever; use BusinessLogic\Categories\CategoryRetriever;

@ -23,9 +23,17 @@ function before() {
} }
function assertApiIsEnabled() { 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) { function buildUserContext($xAuthToken) {
@ -83,8 +91,8 @@ Link::before('before');
Link::all(array( Link::all(array(
// Categories // Categories
'/v1/categories' => '\Controllers\Category\CategoryController::printAllCategories', '/v1/categories' => '\Controllers\Categories\CategoryController::printAllCategories',
'/v1/categories/{i}' => '\Controllers\Category\CategoryController', '/v1/categories/{i}' => '\Controllers\Categories\CategoryController',
// Tickets // Tickets
'/v1/tickets/{i}' => '\Controllers\Tickets\TicketController', '/v1/tickets/{i}' => '\Controllers\Tickets\TicketController',
'/v1/tickets' => '\Controllers\Tickets\TicketController', '/v1/tickets' => '\Controllers\Tickets\TicketController',

Loading…
Cancel
Save