public function hasActionPermission(Action $action, User $user = null) { if ($user === null) { $user = $this->user; } $permissionTable = $this->getPermissionTable($user); return $permissionTable->contains($action->getId()); }
/** * @param Request $request * @param Created $payload */ public function created(Request $request, Created $payload) { $serializer = Action::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $document = new Document($resource); return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = Group::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['users', 'actions'])); $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = Module::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['actions'])); $resource = $resource->fields($params->getFields(['module' => Module::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = Group::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['users', 'actions'])); $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()])); $document = new Document($resource); // meta if ($params->getPage('size') != -1) { $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]); } // return response return new JsonResponse($document->toArray()); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aAction) { $this->aAction->removeApi($this); } $this->id = null; $this->route = null; $this->method = null; $this->action_id = null; $this->required_params = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aGroup) { $this->aGroup->removeGroupAction($this); } if (null !== $this->aAction) { $this->aAction->removeGroupAction($this); } $this->group_id = null; $this->action_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
private function installActions(Module $module, $data) { if (!isset($data['actions'])) { return; } $actions = []; foreach ($data['actions'] as $name => $options) { $a = new Action(); $a->setName($name); $a->setModule($module); if (isset($options['title'])) { $a->setTitle($options['title']); } if (isset($options['description'])) { $a->setDescription($options['description']); } if (isset($options['class'])) { $a->setClassName($options['class']); } // add acl if (isset($options['acl'])) { foreach ($options['acl'] as $group) { $a->addGroup($this->getGroup($group)); } } $a->save(); $actions[$name] = $a->getId(); } return $actions; }
/** */ public function getRelationships() { return ['action' => Action::getSerializer()->getType(null)]; }
/** * Returns the actions title * * @return string */ public function getTitle() { return $this->model->getTitle(); }
/** * Exclude object from result * * @param ChildAction $action Object to remove from the list of results * * @return $this|ChildActionQuery The current query, for fluid interface */ public function prune($action = null) { if ($action) { $this->addUsingAlias(ActionTableMap::COL_ID, $action->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $serializer = Action::getSerializer(); $relationship = $serializer->apis($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * Internal mechanism to set the Module id * * @param Action $model * @param mixed $relatedId */ protected function doSetModuleId(Action $model, $relatedId) { if ($model->getModuleId() !== $relatedId) { $model->setModuleId($relatedId); return true; } return false; }
/** * Filter the query by a related \keeko\core\model\Action object * * @param \keeko\core\model\Action|ObjectCollection $action The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildApiQuery The current query, for fluid interface */ public function filterByAction($action, $comparison = null) { if ($action instanceof \keeko\core\model\Action) { return $this->addUsingAlias(ApiTableMap::COL_ACTION_ID, $action->getId(), $comparison); } elseif ($action instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(ApiTableMap::COL_ACTION_ID, $action->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByAction() only accepts arguments of type \\keeko\\core\\model\\Action or Collection'); } }
/** * @param ChildAction $action The ChildAction object to add. */ protected function doAddAction(ChildAction $action) { $this->collActions[] = $action; $action->setModule($this); }
/** * @param Request $request * @param Found $payload */ public function read(Request $request, Found $payload) { $serializer = Action::getSerializer(); $relationship = $serializer->module($payload->getModel()); return new JsonResponse($relationship->toArray()); }
private function updateActions(Module $model, ModuleSchema $module) { $actions = []; foreach ($module->getActionNames() as $name) { $action = $module->getAction($name); $a = new Action(); $a->setName($name); $a->setModule($model); $a->setTitle($action->getTitle()); $a->setDescription($action->getDescription()); $a->setClassName($action->getClass()); // add acl foreach ($action->getAcl() as $group) { $a->addGroup($this->getGroup($group)); } $a->save(); $actions[$name] = $a->getId(); } // remove obsolete actions ActionQuery::create()->filterByModule($model)->where('Action.Name NOT IN ?', $module->getActionNames()->toArray())->delete(); return $actions; }
/** * Filter the query by a related \keeko\core\model\Action object * * @param \keeko\core\model\Action|ObjectCollection $action the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildModuleQuery The current query, for fluid interface */ public function filterByAction($action, $comparison = null) { if ($action instanceof \keeko\core\model\Action) { return $this->addUsingAlias(ModuleTableMap::COL_ID, $action->getModuleId(), $comparison); } elseif ($action instanceof ObjectCollection) { return $this->useActionQuery()->filterByPrimaryKeys($action->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByAction() only accepts arguments of type \\keeko\\core\\model\\Action or Collection'); } }