[FEATURE] Creating User Rights
authorBastian Bringenberg <spam@bastian-bringenberg.de>
Thu, 28 Nov 2013 17:39:31 +0000 (18:39 +0100)
committerBastian Bringenberg <spam@bastian-bringenberg.de>
Thu, 28 Nov 2013 17:39:31 +0000 (18:39 +0100)
Allows to disabling the edit-function for guests

Change-Id: I990c81a0112b47be6c32e02a26a710037c0da067
Refs: #40636

Classes/Controller/PageController.php
Classes/Domain/Model/Page.php
Configuration/TypoScript/setup.txt
Resources/Private/Templates/Page/Show.html

index 7444ebf..96c62b6 100755 (executable)
@@ -4,7 +4,7 @@
  *  Copyright notice
  *
  *  (c) 2012 Bastian Bringenberg <typo3@bastian-bringenberg.de>, Bastian Bringenberg
- *  
+ *
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -91,6 +91,7 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
                        $renderHelper->setRelatedPage($page);
                        $page->getMainRevision()->setRenderedText($renderHelper->renderText($page->getMainRevision()->getUnrenderedText()));
                }
+               $this->view->assign('allowEdit', $page->allowEdit($this->settings));
                $this->view->assign('redirection', $redirection);
                $this->view->assign('page', $page);
        }
@@ -135,13 +136,15 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
                        $persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
                        $persistenceManager->persistAll();
                }
+               if(!$page->allowEdit($this->settings)) $this->redirect('show', NULL, NULL, array('page' => $page));
+
         $preview = NULL;
         $myUnrenderedText = '';
-        if($page->getMainRevision() !== NULL) $myUnrenderedText = $page->getMainRevision()->getUnrenderedText();
-        if($unrenderedText !== NULL){
+               if($page->getMainRevision() !== NULL) $myUnrenderedText = $page->getMainRevision()->getUnrenderedText();
+               if($unrenderedText !== NULL){
             $renderHelper = $this->createRenderHelper();
-            $preview = $renderHelper->renderText($unrenderedText);
-            $myUnrenderedText = $unrenderedText;
+                       $preview = $renderHelper->renderText($unrenderedText);
+                       $myUnrenderedText = $unrenderedText;
         }
         $this->view->assign('preview', $preview);
         $this->view->assign('changes', $changes);
@@ -156,7 +159,8 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
         * @return void
         */
        public function updateAction(Tx_Typo3wiki_Domain_Model_Page $page) {
-               if($page === NULL) $page = $this->pageRepository->findOneByPageTitle($this->request->getArgument('page'));
+               if($page === NULL) $page = $this->pageRepository->findOneByPageTitle($this->request->getArgument('page'));
+               if(!$page->allowEdit($this->settings)) $this->redirect('show', NULL, NULL, array('page' => $page));
                $text = $this->request->getArgument('text');
         $changes = $this->request->getArgument('changes');
         try{
@@ -165,7 +169,6 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
         }catch(Exception $e){
             $preview = FALSE;
         }
-
         if(isset($page) && $preview){
             $this->forward('edit', NULL, NULL, array('page' => $page, 'unrenderedText' => $text, 'changes' => $changes));
         }
@@ -237,4 +240,4 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
                return $page;
        }
 
-}
\ No newline at end of file
+}
index ce67b7e..150af8a 100755 (executable)
                }
 
                /**
+                * Checks if user is allowed to edit page
+                *
+                * @param array $settings
+                * @return boolean
+                */
+               public function allowEdit($settings) {
+                       if(!$settings->guestCanEdit && $GLOBALS['TSFE']->fe_user->user['uid'] == 0) return false;
+                       return true;
+               }
+
+               /**
                 * Returns the pageTitle
                 *
                 * @return string $pageTitle
 
        }
 
-?>
\ No newline at end of file
+?>
index e8b8ab2..a2de818 100755 (executable)
@@ -13,6 +13,9 @@ plugin.tx_typo3wiki {
        }
        settings {
        indexPageTitle = {$plugin.tx_typo3wiki.settings.indexPageTitle}
+       guestCanEdit = {$plugin.tx_typo3wiki.settings.guestCanEdit}
+        guestCanRead = {$plugin.tx_typo3wiki.settings.guestCanRead}
+        adminGroupID = {$plugin.tx_typo3wiki.settings.adminGroupID}
     }
 }
 
index 9194ecc..f916677 100755 (executable)
@@ -8,6 +8,6 @@
             <f:link.action action="show" arguments="{page: redirection}">{redirection}</f:link.action>
         </div>
     </f:if>
-    <div class="edit"><f:link.action action="edit" arguments="{page: page}">edit</f:link.action></div>
+    <f:if condition="{allowEdit}"><div class="edit"><f:link.action action="edit" arguments="{page: page}">edit</f:link.action></div></f:if>
     <div class="content"><f:format.raw>{page.mainRevision.renderedText}</f:format.raw></div>
-</f:section>
\ No newline at end of file
+</f:section>