Exemplo n.º 1
0
 /**
  * Setup for tests
  *
  * @return null
  */
 public function setUp()
 {
     $this->mockPageRepo = $this->getMockBuilder('\\Rcm\\Repository\\Page')->disableOriginalConstructor()->getMock();
     $this->mockPageRepo->expects($this->any())->method('getPageByName')->will($this->returnCallback([$this, 'pageRepoMockCallback']));
     $mockLayoutManager = $this->getMockBuilder('\\Rcm\\Service\\LayoutManager')->disableOriginalConstructor()->getMock();
     $mockLayoutManager->expects($this->any())->method('getSiteLayout')->will($this->returnCallback([$this, 'layoutManagerMockCallback']));
     $this->mockUserServicePlugin = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RcmIsAllowed')->disableOriginalConstructor()->getMock();
     $this->mockIsPageAllowed = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RcmIsPageAllowed')->disableOriginalConstructor()->getMock();
     $this->mockShouldShowRevisions = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\ShouldShowRevisions')->disableOriginalConstructor()->getMock();
     $this->mockRedirectToPage = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RedirectToPage')->disableOriginalConstructor()->getMock();
     $this->mockIsSiteAdmin = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\IsSiteAdmin')->disableOriginalConstructor()->getMock();
     $this->currentSite = new Site();
     $this->currentSite->setSiteId(1);
     $this->currentSite->setNotFoundPage('not-found');
     $config = ['contentManager' => ['type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => ['route' => '/rcm[/:page][/:revision]', 'defaults' => ['controller' => 'Rcm\\Controller\\IndexController', 'action' => 'index']]], 'contentManagerWithPageType' => ['type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => ['route' => '/rcm/:pageType/:page[/:revision]', 'constraints' => ['pageType' => '[a-z]'], 'defaults' => ['controller' => 'Rcm\\Controller\\IndexController', 'action' => 'index']]]];
     /** @var \Rcm\Service\LayoutManager $mockLayoutManager */
     $this->controller = new IndexController($mockLayoutManager, $this->currentSite, $this->mockPageRepo);
     $this->controller->getPluginManager()->setService('rcmIsAllowed', $this->mockUserServicePlugin)->setService('shouldShowRevisions', $this->mockShouldShowRevisions)->setService('redirectToPage', $this->mockRedirectToPage)->setService('rcmIsSiteAdmin', $this->mockIsSiteAdmin)->setService('rcmIsPageAllowed', $this->mockIsPageAllowed);
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(['controller' => 'index']);
     $this->event = new MvcEvent();
     $routerConfig = $config;
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
 }
Exemplo n.º 2
0
 /**
  * Initialize the form
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function init()
 {
     $pageList = $this->pageRepo->getAllPageIdsAndNamesBySiteThenType($this->currentSite->getSiteId(), 't');
     $pageList['blank'] = 'Blank Page (Experts Only)';
     $filter = new InputFilter();
     $this->add(['name' => 'url', 'options' => ['label' => 'Page Url'], 'type' => 'text']);
     $filter->add(['name' => 'url', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim', 'options' => ['charlist' => '-_']]], 'validators' => [$this->pageValidator]]);
     $this->add(['name' => 'title', 'options' => ['label' => 'Page Title'], 'type' => 'text']);
     $filter->add(['name' => 'title', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => '\\Zend\\I18n\\Validator\\Alnum', 'options' => ['allowWhiteSpace' => true]]]]);
     $this->add(['name' => 'page-template', 'options' => ['label' => 'Page Template', 'value_options' => $pageList], 'type' => 'Zend\\Form\\Element\\Select']);
     $filter->add(['name' => 'page-template', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [$this->templateValidator]]);
     $this->add(['name' => 'main-layout', 'options' => ['label' => 'Main Layout', 'layouts' => $this->layoutManager->getSiteThemeLayoutsConfig($this->currentSite->getTheme())], 'type' => 'mainLayout']);
     $filter->add(['name' => 'main-layout', 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [$this->layoutValidator]]);
     $this->setInputFilter($filter);
 }
Exemplo n.º 3
0
 /**
  * savePageAction
  *
  * @return Response|\Zend\Http\Response
  */
 public function savePageAction()
 {
     if (!$this->rcmIsAllowed('sites.' . $this->currentSite->getSiteId() . '.pages', 'edit')) {
         $response = new Response();
         $response->setStatusCode('401');
         return $response;
     }
     // @todo - might validate these against the data coming in
     $pageName = $this->getEvent()->getRouteMatch()->getParam('rcmPageName', 'index');
     $pageRevision = $this->getEvent()->getRouteMatch()->getParam('rcmPageRevision', null);
     $pageType = $this->getEvent()->getRouteMatch()->getParam('rcmPageType', 'n');
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     if ($request->isPost()) {
         /** @var \Zend\Stdlib\Parameters $data */
         $data = $request->getPost()->toArray();
         $this->prepSaveData($data);
         $result = $this->pageRepo->savePage($this->currentSite, $pageName, $pageRevision, $pageType, $data, $this->rcmUserGetCurrentUser()->getName());
         if (empty($result)) {
             $return['redirect'] = $this->urlToPage($pageName, $pageType, $pageRevision);
         } else {
             $return['redirect'] = $this->urlToPage($pageName, $pageType, $result);
         }
         return $this->getJsonResponse($return);
     }
     $response = new Response();
     $response->setStatusCode('404');
     return $response;
 }
