public function addAjax() 
    {
        $this->request->allowMethod(['ajax']);
        $data['group_or_user'] = $this->request->data['group_or_user'];
        $data['group_or_user_id'] = $this->request->data['group_or_user_id'];
        $permissions = json_decode($this->request->data['permissions']);
        
        foreach($permissions as $permission) {
            $data['permission_id'] = $permission->id;
            $data['allow'] = $permission->allow;
            
            $userGroupPermission = $this->UserGroupPermission->findUserGroupPermission(
                    ['id'], $data['group_or_user_id'], $data['group_or_user'], $data['permission_id']
                )->first();
            
            if(!is_null($userGroupPermission)) {
                $this->UserGroupPermission->get($userGroupPermission->id);
                $userGroupPermission->allow = $data['allow'];
            }else {
                $userGroupPermission = $this->UserGroupPermission->newEntity();
                $userGroupPermission = $this->UserGroupPermission->patchEntity($userGroupPermission, $data);
            }
            
            $this->UserGroupPermission->save($userGroupPermission);
        }
        
        $this->Flash->success(__('The user group permission has been updated.'));
        
        $this->set(compact('response'));
        $this->set('_serialize', ['response']);
        $this->render('Acl.Ajax/ajax_response', false);
    }