diff --git a/config/web_portal/menu.xml b/config/web_portal/menu.xml index 310afcfc8..4a7f1fa77 100644 --- a/config/web_portal/menu.xml +++ b/config/web_portal/menu.xml @@ -54,6 +54,12 @@ index.php?Page_Type=View_Role_Action_Mappings + + write_enabled + Service Types + index.php?Page_Type=Service_Types + + Add write_enabled @@ -152,7 +158,7 @@ admin Service Types - index.php?Page_Type=Admin_Service_Types + index.php?Page_Type=Service_Types diff --git a/config/web_portal/menu.xsd b/config/web_portal/menu.xsd index 7a62fad05..5aa6b1fcf 100644 --- a/config/web_portal/menu.xsd +++ b/config/web_portal/menu.xsd @@ -17,6 +17,7 @@ + diff --git a/htdocs/web_portal/components/Draw_Components/menu.php b/htdocs/web_portal/components/Draw_Components/menu.php index bcd58fd53..5dc4791c1 100644 --- a/htdocs/web_portal/components/Draw_Components/menu.php +++ b/htdocs/web_portal/components/Draw_Components/menu.php @@ -40,6 +40,9 @@ function draw_menu($menu_name) // and draws that menu as HTML function xml_to_menu($menu_name, $menus_xml) { + $identifier = Get_User_Principle(); + $userService = \Factory::getUserService(); + $user = $userService->getUserByPrinciple($identifier); $html = ""; $html .= "
"; $html .= "
    "; @@ -47,6 +50,17 @@ function xml_to_menu($menu_name, $menus_xml) { // Check if display of menu is overridden in the local configuration if (\Factory::getConfigService()->showMenu($key)) { + /** + * @var \User $user + */ + $isUserAdmin = isset($user) ? $user->isAdmin() : false; + + if ($key == "ViewServiceTypes") { + if ($isUserAdmin) { + continue; + } + } + $html .= add_menu_item($value) . "\n"; } } diff --git a/htdocs/web_portal/controllers/admin/view_service_type.php b/htdocs/web_portal/controllers/admin/view_service_type.php index f94895324..a738865bb 100644 --- a/htdocs/web_portal/controllers/admin/view_service_type.php +++ b/htdocs/web_portal/controllers/admin/view_service_type.php @@ -24,14 +24,19 @@ function view_service_type() { - //Check the user has permission to see the page, will throw exception - //if correct permissions are lacking - checkUserIsAdmin(); + $params = []; + + $identifier = Get_User_Principle(); + $user = \Factory::getUserService()->getUserByPrinciple($identifier); + + /** + * @var \User $user + */ + $params['isUserAdmin'] = checkUserForAdminCredentials($user); + if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) { throw new Exception("An id must be specified"); } - $dn = Get_User_Principle(); - $user = \Factory::getUserService()->getUserByPrinciple($dn); $serv = \Factory::getServiceTypeService(); /** @@ -39,16 +44,11 @@ function view_service_type() */ $serviceType = $serv ->getServiceType($_REQUEST['id']); - $params = []; $params['Name'] = $serviceType->getName(); $params['Description'] = $serviceType->getDescription(); $params['ID'] = $serviceType->getId(); $params['AllowMonitoringException'] = $serviceType->getAllowMonitoringException(); $params['Services'] = $serv->getServices($params['ID']); - /** - * @var \User $user - */ - $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user); show_view("admin/view_service_type.php", $params, $params['Name']); } diff --git a/htdocs/web_portal/controllers/admin/view_service_types.php b/htdocs/web_portal/controllers/admin/view_service_types.php index 1e28a3a6c..dc72df991 100644 --- a/htdocs/web_portal/controllers/admin/view_service_types.php +++ b/htdocs/web_portal/controllers/admin/view_service_types.php @@ -23,15 +23,15 @@ require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php'; function show_all(){ - //Check the user has permission to see the page, will throw exception - //if correct permissions are lacking - checkUserIsAdmin(); + $params = []; - $dn = Get_User_Principle(); - $user = \Factory::getUserService()->getUserByPrinciple($dn); + $identifier = Get_User_Principle(); + $user = \Factory::getUserService()->getUserByPrinciple($identifier); + + $params['isUserAdmin'] = checkUserForAdminCredentials($user); $serviceTypes = \Factory::getServiceTypeService()->getServiceTypes(); $params['ServiceTypes']= $serviceTypes; - $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user); + show_view('admin/view_service_types.php', $params, 'Service Types'); } diff --git a/htdocs/web_portal/controllers/utils.php b/htdocs/web_portal/controllers/utils.php index aa98bb42e..763a208b1 100644 --- a/htdocs/web_portal/controllers/utils.php +++ b/htdocs/web_portal/controllers/utils.php @@ -817,3 +817,13 @@ function getReadPDParams($user) } return array($userIsAdmin, $authenticated); } + +/** + * Helper to identify whether the user is an Admin or NOT. + * + * Returns `true` if the user is an Admin, `false` otherwise. + */ +function checkUserForAdminCredentials($user) +{ + return $user->isAdmin(); +} diff --git a/htdocs/web_portal/index.php b/htdocs/web_portal/index.php index 6947b333c..1d1d7e2ae 100644 --- a/htdocs/web_portal/index.php +++ b/htdocs/web_portal/index.php @@ -450,12 +450,12 @@ function Draw_Page($Page_Type) { require_once __DIR__.'/controllers/admin/move_service_end_point.php'; move_service_end_point(); break; - case "Admin_Service_Types": + case "Service_Types": rejectIfNotAuthenticated(); require_once __DIR__.'/controllers/admin/view_service_types.php'; show_all(); break; - case "Admin_Service_Type": + case "Service_Type": rejectIfNotAuthenticated(); require_once __DIR__.'/controllers/admin/view_service_type.php'; view_service_type(); diff --git a/htdocs/web_portal/views/admin/view_service_type.php b/htdocs/web_portal/views/admin/view_service_type.php index 0c407dccf..e06f31137 100644 --- a/htdocs/web_portal/views/admin/view_service_type.php +++ b/htdocs/web_portal/views/admin/view_service_type.php @@ -5,7 +5,7 @@ $id = $params['ID']; $services = $params['Services']; $SEsCount = sizeof($services); -$portalIsReadOnly = $params['portalIsReadOnly']; +$isUserAdmin = $params['isUserAdmin']; ?> @@ -20,8 +20,9 @@ - - + +