RestApi: allow to override permission check

This commit is contained in:
Thomas Gelf 2017-07-06 15:09:18 +02:00
parent e562d00a50
commit 475c84de1e
1 changed files with 8 additions and 4 deletions

View File

@ -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');
}