Ejemplo n.º 1
0
 /**
  * Toggle permission action.
  *
  * @param int $acoId
  * @param int $aroId
  * @return \Cake\Network\Response|null
  */
 public function toggle($acoId, $aroId)
 {
     if (!$this->request->is('ajax')) {
         return $this->redirect(['action' => 'permissions']);
     }
     $aro = $this->_Permissions->Aros->find()->select(['id', 'lft', 'rght', 'model', 'alias', 'foreign_key'])->where(['id' => $aroId])->first()->toArray();
     $path = $this->_Permissions->Acos->find('path', ['for' => $acoId]);
     $path = join('/', collection($path)->extract('alias')->toArray());
     $value = !$this->_Permissions->check($aro, $path);
     $isAllow = $this->_Permissions->allow($aro, $path, '*', $value ? 1 : -1);
     $this->set('_serialize', false);
     $this->set(compact('value', 'acoId', 'aroId', 'isAllow'));
 }