Grav\Plugin\Admin\AdminBaseController::authorizeTask PHP Method

authorizeTask() protected method

Checks if the user is allowed to perform the given task with its associated permissions
protected authorizeTask ( string $task = '', array $permissions = [] ) : boolean
$task string The task to execute
$permissions array The permissions given
return boolean True if authorized. False if not.
    protected function authorizeTask($task = '', $permissions = [])
    {
        if (!$this->admin->authorize($permissions)) {
            if ($this->grav['uri']->extension() === 'json') {
                $this->admin->json_response = ['status' => 'unauthorized', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'];
            } else {
                $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.', 'error');
            }
            return false;
        }
        return true;
    }