Skip to content

Commit

Permalink
[GT-183] Add service types page for non-admins
Browse files Browse the repository at this point in the history
  • Loading branch information
Sae126V committed Sep 11, 2023
1 parent a8d8285 commit d1e50cb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 28 deletions.
8 changes: 7 additions & 1 deletion config/web_portal/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<link>index.php?Page_Type=View_Role_Action_Mappings</link>
</RoleActionMappings>

<ViewServiceTypes>
<show_on_instance>write_enabled</show_on_instance>
<name>Service Types</name>
<link>index.php?Page_Type=Service_Types</link>
</ViewServiceTypes>

<spacer>
<spacer>Add</spacer>
<show_on_instance>write_enabled</show_on_instance>
Expand Down Expand Up @@ -152,7 +158,7 @@
<ServiceTypes>
<show_on_instance>admin</show_on_instance>
<name>Service Types</name>
<link>index.php?Page_Type=Admin_Service_Types</link>
<link>index.php?Page_Type=Service_Types</link>
</ServiceTypes>

<Users>
Expand Down
1 change: 1 addition & 0 deletions config/web_portal/menu.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<xs:element name="Services" type="showType" minOccurs="0"/>
<xs:element name="Scopes" type="showType" minOccurs="0"/>
<xs:element name="RoleActionMappings" type="showType" minOccurs="0"/>
<xs:element name="ViewServiceTypes" type="showType" minOccurs="0"/>
<xs:element name="AddSite" type="showType" minOccurs="0"/>
<xs:element name="AddServiceGroup" type="showType" minOccurs="0"/>
<xs:element name="AddService" type="showType" minOccurs="0"/>
Expand Down
14 changes: 14 additions & 0 deletions htdocs/web_portal/components/Draw_Components/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,27 @@ 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 .= "<hr style=\"clear: both;\"/>";
$html .= "<ul class=\"Smaller_Left_Padding Smaller_Top_Margin\">";
foreach($menus_xml->$menu_name->children() as $key => $value)
{
// 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";
}
}
Expand Down
20 changes: 10 additions & 10 deletions htdocs/web_portal/controllers/admin/view_service_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@

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();
/**
* @var \ServiceType $serviceType
*/
$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']);
}
12 changes: 6 additions & 6 deletions htdocs/web_portal/controllers/admin/view_service_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
10 changes: 10 additions & 0 deletions htdocs/web_portal/controllers/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 2 additions & 2 deletions htdocs/web_portal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions htdocs/web_portal/views/admin/view_service_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$id = $params['ID'];
$services = $params['Services'];
$SEsCount = sizeof($services);
$portalIsReadOnly = $params['portalIsReadOnly'];
$isUserAdmin = $params['isUserAdmin'];
?>


Expand All @@ -20,8 +20,9 @@
</div>

<!--Edit/Delete buttons-->
<!-- Only show when portal is not read only mode -->
<?php if (!$portalIsReadOnly) :?>
<!--Enable edit and delete functionality ONLY when
the web portal is accessed by an Admin.-->
<?php if ($isUserAdmin) :?>
<div style="float: right;">
<div style="float: right; margin-left: 2em;">
<a href="index.php?Page_Type=Admin_Edit_Service_Type&amp;id=<?php echo $id ?>">
Expand Down
20 changes: 14 additions & 6 deletions htdocs/web_portal/views/admin/view_service_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
Service Types
</h1>
<span style="clear: both; float: left; padding-bottom: 0.4em;">
Click on the name of a service type to edit or delete it.
All Service Types in GOCDB.
</span>
</div>

<!-- Only show add when not in read only mode-->
<?php if (!$params['portalIsReadOnly']) :?>
<!--Enable Add functionality ONLY when
the web portal is accessed by an Admin.-->
<?php if ($params['isUserAdmin']) :?>
<div style="float: right;">
<center>
<a href="index.php?Page_Type=Admin_Add_Service_Type">
Expand All @@ -37,16 +38,23 @@
</tr>
<?php
$num = 2;
$searchName = 'Service_Type';

if ($numberOfServiceTypes > 0) {
foreach ($params['ServiceTypes'] as $serviceType) {
?>
<tr class="site_table_row_<?php echo $num ?>">
<td class="site_table" style="width: 30%">
<div style="background-color: inherit;">
<span style="vertical-align: middle;">
<a href="index.php?Page_Type=Admin_Service_Type&amp;id=<?php echo $serviceType->getId() ?>">
<?php xecho($serviceType->getName()); ?>
</a>
<?php
echo "<a href=\"index.php?Page_Type="
. $searchName
. "&amp;id=" . $serviceType->getId()
. "\">"
. $serviceType->getName()
. "</a>";
?>
</span>
</div>
</td>
Expand Down

0 comments on commit d1e50cb

Please sign in to comment.