From 1d43219f91e2a69fc5ea0a0f9ce2dcf99a057db0 Mon Sep 17 00:00:00 2001 From: Sae126V Date: Tue, 12 Sep 2023 08:10:47 +0000 Subject: [PATCH] [GT-183] Add service types page for non-admins --- config/web_portal/menu.xml | 20 ++++++++----- config/web_portal/menu.xsd | 3 +- .../controllers/admin/view_service_type.php | 20 ++++++------- .../controllers/admin/view_service_types.php | 8 +----- htdocs/web_portal/controllers/utils.php | 10 +++++++ htdocs/web_portal/index.php | 4 +-- .../views/admin/added_service_type.php | 2 +- .../admin/delete_service_type_denied.php | 5 +++- .../views/admin/edited_service_type.php | 6 ++-- .../views/admin/view_service_type.php | 7 +++-- .../views/admin/view_service_types.php | 28 ++++++++----------- 11 files changed, 62 insertions(+), 51 deletions(-) diff --git a/config/web_portal/menu.xml b/config/web_portal/menu.xml index 310afcfc8..161a1eb3b 100644 --- a/config/web_portal/menu.xml +++ b/config/web_portal/menu.xml @@ -42,6 +42,12 @@ index.php?Page_Type=Services + + write_enabled + Service Types + index.php?Page_Type=Service_Types + + all Scopes @@ -136,7 +142,13 @@ Add Project index.php?Page_Type=Admin_Add_Project - + + + admin + Add Service Type + index.php?Page_Type=Admin_Add_Service_Type + + admin Move Service @@ -149,12 +161,6 @@ index.php?Page_Type=Admin_Move_Site - - admin - Service Types - index.php?Page_Type=Admin_Service_Types - - admin Users diff --git a/config/web_portal/menu.xsd b/config/web_portal/menu.xsd index 7a62fad05..40d7ce12d 100644 --- a/config/web_portal/menu.xsd +++ b/config/web_portal/menu.xsd @@ -15,6 +15,7 @@ + @@ -26,9 +27,9 @@ + - 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..60c8f6106 100644 --- a/htdocs/web_portal/controllers/admin/view_service_types.php +++ b/htdocs/web_portal/controllers/admin/view_service_types.php @@ -23,15 +23,9 @@ 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(); - - $dn = Get_User_Principle(); - $user = \Factory::getUserService()->getUserByPrinciple($dn); $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/added_service_type.php b/htdocs/web_portal/views/admin/added_service_type.php index 8654752d9..21f7ba52d 100644 --- a/htdocs/web_portal/views/admin/added_service_type.php +++ b/htdocs/web_portal/views/admin/added_service_type.php @@ -4,7 +4,7 @@ - + Click here to view the service type. diff --git a/htdocs/web_portal/views/admin/delete_service_type_denied.php b/htdocs/web_portal/views/admin/delete_service_type_denied.php index cde534411..033c4e9cb 100644 --- a/htdocs/web_portal/views/admin/delete_service_type_denied.php +++ b/htdocs/web_portal/views/admin/delete_service_type_denied.php @@ -3,7 +3,10 @@

Deletion Failed


The service type ' - + + getName());?> ' can not be deleted as the following services are still of this type: diff --git a/htdocs/web_portal/views/admin/edited_service_type.php b/htdocs/web_portal/views/admin/edited_service_type.php index 76b3924eb..8d9ed3bb0 100644 --- a/htdocs/web_portal/views/admin/edited_service_type.php +++ b/htdocs/web_portal/views/admin/edited_service_type.php @@ -1,7 +1,9 @@

Success


-

- Service Type properties have been successfully edited to - +

+ + Service Type properties have been successfully edited to -

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 @@
- - + +