Unverified Commit 102807e2 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(webservice) Apply values to tabs in correct order

The order may not be exact for dynamic tabs but at least it will not be
 dependent on JSON undefined behavior and will apply main tab first which
 is the most important.

issue #6110
Showing with 42 additions and 0 deletions
+42 -0
...@@ -508,6 +508,27 @@ class fdRPCService ...@@ -508,6 +508,27 @@ class fdRPCService
} else { } else {
$tabobject = objects::open($dn, $type); $tabobject = objects::open($dn, $type);
} }
$infos = objects::infos($type);
/* Note: This might not be exactly the right order but it’s the best we got */
$potentialTabsOrder = array_flip(array_map(
function ($a)
{
return $a['CLASS'];
},
$infos['tabClass']::getPotentialTabList($type, $infos)
));
uksort(
$values,
function ($k1, $k2) use ($potentialTabsOrder) {
if (!isset($potentialTabsOrder[$k1])) {
return 1;
} elseif (!isset($potentialTabsOrder[$k2])) {
return -1;
} else {
return $potentialTabsOrder[$k1] <=> $potentialTabsOrder[$k2];
}
}
);
foreach ($values as $tab => $tabvalues) { foreach ($values as $tab => $tabvalues) {
if (!isset($tabobject->by_object[$tab])) { if (!isset($tabobject->by_object[$tab])) {
throw new WebServiceError('This tab does not exists: "'.$tab.'"', 404); throw new WebServiceError('This tab does not exists: "'.$tab.'"', 404);
...@@ -573,6 +594,27 @@ class fdRPCService ...@@ -573,6 +594,27 @@ class fdRPCService
static::addLockOrThrow($dn); static::addLockOrThrow($dn);
try { try {
$tabobject = objects::open($dn, $type); $tabobject = objects::open($dn, $type);
$infos = objects::infos($type);
/* Note: This might not be exactly the right order but it’s the best we got */
$potentialTabsOrder = array_flip(array_map(
function ($a)
{
return $a['CLASS'];
},
$infos['tabClass']::getPotentialTabList($type, $infos)
));
uksort(
$values,
function ($k1, $k2) use ($potentialTabsOrder) {
if (!isset($potentialTabsOrder[$k1])) {
return 1;
} elseif (!isset($potentialTabsOrder[$k2])) {
return -1;
} else {
return $potentialTabsOrder[$k1] <=> $potentialTabsOrder[$k2];
}
}
);
foreach ($values as $tab => $tabvalues) { foreach ($values as $tab => $tabvalues) {
if (!isset($tabobject->by_object[$tab])) { if (!isset($tabobject->by_object[$tab])) {
throw new WebServiceError('This tab does not exists: "'.$tab.'"', 404); throw new WebServiceError('This tab does not exists: "'.$tab.'"', 404);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment