Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-95 Softcoding of service type production<=>monitored service flag relations. #209

Merged
merged 3 commits into from Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions config/gocdb_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,22 @@
</entity>
<!-- ========================================================== -->
<entity>
<name>service_type</name>
<field>
<fname>NAME</fname>
<length>255</length>
<regex>/^([[:alpha:]]|[[:digit:]]|[\._-])*$/</regex>
</field>
<field>
<fname>DESCRIPTION</fname>
<length>255</length>
<!--<regex>/^[a-zA-Z0-9\-\._\(\)\[\],;+:\/'"\s]*$/</regex>-->
<regex>/^[^`'\";&lt;&gt;]+$/</regex>
</field>
<name>service_type</name>
<field>
<fname>NAME</fname>
<length>255</length>
<regex>/^([[:alpha:]]|[[:digit:]]|[\._-])*$/</regex>
</field>
<field>
<fname>DESCRIPTION</fname>
<length>255</length>
<!--<regex>/^[a-zA-Z0-9\-\._\(\)\[\],;+:\/'"\s]*$/</regex>-->
<regex>/^[^`'\";&lt;&gt;]+$/</regex>
</field>
<field>
<fname>ALLOWMONITORINGEXCEPTION</fname>
<ftype>boolean</ftype>
</field>
</entity>
<!-- ========================================================== -->
<entity>
Expand Down
4 changes: 2 additions & 2 deletions htdocs/PI/write/PIWriteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ private function updateServicePropPut (\Service $service, $servicePropName, $ser

//Validate production/monitored flag combination
try {
$this->serviceService->validateProductionMonitoredCombination($service->getServiceType()->getName(), $production, $monitored);
$this->serviceService->validateProductionMonitoredCombination($service->getServiceType(), $production, $monitored);
} catch(\Exception $e){
$this->exceptionWithResponseCode(403, $e->getMessage());
}
Expand Down Expand Up @@ -1351,7 +1351,7 @@ private function updateEndpointPropPost (\EndpointLocation $endpoint, $endpointP
#POST not valid for Endpoint booleans as they are set when the entity created and so are already defined
$this->exceptionWithResponseCode(405,$this->genericExceptionMessages["cantPostABool"]);

} elseif ($this->serviceService->EndpointPropSet($endpoint, $endpointPropName)) {
} elseif ($this->serviceService->endpointPropSet($endpoint, $endpointPropName)) {
#POST method must fail if the value is already set
$this->exceptionWithResponseCode(409,$this->genericExceptionMessages["propAlreadySet"]);

Expand Down
30 changes: 20 additions & 10 deletions htdocs/web_portal/controllers/admin/add_service_type.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*______________________________________________________
*======================================================
* File: add_service_type.php
Expand All @@ -22,18 +23,19 @@
* limitations under the License.
/*======================================================*/
require_once __DIR__ . '/../utils.php';
require_once __DIR__.'/../../../../lib/Gocdb_Services/Factory.php';
require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';

/**
* Controller for an add service type request
* @global array $_POST only set if the browser has POSTed data
* @return null
*/
function add_type() {
function add_type()
{
//The following line will be needed if this controller is ever used for non administrators:
//checkPortalIsNotReadOnlyOrUserIsAdmin($user);

if($_POST) { // If we receive a POST request it's to add a service type
if ($_POST) { // If we receive a POST request it's to add a service type
submit();
} else { // If there is no post data, draw the add service type form
draw();
Expand All @@ -44,7 +46,8 @@ function add_type() {
* Draws the add service type form
* @return null
*/
function draw() {
function draw()
{
//Check the user has permission to see the page, will throw exception
//if correct permissions are lacking
checkUserIsAdmin();
Expand All @@ -58,27 +61,34 @@ function draw() {
* services layer's service type functions.
* @return null
*/
function submit() {
function submit()
{
require_once __DIR__ . '/../../../../htdocs/web_portal/components/Get_User_Principle.php';

//Get the posted service type data
$newValues = getSTDataFromWeb();

//get the user data for the add service type function (so it can check permissions)
$dn = Get_User_Principle();
/**
* Fudge for getUserByPrinciple return object namespace error
* @var \User $user
*/
$user = \Factory::getUserService()->getUserByPrinciple($dn);

try {
//function will through error if user does not have the correct permissions
//function will throw error if user does not have the correct permissions
/**
* @var \ServiceType $serviceType
*/
$serviceType = \Factory::getServiceTypeService()->addServiceType($newValues, $user);
$params = array('Name' => $serviceType->getName(),
'Description'=> $serviceType->getDescription(),
'ID'=> $serviceType->getId());
'Description' => $serviceType->getDescription(),
'AllowMonitoringException' => $serviceType->getAllowMonitoringException(),
'ID' => $serviceType->getId());
show_view("admin/added_service_type.php", $params, "Successfuly added new service type");
} catch (Exception $e) {
show_view('error.php', $e->getMessage());
die();
}
}

?>
37 changes: 25 additions & 12 deletions htdocs/web_portal/controllers/admin/edit_service_type.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*______________________________________________________
*======================================================
* File: edit_service_type.php
Expand All @@ -22,18 +23,19 @@
* limitations under the License.
/*======================================================*/
require_once __DIR__ . '/../utils.php';
require_once __DIR__.'/../../../../lib/Gocdb_Services/Factory.php';
require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';

/**
* Controller for an edit service type request
* @global array $_POST only set if the browser has POSTed data
* @return null
*/
function edit_type() {
function edit_type()
{
//The following line will be needed if this controller is ever used for non administrators:
//checkPortalIsNotReadOnlyOrUserIsAdmin($user);

if($_POST) { // If we receive a POST request it's for a service type edit
if ($_POST) { // If we receive a POST request it's for a service type edit
submit();
} else { // If there is no post data, draw the service type edit
draw();
Expand All @@ -44,19 +46,24 @@ function edit_type() {
* Draws the edit service type form
* @return null
*/
function draw() {
function draw()
{
//Check the user has permission to see the page, will throw exception
//if correct permissions are lacking
checkUserIsAdmin();
if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id']) ){
if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
throw new Exception("An id must be specified");
}

// Get the service type
/**
* @var \ServiceType $serviceType
*/
$serviceType = \Factory::getServiceTypeService()->getServiceType($_REQUEST['id']);

$params = array('Name' => $serviceType->getName(),'ID' => $serviceType->getId(),
'Description' => $serviceType->getDescription());
'Description' => $serviceType->getDescription(),
'AllowMonitoringException' => $serviceType->getAllowMonitoringException());

show_view("admin/edit_service_type.php", $params, "Edit " . $serviceType->getName());
}
Expand All @@ -66,7 +73,8 @@ function draw() {
* services layer's service type functions.
* @return null
*/
function submit() {
function submit()
{
require_once __DIR__ . '/../../../../htdocs/web_portal/components/Get_User_Principle.php';

//Get the posted service type data
Expand All @@ -78,19 +86,24 @@ function submit() {

//get the service type service and the service type being edited
$serv = \Factory::getServiceTypeService();
/**
* @var \ServiceType $unalteredServiceType
*/
$unalteredServiceType = $serv->getServiceType($newValues['ID']);

try {
//function will throw error if user does not have the correct permissions
$alteredServiceType =$serv->editServiceType($unalteredServiceType, $newValues, $user);
/**
* @var \User $user
*/
$alteredServiceType = $serv->editServiceType($unalteredServiceType, $newValues, $user);
$params = array('Name' => $alteredServiceType->getName(),
'Description'=> $alteredServiceType->getDescription(),
'ID'=> $alteredServiceType->getId());
'Description' => $alteredServiceType->getDescription(),
'AllowMonitoringException' => $alteredServiceType->getAllowMonitoringException(),
'ID' => $alteredServiceType->getId());
show_view("admin/edited_service_type.php", $params);
} catch (Exception $e) {
show_view('error.php', $e->getMessage());
die();
}
}

?>
28 changes: 18 additions & 10 deletions htdocs/web_portal/controllers/admin/view_service_type.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*______________________________________________________
*======================================================
* File: view_service_type.php
Expand All @@ -21,26 +22,33 @@
require_once __DIR__ . '/../utils.php';
require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';

function view_service_type(){
function view_service_type()
{
//Check the user has permission to see the page, will throw exception
//if correct permissions are lacking
checkUserIsAdmin();
if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id']) ){
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();
$serviceType =$serv ->getServiceType($_REQUEST['id']);
$serv = \Factory::getServiceTypeService();
/**
* @var \ServiceType $serviceType
*/
$serviceType = $serv ->getServiceType($_REQUEST['id']);

$params['Name'] = $serviceType -> getName();
$params['Description'] = $serviceType -> getDescription();
$params['ID']= $serviceType ->getId();
$params['Services'] = $serv ->getServices($params['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']);

}

Loading