N°4921 - Add support for attcode & attvalue parameters in URL to access an object (#273)

This is a way to solve problems when an object ref and id isn't equals : for example id=99 and ref = 100.
This could happen since iTop 2.7.0, see https://www.itophub.io/wiki/page?id=2_7_0%3Arelease%3A2_7_whats_new#ticket_ref_generation

Note that id parameter can be set to the object's friendlyname as a workaround, but this might not be enough for some objects where friendlyname contains more that the ref field (for example title, org, ...)

* Admin console : new UI.php URL parameters : attcode and attvalue.
Example URLs : 
/pages/UI.php?operation=details&class=UserRequest&id=99
/pages/UI.php?operation=details&class=UserRequest&attcode=ref&attvalue=R-000100

An exception will be thrown if no object is found or multiple instances are.

* User portal
New route : /object/view/{sObjectClass}/{sObjectAttCode}/{sObjectAttValue}
For example :
/pages/exec.php/object/view/UserRequest/99?exec_module=itop-portal-base&exec_page=index.php&portal_id=itop-portal
/pages/exec.php/object/view/UserRequest/ref/R-000100?exec_module=itop-portal-base&exec_page=index.php&portal_id=itop-portal

On error we will get a 404 error page
This commit is contained in:
Pierre Goiffon
2022-03-09 10:51:21 +01:00
committed by GitHub
parent 5854c199d0
commit 8d4545f008
4 changed files with 139 additions and 54 deletions

View File

@@ -346,22 +346,30 @@ try
case 'details': // Details of an object
$sClass = utils::ReadParam('class', '', false, 'class');
$id = utils::ReadParam('id', '');
if ( empty($sClass) || empty($id))
{
throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
if (empty($sClass)) {
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
}
if (is_numeric($id))
{
$oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
$id = utils::ReadParam('id', null);
if (false === is_null($id)) {
if (is_numeric($id)) {
$oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
} else {
$oObj = MetaModel::GetObjectByName($sClass, $id, false /* MustBeFound */);
}
} else {
$sAttCode = utils::ReadParam('attcode', '');
$sAttValue = utils::ReadParam('attvalue', '');
if ((strlen($sAttCode) === 0) || (strlen($sAttValue) === 0)) {
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
}
$oObj = MetaModel::GetObjectByColumn($sClass, $sAttCode, $sAttValue, true);
}
else
{
$oObj = MetaModel::GetObjectByName($sClass, $id, false /* MustBeFound */);
}
if (is_null($oObj))
{
if (is_null($oObj)) {
// Check anyhow if there is a message for this object (like you've just created it)
$sMessageKey = $sClass.'::'.$id;
DisplayMessages($sMessageKey, $oP);
@@ -369,8 +377,7 @@ try
// Attempt to load the object in archive mode
utils::PushArchiveMode(true);
if (is_numeric($id))
{
if (is_numeric($id)) {
$oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
}
else