function afterLoad() { // unpack uuid $this->uuid = util::unpackUuid($this->uuid); // Merge tasks with settings $this->tasks = array_reduce((array) @$this->tasks, function ($result, $task) { $taskModel = new Task($task); $taskModel->load($taskModel->identity()); if ($taskModel->identity()) { $taskModel->appendData($task); $result[] = $taskModel; } return $result; }, array()); // Restrict to users who have access to the first step if (!$this->__isSuperUser) { if (!array_intersect((array) @$this->tasks[0]->userGroups(), (array) @$this->__request->user->groups)) { $this->data(array()); } } return parent::afterLoad(); }
/** * @protected * * Create relations between steps and works or jobs, even though works and jobs * are mutually exclusive, manage this on the parent side. */ function afterSave() { if ($this->isCreate()) { // Task:Instance $this->parents('Task', $this->task(), true); // WorkInstance:TaskInstance $this->parents(static::WORK_RELATION, $this->workInstance(), true); } // unpack uuid strings $this->uuid = util::unpackUuid($this->uuid); return parent::afterSave(); }
/** * Generate a one-time authentication token string for additional * security for AJAX service calls. * * Each additional call to this function overwrites the token generated last time. * * @return One-time token string, or null on invalid session. */ static function generateToken($sid = null) { $res = static::ensure($sid); if ($res !== true) { return $res; } $res =& static::$currentSession; $res['token'] = Database::fetchField("SELECT UNHEX(REPLACE(UUID(),'-',''));"); unset($res['timestamp']); if (Node::set($res) === false) { return null; } return util::unpackUuid($res['token']); }
/** * @protected * * Load task contents, remove task scripts. */ function afterLoad() { // unpack uuid $this->uuid = util::unpackUuid($this->uuid); $this->nextTask = util::unpackUuid($this->nextTask); // note: Only users with access to nextTask has view permission. if (!$this->__isSuperUser) { // 1. Group:User $res = (array) @$this->__request->user->groups; // 2. Task:Group $res = Relation::getAncestors($res, Task::GROUP_RELATION); // 3. Task $res = Relation::getDescendants($res, 'Task'); // 4. UUID comparison if (!in_array($this->nextTask, $res)) { return $this->data(array()); } } // load task details, do not expose internal scripts $taskInstance = new TaskInstance(); $this->tasks = array_map(removes('order'), $taskInstance->find(array('uuid' => $this->children($taskInstance::WORK_RELATION), '@sorter' => ['order']))); unset($taskInstance); $res = parent::afterLoad(); // lock the item after load $this->_immutable = true; return $res; }