Bolt\Users::isAllowed PHP Method

isAllowed() public method

Apart from the route-based rules defined in permissions.yml, the following special cases are available: "overview:$contenttype" - view the overview for the content type. Alias for "contenttype:$contenttype:view". "contenttype:$contenttype", "contenttype:$contenttype:view", "contenttype:$contenttype:view:$id" - View any item or a particular item of the specified content type. "contenttype:$contenttype:edit", "contenttype:$contenttype:edit:$id" - Edit any item or a particular item of the specified content type. "contenttype:$contenttype:create" - Create a new item of the specified content type. (It doesn't make sense to provide this permission on a per-item basis, for obvious reasons) "contenttype:$contenttype:change-ownership", "contenttype:$contenttype:change-ownership:$id" - Change the ownership of the specified content type or item.
public isAllowed ( string $what, string $contenttype = null, integer $contentid = null ) : boolean
$what string The desired permission, as elaborated upon above.
$contenttype string
$contentid integer
return boolean TRUE if the permission is granted, FALSE if denied.
    public function isAllowed($what, $contenttype = null, $contentid = null)
    {
        $user = $this->getCurrentUser();
        return $this->app['permissions']->isAllowed($what, $user, $contenttype, $contentid);
    }

Usage Example

Example #1
0
 /**
  * When redirecting to the backend dashboard (while logged in),
  * if the user does not have access change the redirect to the homepage.
  *
  * @param \Symfony\Component\HttpFoundation\RedirectResponse $response
  */
 protected function handleNoBackendAccess(RedirectResponse $response)
 {
     $authCookie = $this->session->get('authentication');
     if (!$this->authentication->isValidSession((string) $authCookie)) {
         return;
     }
     $dashboardPath = $this->urlGenerator->generate('dashboard');
     $dashboardAccess = $this->users->isAllowed('dashboard');
     if ($response->getTargetUrl() === $dashboardPath && !$dashboardAccess) {
         $this->session->getFlashBag()->clear();
         $response->setTargetUrl($this->urlGenerator->generate('homepage'));
     }
 }
All Usage Examples Of Bolt\Users::isAllowed