Add array support for `TagCloudBoxController::$neededPermission`
authorMatthias Schmidt <gravatronics@live.com>
Mon, 7 Aug 2017 16:42:26 +0000 (18:42 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 7 Aug 2017 16:42:26 +0000 (18:42 +0200)
Close #2369

wcfsetup/install/files/lib/system/box/TagCloudBoxController.class.php

index cc5c04a1976b0fba9fc4cfb5ae1f4b28ecf6c5c9..0d8d92e0b3635c99244907985b4fb899425a1044 100644 (file)
@@ -4,6 +4,7 @@ use wcf\system\language\LanguageFactory;
 use wcf\system\tagging\TagCloud;
 use wcf\system\tagging\TypedTagCloud;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 
 /**
  * Box for the tag cloud.
@@ -27,7 +28,7 @@ class TagCloudBoxController extends AbstractBoxController {
        
        /**
         * needed permission to view this box
-        * @var string
+        * @var string|string[]
         */
        protected $neededPermission = '';
        
@@ -35,7 +36,31 @@ class TagCloudBoxController extends AbstractBoxController {
         * @inheritDoc
         */
        protected function loadContent() {
-               if (MODULE_TAGGING && WCF::getSession()->getPermission('user.tag.canViewTag') && (!$this->neededPermission || WCF::getSession()->getPermission($this->neededPermission))) {
+               if (MODULE_TAGGING && WCF::getSession()->getPermission('user.tag.canViewTag')) {
+                       if ($this->neededPermission) {
+                               if (is_string($this->neededPermission)) {
+                                       if (!WCF::getSession()->getPermission($this->neededPermission)) {
+                                               return;
+                                       }
+                               }
+                               else if (is_array($this->neededPermission)) {
+                                       $hasPermission = false;
+                                       foreach ($this->neededPermission as $permission) {
+                                               if (WCF::getSession()->getPermission($permission)) {
+                                                       $hasPermission = true;
+                                                       break;
+                                               }
+                                       }
+                                       
+                                       if (!$hasPermission) {
+                                               return;
+                                       }
+                               }
+                               else {
+                                       throw new \LogicException("\$neededPermission must not be of type '" . gettype($this->neededPermission) . "', only strings and arrays are supported.");
+                               }
+                       }
+                       
                        $languageIDs = [];
                        if (LanguageFactory::getInstance()->multilingualismEnabled()) {
                                $languageIDs = WCF::getUser()->getLanguageIDs();