Commit 8d14d66f authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

FIX search messages to allow access to ancestors of recipients and senders

parent c128ca71
...@@ -83,7 +83,7 @@ class ArchiveRestitutionRequest extends abstractMessage ...@@ -83,7 +83,7 @@ class ArchiveRestitutionRequest extends abstractMessage
$queryParts[] = "senderOrgRegNumber=$registrationNumber"; $queryParts[] = "senderOrgRegNumber=$registrationNumber";
$queryParts[] = "active=true"; $queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300); return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
} }
/** /**
......
...@@ -262,7 +262,7 @@ class message ...@@ -262,7 +262,7 @@ class message
{ {
$queryParts = $this->searchMessage($type, $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate); $queryParts = $this->searchMessage($type, $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate);
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300); return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
} }
/** /**
...@@ -325,37 +325,44 @@ class message ...@@ -325,37 +325,44 @@ class message
$queryParts[] = "reference='$reference'"; $queryParts[] = "reference='$reference'";
} }
if ($type) { if ($type) {
$clause = ""; $clause = [];
if ($type == "ArchiveDelivery") { if ($type == "ArchiveDelivery") {
if (in_array('originator', $currentService->orgRoleCodes) || in_array('archiver', $currentService->orgRoleCodes)) { if (in_array('originator', $currentService->orgRoleCodes) || in_array('archiver', $currentService->orgRoleCodes)) {
$clause .= "type='*$type*'"; $clause[] = "type='*$type*'";
} }
if (in_array('controlAuthority', $currentService->orgRoleCodes)) { if (in_array('controlAuthority', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDeliveryRequest'"; $clause[] = "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDeliveryRequest'";
} }
} elseif ($type == "ArchiveDestruction") { } elseif ($type == "ArchiveDestruction") {
if (in_array('archiver', $currentService->orgRoleCodes)) { if (in_array('archiver', $currentService->orgRoleCodes)) {
$clause .= "type='*$type*'"; $clause[] = "type='*$type*'";
} }
if (in_array('originator', $currentService->orgRoleCodes)) { if (in_array('originator', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationOriginatingRequest' AND authorizationReason='ArchiveDestructionRequest'"; $clause[] = "type='AuthorizationOriginatingRequest' AND authorizationReason='ArchiveDestructionRequest'";
} }
if (in_array('controlAuthority', $currentService->orgRoleCodes)) { if (in_array('controlAuthority', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDestructionRequest'"; $clause[] = "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDestructionRequest'";
} }
} elseif ($type == "ArchiveRestitution") { } elseif ($type == "ArchiveRestitution") {
$clause .= "type=['ArchiveRestitutionRequest','ArchiveRestitution']"; $clause[] = "type=['ArchiveRestitutionRequest','ArchiveRestitution']";
} else { } else {
$clause = "type='$type' AND status !='template'"; $clause[] = "type='$type' AND status !='template'";
} }
$queryParts[] = $clause; if (!empty($clause)) {
$queryParts[] =
'('
.\laabs\implode(') OR (', $clause)
.')';
}
} }
$queryParts[] = "(recipientOrgRegNumber='$currentService->registrationNumber' OR senderOrgRegNumber='$currentService->registrationNumber')"; $orgUnitsClause = $this->getCurrentRegistrationNumber();
$queryParts[] = "(recipientOrgRegNumber=$orgUnitsClause OR senderOrgRegNumber=$orgUnitsClause)";
return $queryParts; return $queryParts;
} }
...@@ -1012,7 +1019,7 @@ class message ...@@ -1012,7 +1019,7 @@ class message
{ {
$queryParts = $this->searchMessage(null, $reference); $queryParts = $this->searchMessage(null, $reference);
$message = $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300); $message = $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
if (!$message) { if (!$message) {
return null; return null;
......
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