Exemplo n.º 4
0
 /**
  * renderNotFoundPage
  *
  * @param Site $site
  *
  * @return null|Page
  */
 public function renderNotFoundPage($site)
 {
     $page = $this->pageRepo->getPageByName($site, $site->getNotFoundPage(), 'n');
     if (empty($page)) {
         throw new PageNotFoundException('No default page defined for 404 not found error');
     }
     $response = $this->getResponse();
     $response->setStatusCode(410);
     return $page;
 }
Exemplo n.º 5
0
 /**
  * Is the page valid?
  *
  * @param string $value Page to validate
  *
  * @return bool
  */
 public function isValid($value)
 {
     $this->setValue($value);
     $check = $this->pageRepo->findOneBy(['pageId' => $value, 'pageType' => $this->pageType, 'site' => $this->site]);
     if (empty($check)) {
         $this->error(self::PAGE_TEMPLATE);
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
Arquivo: Page.php Projeto: reliv/rcm
 /**
  * Is the page valid?
  *
  * @param string $value Page to validate
  *
  * @return bool
  */
 public function isValid($value)
 {
     $nameOk = parent::isValid($value);
     if (!$nameOk) {
         return false;
     }
     $check = $this->pageRepo->findOneBy(['name' => $value, 'pageType' => $this->pageType, 'site' => $this->siteId]);
     if (!empty($check)) {
         $this->error(self::PAGE_EXISTS);
         return false;
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * getRevisionList
  *
  * @param bool $published
  * @param int  $limit
  *
  * @return array|mixed
  */
 protected function getRevisionList($published = false, $limit = 10)
 {
     $revisions = $this->pageRepo->getRevisionList($this->currentSite->getSiteId(), $this->page->getName(), $this->page->getPageType(), $published, $limit);
     return $revisions;
 }
 /**
  * Update an existing resource
  *
  * @param  string $id   $pageName
  * @param  array  $data $roles
  *
  * @return mixed
  */
 public function update($id, $data)
 {
     $this->aclDataService = $this->getServiceLocator()->get('RcmUser\\Acl\\AclDataService');
     $this->resourceProvider = $this->getServiceLocator()->get('Rcm\\Acl\\ResourceProvider');
     /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $this->pageRepo = $entityManager->getRepository('\\Rcm\\Entity\\Page');
     if (!is_array($data)) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     /** @var \Rcm\Entity\Site $currentSite */
     $currentSite = $this->getServiceLocator()->get('Rcm\\Service\\CurrentSite');
     if (is_numeric($data['siteId']) && $currentSite->getSiteId() == $data['siteId']) {
         $siteId = $data['siteId'];
     } else {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     if (is_string($data['pageName'])) {
         $pageName = $data['pageName'];
     } else {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     if (is_string($data['pageType']) && strlen($data['pageType']) == '1') {
         $pageType = $data['pageType'];
     } else {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     if (is_array($data['selectedRoles'])) {
         $selectedRoles = $data['selectedRoles'];
     } else {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     //CREATE RESOURCE ID
     $resourceId = 'sites.' . $siteId . '.pages.' . 'n' . '.' . $pageName;
     //ACCESS CHECK
     if (!$this->rcmIsAllowed($resourceId, 'edit') && !$this->isAllowed('pages', 'edit')) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);
         return $this->getResponse();
     }
     //IS PAGE VALID?
     $validPage = $this->pageRepo->isValid($currentSite, $pageName, $pageType);
     if (!$validPage) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_404);
         return $this->getResponse();
     }
     if (!$this->isValidResourceId($resourceId)) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     //DELETE ALL PERMISSIONS
     $deleteAllPermissions = $this->deletePermissions($resourceId);
     if (!$deleteAllPermissions) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);
         return $this->getResponse();
     }
     $newRoles = $this->addPermissions($selectedRoles, $resourceId);
     return new JsonModel($newRoles);
 }