protected function saveAcls($acls, $role) { foreach ($acls as $acl) { $acl = explode("/", $acl); $dbAcl = new Acl(); $dbAcl->setIdRole($role); $dbAcl->setController($acl[0]); $dbAcl->setAction($acl[1]); $dbAcl->save(); } }
public static function set($group, $key, $allowed) { if ($acl = self::get($group, $key)) { $acl->allowed = $allowed; } else { $acl = new Acl($group, $key, $allowed); } $acl->save(); }
/** * Get the ACL that can be used to make things read only for everyone. * * @return \Acl */ public function getReadOnlyAcl() { $acl_id = \GO::config()->get_setting('readonly_acl_id'); $acl = Acl::model()->findByPk($acl_id); if (!$acl) { $acl = new Acl(); $acl->description = 'readonly'; $acl->save(); $acl->addGroup(\GO::config()->group_everyone, Acl::READ_PERMISSION); \GO::config()->save_setting('readonly_acl_id', $acl->id); } return $acl; }
public function updateAcl($new_job, $new_acl) { foreach ($new_acl as $nk => $nv) { if (isset($nv['add']) && $nv['add'] == 'on') { $new_acl[$nk]['add'] = 1; } else { $new_acl[$nk]['add'] = null; } if (isset($nv['edit']) && $nv['edit'] == 'on') { $new_acl[$nk]['edit'] = 1; } else { $new_acl[$nk]['edit'] = null; } if (isset($nv['remove']) && $nv['remove'] == 'on') { $new_acl[$nk]['remove'] = 1; } else { $new_acl[$nk]['remove'] = null; } } $acls = $this->getAcls(new Criteria()); $old = array(); foreach ($acls as $acl) { $old['job_' . $acl->getJobId()] = array('add' => $acl->getAddPriv(), 'edit' => $acl->getEditPriv(), 'remove' => $acl->getRemovePriv()); } $removed = array_diff_key($old, $new_job); $inserted = array_diff_key($new_job, $old); $nc = array_intersect_key($new_acl, $new_job); $vc = array(); foreach ($old as $k => $v) { if (!isset($new_acl[$k]) && ($old[$k]['add'] == '1' || $old[$k]['edit'] == '1' || $old[$k]['remove'] == '1')) { $vc[$k] = array('add' => null, 'edit' => null, 'remove' => null); } if (isset($new_acl[$k])) { if ($new_acl[$k]['add'] != $old[$k]['add'] || $new_acl[$k]['edit'] != $old[$k]['edit'] || $new_acl[$k]['remove'] != $old[$k]['remove']) { $vc[$k] = array('add' => $new_acl[$k]['add'], 'edit' => $new_acl[$k]['edit'], 'remove' => $new_acl[$k]['remove']); } } } if ($inserted) { foreach ($inserted as $k => $v) { $job_id = preg_split('/_/', $k); $job_id = $job_id[1]; $acl = new Acl(); $acl->setUserGroup($this); $acl->setJobId($job_id); if (isset($new_acl[$k])) { if (isset($new_acl[$k]['add'])) { $acl->setAddPriv($new_acl[$k]['add']); } if (isset($new_acl[$k]['edit'])) { $acl->setEditPriv($new_acl[$k]['edit']); } if (isset($new_acl[$k]['remove'])) { $acl->setRemovePriv($new_acl[$k]['remove']); } } $acl->save(); } } if ($removed) { foreach ($removed as $k => $v) { $job_id = preg_split('/_/', $k); $job_id = $job_id[1]; $acl = AclPeer::retrieveByPK($this->getId(), $job_id); $acl->delete(); } } if ($vc) { foreach ($vc as $k => $v) { $job_id = preg_split('/_/', $k); $job_id = $job_id[1]; $acl = AclPeer::retrieveByPK($this->getId(), $job_id); $acl->setAddPriv($v['add']); $acl->setEditPriv($v['edit']); $acl->setRemovePriv($v['remove']); $acl->save(); } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Acl(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Acl'])) { $model->attributes = $_POST['Acl']; if ($model->save()) { Yii::app()->user->setFlash('success', 'Saved successfully'); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
protected function on_after_save($was_new) { if ($this->_attr !== null) { $res_attr = array(); foreach ($this->_attr as $attrs) { foreach ($attrs as $attr) { if ($attr['v'] === null) { if ($attr['i'] != 0) { SRecord::remove_by_id('Attribute', $attr['i']); } } else { $attr['v']->node_id = $this->id; if ($attr['v']->is_dirty()) { $attr['v']->save(); } if (!array_key_exists('n' . $attr['v']->name, $res_attr)) { $res_attr['n' . $attr['v']->name] = array(); } $res_attr['n' . $attr['v']->name]['n' . $attr['v']->lang] = array('i' => $attr['v']->id, 'v' => $attr['v']); } } } $this->_attr = $res_attr; $res_attr = null; } if ($this->_acl !== null) { $existing_acl = array(); foreach ($this->acl as $acl) { $existing_acl[urlencode($acl->action) . ':' . urlencode($acl->ident)] = true; if (!array_key_exists($acl->action, $this->_acl) || !array_key_exists($this->_acl[$acl->action], $acl->ident) || !$this->_acl[$acl->action][$acl->ident]) { $acl->remove(); } } foreach ($this->_acl as $action) { foreach ($this->_acl[$action] as $ident) { if ($this->_acl[$action][$ident] && !array_key_exists(urlencode($action) . ':' . urlencode($ident))) { $acl = new Acl(); $acl->node_id = $this->id; $acl->action = $action; $acl->ident = $ident; $acl->save(); } } } } $path = CMS . "modules/{$this->type}/model.php"; if (is_readable($path)) { require_once $path; $class_name = Cms::capitalize_words($this->type); if (is_callable(array($class_name, '_saved'))) { call_user_func(array($class_name, '_saved'), $this, $was_new); } } }