From: Marcel Werk Date: Thu, 17 Mar 2016 18:01:42 +0000 (+0100) Subject: Added permissions/options for pages/menu items X-Git-Tag: 3.0.0_Beta_1~2021 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=afba9daff2820d1e9c5ce1561a7a2aaca06e42ad;p=GitHub%2FWoltLab%2FWCF.git Added permissions/options for pages/menu items --- diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index 85995c9c95..5144bc8916 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -6,12 +6,15 @@ wcf\page\DashboardPage + module_dashboard_page wcf\page\MembersListPage + user.profile.canViewMembersList + module_members_list wcf\page\RecentActivityListPage @@ -24,18 +27,24 @@ com.woltlab.wcf.MembersList + user.profile.canViewUsersOnlineList + module_users_online wcf\page\TeamPage com.woltlab.wcf.MembersList + user.profile.canViewMembersList + module_team_page wcf\page\UserSearchForm com.woltlab.wcf.MembersList + user.profile.canViewMembersList + module_members_list @@ -101,6 +110,7 @@ Privacy Policy Datenschutzerklärung + module_privacy_policy_page Privacy Policy diff --git a/wcfsetup/install/files/lib/data/menu/Menu.class.php b/wcfsetup/install/files/lib/data/menu/Menu.class.php index 009984aec7..53e4fc20c0 100644 --- a/wcfsetup/install/files/lib/data/menu/Menu.class.php +++ b/wcfsetup/install/files/lib/data/menu/Menu.class.php @@ -67,8 +67,7 @@ class Menu extends DatabaseObject { * @return boolean */ public function hasContent() { - return true; // @todo - //return count(MenuCache::getInstance()->getMenuItemsByMenuID($this->menuID)->getNodeList()); + return $this->getMenuItemNodeTree()->getVisibleItemCount() > 0; } /** @@ -104,7 +103,7 @@ class Menu extends DatabaseObject { } /** - * @return MenuItemNodeTree + * @return MenuItemNodeTree */ protected function getMenuItemNodeTree() { if ($this->menuItemNodeTree === null) { diff --git a/wcfsetup/install/files/lib/data/menu/item/MenuItem.class.php b/wcfsetup/install/files/lib/data/menu/item/MenuItem.class.php index 1fe322c4bf..da5576cb49 100644 --- a/wcfsetup/install/files/lib/data/menu/item/MenuItem.class.php +++ b/wcfsetup/install/files/lib/data/menu/item/MenuItem.class.php @@ -90,13 +90,11 @@ class MenuItem extends DatabaseObject { /** * Returns the page that is linked by this menu item. * - * @return Page + * @return Page|null */ public function getPage() { - if ($this->page === null) { - if ($this->pageID) { - $this->page = new Page($this->pageID); - } + if ($this->page === null && $this->pageID) { + $this->page = new Page($this->pageID); } return $this->page; @@ -108,6 +106,10 @@ class MenuItem extends DatabaseObject { * @return boolean */ public function isVisible() { + if ($this->getPage() !== null && !$this->getPage()->isVisible()) { + return false; + } + if ($this->getMenuPageHandler() !== null) { return $this->getMenuPageHandler()->isVisible($this->pageObjectID ?: null); } @@ -129,7 +131,7 @@ class MenuItem extends DatabaseObject { } /** - * @return IMenuPageHandler + * @return IMenuPageHandler|null */ protected function getMenuPageHandler() { $page = $this->getPage(); diff --git a/wcfsetup/install/files/lib/data/menu/item/MenuItemNodeTree.class.php b/wcfsetup/install/files/lib/data/menu/item/MenuItemNodeTree.class.php index a96a02c164..c0c69811be 100644 --- a/wcfsetup/install/files/lib/data/menu/item/MenuItemNodeTree.class.php +++ b/wcfsetup/install/files/lib/data/menu/item/MenuItemNodeTree.class.php @@ -37,6 +37,12 @@ class MenuItemNodeTree { */ public $node; + /** + * number of visible items + * @var integer + */ + protected $visibleItemCount = 0; + /** * Creates a new MenuItemNodeTree object. * @@ -54,6 +60,7 @@ class MenuItemNodeTree { $menuItemList->readObjects(); } + // build menu structure foreach ($menuItemList as $menuItem) { $this->menuItems[$menuItem->itemID] = $menuItem; @@ -63,25 +70,13 @@ class MenuItemNodeTree { $this->menuItemStructure[$menuItem->parentItemID][] = $menuItem->itemID; } - // filter items by visibility - foreach ($this->menuItems as $menuItemID => $menuItem) { - if (!$menuItem->isVisible()) { - unset($this->menuItems[$menuItemID]); - unset($this->menuItemStructure[$menuItemID]); - - // remove item from parent item structure - $key = array_search($menuItemID, $this->menuItemStructure[$menuItem->parentItemID]); - array_splice($this->menuItemStructure[$menuItem->parentItemID], $key, 1); - } - } - // generate node tree $this->node = new MenuItemNode(); $this->node->setChildren($this->generateNodeTree(null, $this->node)); } /** - * Generates the node tree recursively + * Generates the node tree recursively. * * @param integer $parentID parent menu item id * @param MenuItemNode $parentNode parent menu item object @@ -93,11 +88,15 @@ class MenuItemNodeTree { $itemIDs = (isset($this->menuItemStructure[$parentID]) ? $this->menuItemStructure[$parentID] : []); foreach ($itemIDs as $itemID) { $menuItem = $this->menuItems[$itemID]; + if (!$menuItem->isVisible()) continue; $node = new MenuItemNode($parentNode, $menuItem, ($parentNode !== null ? ($parentNode->getDepth() + 1) : 0)); $nodes[] = $node; // get children $node->setChildren($this->generateNodeTree($itemID, $node)); + + // increase item counter + $this->visibleItemCount++; } return $nodes; @@ -113,11 +112,20 @@ class MenuItemNodeTree { } /** - * Returns the iteratable node list + * Returns the iteratable node list. * * @return \RecursiveIteratorIterator */ public function getNodeList() { return new \RecursiveIteratorIterator($this->node, \RecursiveIteratorIterator::SELF_FIRST); } + + /** + * Returns the number of visible items. + * + * @return integer + */ + public function getVisibleItemCount() { + return $this->visibleItemCount; + } } diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 23d9135a78..5bb8d49206 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -163,6 +163,44 @@ class Page extends DatabaseObject { return $this->pageHandler; } + /** + * Returns false if this page should be hidden from menus, but does not control the accessibility + * of the page itself. + * + * @return boolean false if the page should be hidden from menus + */ + public function isVisible() { + // check the options of this page + $hasEnabledOption = true; + if ($this->options) { + $hasEnabledOption = false; + $options = explode(',', strtoupper($this->options)); + foreach ($options as $option) { + if (defined($option) && constant($option)) { + $hasEnabledOption = true; + break; + } + } + } + if (!$hasEnabledOption) return false; + + // check the permission of this page for the active user + $hasPermission = true; + if ($this->permissions) { + $hasPermission = false; + $permissions = explode(',', $this->permissions); + foreach ($permissions as $permission) { + if (WCF::getSession()->getPermission($permission)) { + $hasPermission = true; + break; + } + } + } + if (!$hasPermission) return false; + + return true; + } + /** * Returns the page's internal name. * diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index 1eef245549..48f7b5f3cb 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -155,7 +155,9 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin 'name' => $name, 'originIsSystem' => 1, 'parentPageID' => $parentPageID, - 'requireObjectID' => (!empty($data['elements']['requireObjectID'])) ? 1 : 0 + 'requireObjectID' => (!empty($data['elements']['requireObjectID'])) ? 1 : 0, + 'options' => (isset($data['elements']['options'])) ? $data['elements']['options'] : '', + 'permissions' => (isset($data['elements']['permissions'])) ? $data['elements']['permissions'] : '' ]; } diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 6967524587..9e8412db33 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -915,7 +915,9 @@ CREATE TABLE wcf1_page ( handler VARCHAR(255) NOT NULL DEFAULT '', controllerCustomURL VARCHAR(255) NOT NULL DEFAULT '', requireObjectID TINYINT(1) NOT NULL DEFAULT 0, - lastUpdateTime INT(10) NOT NULL DEFAULT 0 + lastUpdateTime INT(10) NOT NULL DEFAULT 0, + permissions TEXT NULL, + options TEXT NULL ); DROP TABLE IF EXISTS wcf1_page_content;