/** * @static * * @param Node $pNode * @param array $pBoxedContents */ function installContents(Node $pNode, $pBoxedContents) { if (!is_array($pBoxedContents)) { return; } /** * 0: type74 * 1: title * 2: template * 3: content * */ foreach ($pBoxedContents as $boxId => $contents) { foreach ($contents as $content) { $oContent = new Content(); $oContent->setNodeId($pNode->getId()); $oContent->setBoxId($boxId); $oContent->setType($content[0]); $oContent->setTemplate($content[2]); $oContent->setContent($content[3]); $oContent->save(); } } }
public function testNestedSubPermission() { $this->getACL()->setCaching(false); $this->getACL()->removeObjectRules('jarves/node'); $tokenStorage = $this->getTokenStorage(); $token = new UsernamePasswordToken(UserQuery::create()->findOneByUsername('test'), null, "main"); $tokenStorage->setToken($token); $user = $this->getPageStack()->getUser(); $this->assertEquals('test', $user->getUsername()); $domain = DomainQuery::create()->findOne(); $root = NodeQuery::create()->findRoot($domain->getId()); $subNode = new Node(); $subNode->setTitle('TestNode tree'); $subNode->insertAsFirstChildOf($root); $subNode->save(); $subNode2 = new Node(); $subNode2->setTitle('TestNode sub'); $subNode2->insertAsFirstChildOf($subNode); $subNode2->save(); //make access for all $rule = new Acl(); $rule->setAccess(true); $rule->setObject('jarves/node'); $rule->setTargetType(\Jarves\ACL::TARGET_TYPE_USER); $rule->setTargetId($user->getId()); $rule->setMode(\Jarves\ACL::MODE_ALL); $rule->setConstraintType(\Jarves\ACL::CONSTRAINT_ALL); $rule->setPrio(2); $rule->save(); //revoke access for all children of `TestNode tree` $rule2 = new Acl(); $rule2->setAccess(false); $rule2->setObject('jarves/node'); $rule2->setTargetType(\Jarves\ACL::TARGET_TYPE_USER); $rule2->setTargetId($user->getId()); $rule2->setMode(\Jarves\ACL::MODE_ALL); $rule2->setConstraintType(\Jarves\ACL::CONSTRAINT_CONDITION); $rule2->setConstraintCode(json_encode(['title', '=', 'TestNode tree'])); $rule2->setPrio(3); $rule2->setSub(true); $rule2->save(); $this->getCacher()->invalidateCache('core'); $node1RequestListing = ACLRequest::create('jarves/node', $subNode->getId())->onlyListingMode(); $node2RequestListing = ACLRequest::create('jarves/node', $subNode2->getId())->onlyListingMode(); $this->assertFalse($this->getACL()->check($node1RequestListing)); $this->assertFalse($this->getACL()->check($node2RequestListing)); $items = $this->getObjects()->getBranch('jarves/node', $subNode->getId(), null, 1, null, ['permissionCheck' => true]); $this->assertNull($items, 'rule2 revokes the access to all elements'); $item = $this->getObjects()->get('jarves/node', $subNode2->getId(), ['permissionCheck' => true]); $this->assertNull($item); // Deactivate sub $rule2->setSub(false); $rule2->save(); $this->assertFalse($this->getACL()->check($node1RequestListing)); $this->assertTrue($this->getACL()->check($node2RequestListing)); $items = $this->getObjects()->getBranch('jarves/node', $subNode->getId(), null, 1, null, ['permissionCheck' => true]); $this->assertEquals('TestNode sub', $items[0]['title'], 'We got TestNode sub'); $item = $this->getObjects()->get('jarves/node', $subNode2->getId(), ['permissionCheck' => true]); $this->assertEquals('TestNode sub', $item['title'], 'We got TestNode sub'); // Activate access $rule2->setAccess(true); $rule2->save(); $this->assertTrue($this->getACL()->check($node1RequestListing)); $this->assertTrue($this->getACL()->check($node2RequestListing)); $items = $this->getObjects()->getBranch('jarves/node', $subNode->getId(), null, 1, null, ['permissionCheck' => true]); $this->assertEquals('TestNode sub', $items[0]['title'], 'We got TestNode sub'); $subNode->delete(); $subNode2->delete(); $rule->delete(); $rule2->delete(); $this->getACL()->setCaching(true); }
protected function exportNode($position, Domain $domain, Node $node, ExportPointer $exportPointer) { $data = $node->toArray(TableMap::TYPE_CAMELNAME); if (!$node->getUrn()) { return; } $path = $node->getUrn(); $exportPointer->pushPath($path); if ($node->getId() === $domain->getStartnodeId()) { $domain->setVirtualColumn('startnodePath', $path); } $nodeData = $this->clearData($data, ['id', 'lft', 'rgt', 'lvl', 'pid', 'urn', 'domainId'], ['type' => 0, 'layout' => 'default', 'visible' => true]); $nodeData['sort'] = $position; $contents = $node->getContents(); $contentsData = []; foreach ($contents as $content) { $contentData = $content->toArray(TableMap::TYPE_CAMELNAME); $jsonDecoded = json_decode($contentData['content'], true); if (JSON_ERROR_NONE === json_last_error()) { $contentData['content'] = $jsonDecoded; } $contentData = $this->clearData($contentData, ['id', 'nodeId'], ['template' => 'JarvesBundle:Default:content.html.twig', 'type' => 'text']); $contentsData[] = $contentData; } $nodeData['contents'] = $contentsData; $exportPointer->addData($nodeData, '.yml'); foreach ($node->getChildren() as $idx => $child) { $this->exportNode($idx, $domain, $child, $exportPointer); } $exportPointer->popPath(); }
public function registerPluginRoutes(Node $page) { $domain = $this->pageStack->getDomain($page->getDomainId()); $this->stopwatch->start('Register Plugin Routes'); //add all router to current router and fire sub-request $cacheKey = 'core/node/plugins-' . $page->getId(); $plugins = $this->cacher->getDistributedCache($cacheKey); if (null === $plugins) { $plugins = ContentQuery::create()->filterByNodeId($page->getId())->filterByType('plugin')->find(); $this->cacher->setDistributedCache($cacheKey, serialize($plugins)); } else { $plugins = unserialize($plugins); } /** @var $plugins Content[] */ foreach ($plugins as $plugin) { if (!$plugin->getContent()) { continue; } $data = json_decode($plugin->getContent(), true); if (!$data) { $this->logger->alert(sprintf('On page `%s` [%d] is a invalid plugin `%d`.', $page->getTitle(), $page->getId(), $plugin->getId())); continue; } $bundleName = isset($data['module']) ? $data['module'] : @$data['bundle']; $config = $this->jarves->getConfig($bundleName); if (!$config) { $this->logger->alert(sprintf('Bundle `%s` for plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId())); continue; } $pluginDefinition = $config->getPlugin(@$data['plugin']); if (!$pluginDefinition) { $this->logger->alert(sprintf('In bundle `%s` the plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId())); continue; } if ($pluginRoutes = $pluginDefinition->getRoutes()) { foreach ($pluginRoutes as $idx => $route) { $controller = $pluginDefinition->getController(); $defaults = array('_controller' => $route->getController() ?: $controller, '_jarves_is_plugin' => true, '_content' => $plugin, '_title' => sprintf('%s: %s', $bundleName, $pluginDefinition->getLabel()), 'options' => isset($data['options']) && is_array($data['options']) ? $data['options'] : [], 'jarvesFrontend' => true, 'nodeId' => $page->getId()); if ($route->getDefaults()) { $defaults = array_merge($defaults, $route->getArrayDefaults()); } $url = $this->pageStack->getRouteUrl($page->getId()); $this->routes->add('jarves_frontend_plugin_' . ($route->getId() ?: $plugin->getId()) . '_' . $idx, new SyRoute($url . '/' . $route->getPattern(), $defaults, $route->getArrayRequirements() ?: array(), [], '', [], $route->getMethods() ?: [])); } } } $this->stopwatch->stop('Register Plugin Routes'); }