Commit e2cd05a6 authored by Oana-Eliza Alexa's avatar Oana-Eliza Alexa
Browse files

redesign

1 merge request!76Draft: Resolve "Redesign notifications class"
Showing with 75 additions and 34 deletions
+75 -34
...@@ -4,6 +4,7 @@ class Notifications implements EndpointInterface ...@@ -4,6 +4,7 @@ class Notifications implements EndpointInterface
{ {
private TaskGateway $gateway; private TaskGateway $gateway;
private string $errorMessage = 'No matching audited attributes with monitored attributes, safely removed!';
public function __construct (TaskGateway $gateway) public function __construct (TaskGateway $gateway)
{ {
...@@ -61,7 +62,6 @@ class Notifications implements EndpointInterface ...@@ -61,7 +62,6 @@ class Notifications implements EndpointInterface
foreach ($notificationsSubTasks as $task) { foreach ($notificationsSubTasks as $task) {
// If the tasks must be treated - status and scheduled - process the sub-tasks // If the tasks must be treated - status and scheduled - process the sub-tasks
if ($this->gateway->statusAndScheduleCheck($task)) { if ($this->gateway->statusAndScheduleCheck($task)) {
// Retrieve data from the main task // Retrieve data from the main task
$notificationsMainTask = $this->getNotificationsMainTask($task['fdtasksgranularmaster'][0]); $notificationsMainTask = $this->getNotificationsMainTask($task['fdtasksgranularmaster'][0]);
$notificationsMainTaskName = $task['fdtasksgranularmaster'][0]; $notificationsMainTaskName = $task['fdtasksgranularmaster'][0];
...@@ -69,26 +69,7 @@ class Notifications implements EndpointInterface ...@@ -69,26 +69,7 @@ class Notifications implements EndpointInterface
// Generate the mail form with all mail controller requirements // Generate the mail form with all mail controller requirements
$mailTemplateForm = $this->generateMainTaskMailTemplate($notificationsMainTask); $mailTemplateForm = $this->generateMainTaskMailTemplate($notificationsMainTask);
// Simply retrieve the list of audited attributes $matchingAttrs = $this->getMatchingAttrs($notificationsMainTask, $task);
$auditAttributes = $this->decodeAuditAttributes($task);
// Recovering monitored attributes list from the defined notification task.
$monitoredAttrs = $notificationsMainTask[0]['fdtasksnotificationsattributes'];
// Reformat supann
$monitoredSupannResource = $this->getSupannResourceState($notificationsMainTask[0]);
// Simply remove keys with 'count' reported by ldap.
$this->gateway->unsetCountKeys($monitoredAttrs);
$this->gateway->unsetCountKeys($monitoredSupannResource);
// Find matching attributes between audited and monitored attributes
$matchingAttrs = Utils::findMatchingKeys($auditAttributes, $monitoredAttrs);
// Verify Supann resource state if applicable
if ($this->shouldVerifySupannResource($monitoredSupannResource, $auditAttributes)) {
// Adds it to the mating attrs for further notification process.
$matchingAttrs[] = 'supannRessourceEtat';
}
if (!empty($matchingAttrs)) { if (!empty($matchingAttrs)) {
// Fill an array with UID of audited user and related matching attributes // Fill an array with UID of audited user and related matching attributes
...@@ -103,7 +84,7 @@ class Notifications implements EndpointInterface ...@@ -103,7 +84,7 @@ class Notifications implements EndpointInterface
} else { // Simply remove the subTask has no notifications are required } else { // Simply remove the subTask has no notifications are required
$result[$task['dn']]['Removed'] = $this->gateway->removeSubTask($task['dn']); $result[$task['dn']]['Removed'] = $this->gateway->removeSubTask($task['dn']);
$result[$task['dn']]['Status'] = 'No matching audited attributes with monitored attributes, safely removed!'; $result[$task['dn']]['Status'] = $this->errorMessage;
} }
} }
} }
...@@ -115,6 +96,32 @@ class Notifications implements EndpointInterface ...@@ -115,6 +96,32 @@ class Notifications implements EndpointInterface
return $result; return $result;
} }
private function getMatchingAttrs (array $notificationsMainTask, array $task): array
{
// Simply retrieve the list of audited attributes
$auditAttributes = $this->decodeAuditAttributes($task);
// Recovering monitored attributes list from the defined notification task.
$monitoredAttrs = $notificationsMainTask[0]['fdtasksnotificationsattributes'];
// Reformat supann
$monitoredSupannResource = $this->getSupannResourceState($notificationsMainTask[0]);
// Simply remove keys with 'count' reported by ldap.
$this->gateway->unsetCountKeys($monitoredAttrs);
$this->gateway->unsetCountKeys($monitoredSupannResource);
// Find matching attributes between audited and monitored attributes
$matchingAttrs = $this->findMatchingAttributes($auditAttributes, $monitoredAttrs);
// Verify Supann resource state if applicable
if ($this->shouldVerifySupannResource($monitoredSupannResource, $auditAttributes)) {
// Adds it to the mating attrs for further notification process.
$matchingAttrs[] = 'supannRessourceEtat';
}
return $matchingAttrs;
}
/** /**
* Determine if Supann resource verification is needed. * Determine if Supann resource verification is needed.
* *
...@@ -165,6 +172,30 @@ class Notifications implements EndpointInterface ...@@ -165,6 +172,30 @@ class Notifications implements EndpointInterface
return $auditAttributes; return $auditAttributes;
} }
/**
* Find matching attributes between audit and monitored attributes.
*
* @param array|null $auditAttributes
* @param array $monitoredAttrs
* @return array
*/
private function findMatchingAttributes (?array $auditAttributes, array $monitoredAttrs): array
{
$matchingAttrs = [];
if (!empty($auditAttributes)) {
foreach ($auditAttributes as $attributeName) {
foreach ($monitoredAttrs as $monitoredAttr) {
if (!empty($attributeName) && array_key_exists($monitoredAttr, $attributeName)) {
$matchingAttrs[] = $monitoredAttr;
}
}
}
}
return $matchingAttrs;
}
/** /**
* @param array $supannResource * @param array $supannResource
* @param array $auditedAttrs * @param array $auditedAttrs
...@@ -173,25 +204,35 @@ class Notifications implements EndpointInterface ...@@ -173,25 +204,35 @@ class Notifications implements EndpointInterface
*/ */
private function verifySupannState (array $supannResource, array $auditedAttrs): bool private function verifySupannState (array $supannResource, array $auditedAttrs): bool
{ {
$result = FALSE;
//Construct Supann Resource State as string //Construct Supann Resource State as string
$monitoredSupannState = '{' . $supannResource['resource'][0] . '}' . $supannResource['state'][0];
if (!empty($supannResource['subState'][0])) { if (!empty($supannResource['subState'][0])) {
$monitoredSupannState = '{' . $supannResource['resource'][0] . '}' . $supannResource['state'][0] . ':' . $supannResource['subState'][0]; $monitoredSupannState = $monitoredSupannState . ':' . $supannResource['subState'][0];
} else {
$monitoredSupannState = '{' . $supannResource['resource'][0] . '}' . $supannResource['state'][0];
} }
// Get all the values only of a multidimensional array. // Get all the values only of a multidimensional array.
$auditedValues = Utils::getArrayValuesRecursive($auditedAttrs); $auditedValues = $this->getArrayValuesRecursive($auditedAttrs);
return in_array($monitoredSupannState, $auditedValues);
}
if (in_array($monitoredSupannState, $auditedValues)) { /**
$result = TRUE; * @param $array
} else { * @return array
$result = FALSE; * Note : simply return all values of a multi-dimensional array.
*/
public function getArrayValuesRecursive ($array)
{
$values = [];
foreach ($array as $value) {
if (is_array($value)) {
// If value is an array, merge its values recursively
$values = array_merge($values, $this->getArrayValuesRecursive($value));
} else {
// If value is not an array, add it to the result
$values[] = $value;
}
} }
return $values;
return $result;
} }
/** /**
......
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