/**
  * Checks if the provided user is authorized for the request
  * @param array $user The user to check the authorization of. If empty the
  *  user in the session will be used
  * @return bool `true` if the user is authorized, otherwise `false`
  * @uses MeCms\Controller\AppController::isAuthorized()
  * @uses MeCms\Controller\Component\AuthComponent::isGroup()
  */
 public function isAuthorized($user = null)
 {
     //Only admins can delete videos categories
     if ($this->request->isDelete()) {
         return $this->Auth->isGroup('admin');
     }
     //Admins and managers can access other actions
     return parent::isAuthorized($user);
 }
 /**
  * Called before the controller action.
  * You can use this method to perform logic that needs to happen before
  *  each controller action.
  * @param \Cake\Event\Event $event An Event instance
  * @return void
  * @uses MeCms\Controller\AppController::beforeFilter()
  * @uses MeCms\Model\Table\VideosCategoriesTable::getList()
  * @uses MeCms\Model\Table\VideosCategoriesTable::getTreeList()
  * @uses MeCms\Model\Table\UsersTable::getActiveList()
  * @uses MeCms\Model\Table\UsersTable::getList()
  */
 public function beforeFilter(\Cake\Event\Event $event)
 {
     parent::beforeFilter($event);
     if ($this->request->isIndex()) {
         $categories = $this->Videos->Categories->getList();
         $users = $this->Videos->Users->getList();
     } elseif ($this->request->isAction(['add', 'edit'])) {
         $categories = $this->Videos->Categories->getTreeList();
         $users = $this->Videos->Users->getActiveList();
     }
     //Checks for categories
     if (isset($categories) && empty($categories)) {
         $this->Flash->alert(__d('me_cms', 'You must first create a category'));
         $this->redirect(['controller' => 'VideosCategories', 'action' => 'index']);
     }
     if (!empty($categories)) {
         $this->set(compact('categories'));
     }
     if (!empty($users)) {
         $this->set(compact('users'));
     }
 }
 /**
  * Called before the controller action.
  * You can use this method to perform logic that needs to happen before
  *  each controller action.
  * @param \Cake\Event\Event $event An Event instance
  * @return void
  * @see http://api.cakephp.org/3.3/class-Cake.Controller.Controller.html#_beforeFilter
  * @uses MeCms\Controller\AppController::beforeFilter()
  */
 public function beforeFilter(\Cake\Event\Event $event)
 {
     parent::beforeFilter($event);
     $this->Auth->deny('preview');
 }