diff --git a/library/Director/Web/Controller/Extension/RestApi.php b/library/Director/Web/Controller/Extension/RestApi.php index 1c15cc9f..07006c4b 100644 --- a/library/Director/Web/Controller/Extension/RestApi.php +++ b/library/Director/Web/Controller/Extension/RestApi.php @@ -18,13 +18,17 @@ trait RestApi } } + protected function assertApiPermission() + { + if (! $this->hasPermission('director/api')) { + throw new AuthenticationException('You are not allowed to access this API'); + } + } + protected function checkForRestApiRequest() { if ($this->getRequest()->isApiRequest()) { - if (! $this->hasPermission('director/api')) { - throw new AuthenticationException('You are not allowed to access this API'); - } - + $this->assertApiPermission(); if (! $this->isApified()) { throw new NotFoundError('No such API endpoint found'); }