From 875674992beb44b19c4239e0ea4f6e55d758ca3e Mon Sep 17 00:00:00 2001 From: snenko Date: Mon, 6 Jan 2020 23:48:17 +0200 Subject: [PATCH 1/2] hide top menu items if not user do not have permission to this menu item. --- layouts/basic/modules/Vtiger/menu/Label.tpl | 9 +++++++ modules/Vtiger/models/Menu.php | 27 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/layouts/basic/modules/Vtiger/menu/Label.tpl b/layouts/basic/modules/Vtiger/menu/Label.tpl index 668fd4a30adc..bc59c6025155 100644 --- a/layouts/basic/modules/Vtiger/menu/Label.tpl +++ b/layouts/basic/modules/Vtiger/menu/Label.tpl @@ -6,6 +6,14 @@ {else} {assign var=ACTIVE value='false'} {/if} + + {if $MENU_MODULE=='Settings::Vtiger'} + {assign var=SHOWITEMMENU value='true'} + {else} + {assign var=SHOWITEMMENU value=Vtiger_Menu_Model::isShowTopLevelMenuItem($MENU, $MENU_MODULE)} + {/if} + + {if $SHOWITEMMENU=='true'} + {/if} {/strip} diff --git a/modules/Vtiger/models/Menu.php b/modules/Vtiger/models/Menu.php index f8d6c4894440..0413b8259d13 100644 --- a/modules/Vtiger/models/Menu.php +++ b/modules/Vtiger/models/Menu.php @@ -218,4 +218,31 @@ public static function getMenuIcon($menu, $title = '') } return ''; } + + /** + * @param $menu + * + * @return bool + */ + public static function isShowTopLevelMenuItem($menu) + { + if(isset($menu['childs']) && count($menu['childs'])>0) { + foreach ($menu['childs'] as $id=>$subMenu) { + + $privilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); + if(\App\Module::isModuleActive($subMenu['mod'])==false) { + return false; + } + + if ($privilegesModel->isAdminUser() || + $privilegesModel->hasGlobalReadPermission() || + $privilegesModel->hasModulePermission($subMenu['tabid']) ) { + return true; + } + + } + } + + return true; + } } From f93a0f12f6a2856ade8b491092178f22977f1b66 Mon Sep 17 00:00:00 2001 From: snenko Date: Tue, 7 Jan 2020 11:46:57 +0200 Subject: [PATCH 2/2] show top menu items(depends on submenus):fix --- modules/Vtiger/models/Menu.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/Vtiger/models/Menu.php b/modules/Vtiger/models/Menu.php index 0413b8259d13..04400f123eda 100644 --- a/modules/Vtiger/models/Menu.php +++ b/modules/Vtiger/models/Menu.php @@ -231,7 +231,7 @@ public static function isShowTopLevelMenuItem($menu) $privilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); if(\App\Module::isModuleActive($subMenu['mod'])==false) { - return false; + continue; } if ($privilegesModel->isAdminUser() || @@ -241,6 +241,8 @@ public static function isShowTopLevelMenuItem($menu) } } + + return false; } return true;