public function auth($action, $page = null) { $pass = parent::auth($action, $page); if ($pass && $page) { if ($page->admin_class && $this->admin_loader->hasAdminClass($page->admin_class)) { $admin = $this->admin_loader->getAdminByClass($page->admin_class); $_action = $this->getAction($action); if ($_action->isDeleteAction() || $_action->isCreateAction()) { return false; } if ($page->admin_entity_id) { $object = $admin->getObjectById($page->admin_entity_id); if ($object) { return $_action->isFormAction() ? $admin->auth('page', $object) : $admin->auth($action, $object); } else { throw new \Exception(sprintf("invalid Page(id=%s)", $page->getId())); } } else { if ($page->admin_is_root) { return $_action->isFormAction() ? $admin->auth('page') : $admin->auth($action); } else { throw new \Exception(sprintf("invalid Page(id=%s)", $page->getId())); } } } } return $pass; }
/** * @return \Knp\Menu\MenuItem */ public function configureMenu(\Knp\Menu\MenuItem $menu, $text = false) { $_menu = null; $options = array(); $auth_object = null; if ($this->isRequestObject()) { $auth_object = $this->admin->getRouteObject(); } else { if ($this->admin->tree && $this->admin->getTreeObjectId()) { $auth_object = $this->admin->getTreeObject(); } } if (!$this->admin->auth($this->name, $auth_object)) { if ($this->isDeleteAction()) { return null; } if ($text) { if ($this->isRequestObject()) { $label = $this->admin->string($auth_object); } else { $label = $this->getActionLabel(); } $_menu = $menu->addChild($label, $options); } } else { $label = null; if ($this->isRequestObject()) { $label = $this->getActionLabel($auth_object); } else { $label = $this->getActionLabel(); } $options['uri'] = $this->path(); $_menu = $menu->addChild($label, $options); } if ($_menu && $this->isRouteAction()) { $_menu->setCurrent(true); } return $_menu; }