/** * Set a new ACL for this model. You need to save the model after calling this * function. * * @param string $user_id * @return \GO\Base\Model\Acl */ public function setNewAcl($user_id = 0) { if ($this->aclField() === false) { throw new \Exception('Can not create a new ACL for an object that has no ACL field'); } if (!$user_id) { $user_id = GO::user() ? GO::user()->id : 1; } $acl = new \GO\Base\Model\Acl(); $acl->description = $this->tableName() . '.' . $this->aclField(); $acl->user_id = $user_id; if (!$acl->save()) { throw new \Exception("Could not save ACL: " . var_export($this->getValidationErrors(), true)); } $this->{$this->aclField()} = $acl->id; return $acl; }
protected function actionGetNewAcl($params) { $acl = new \GO\Base\Model\Acl(); $acl->user_id = isset($params['user_id']) ? $params['user_id'] : \GO::user()->id; $acl->description = $params['description']; $acl->save(); echo $acl->id; }
/** * Check if the acl for the finance does exist. * If not, then create a new acl and return it. * * @return \GO\Base\Model\Acl */ public static function getFinanceAcl() { $financeAclID = \GO::config()->get_setting('projects2_finance_acl'); if (!empty($financeAclID)) { $financeAcl = \GO\Base\Model\Acl::model()->findByPk($financeAclID); } if (empty($financeAcl)) { $financeAcl = new \GO\Base\Model\Acl(); $financeAcl->user_id = 1; $financeAcl->description = 'Finance access for Projects 2'; if ($financeAcl->save()) { \GO::config()->save_setting('projects2_finance_acl', $financeAcl->id); } } return $financeAcl; }