diff --git a/library/plugins/MailUtils.php b/library/orchLibrary/orchLibraryMailUtils.php similarity index 96% rename from library/plugins/MailUtils.php rename to library/orchLibrary/orchLibraryMailUtils.php index 87f4c6420bcd265b82ffb32d511bd63f66d79422..60af1159896d4724a51c2debfd1ee5c84e3ad064 100644 --- a/library/plugins/MailUtils.php +++ b/library/orchLibrary/orchLibraryMailUtils.php @@ -1,6 +1,6 @@ <?php -class MailUtils +class orchLibraryMailUtils { public function __construct () { diff --git a/library/plugins/ReminderTokenUtils.php b/library/orchLibrary/orchLibraryReminderTokenUtils.php similarity index 99% rename from library/plugins/ReminderTokenUtils.php rename to library/orchLibrary/orchLibraryReminderTokenUtils.php index bb08d24552400a9edf615d4120908ddb4986fa04..8d33a03481d4a371125b0c8aaa355f1484f08d66 100644 --- a/library/plugins/ReminderTokenUtils.php +++ b/library/orchLibrary/orchLibraryReminderTokenUtils.php @@ -1,6 +1,6 @@ <?php -class ReminderTokenUtils +class orchLibraryReminderTokenUtils { public function __construct () { diff --git a/library/plugins/Utils.php b/library/orchLibrary/orchLibraryUtils.php similarity index 98% rename from library/plugins/Utils.php rename to library/orchLibrary/orchLibraryUtils.php index 10eafe626a4d288e6a5a66a80b54102547b05ca5..9e064234a117da23ca063f5f574bf1917340d086 100644 --- a/library/plugins/Utils.php +++ b/library/orchLibrary/orchLibraryUtils.php @@ -1,6 +1,6 @@ <?php -class Utils +class orchLibraryUtils { public function __construct () { diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php index 2ef3e2f08d4c90222b5bb9b3d42882d13ed8199a..aa6932abed3f560ac17e98ece4deb4bf471d6a18 100644 --- a/plugins/tasks/Archive.php +++ b/plugins/tasks/Archive.php @@ -8,33 +8,33 @@ class Archive implements EndpointInterface public function __construct (TaskGateway $gateway) { - $this->gateway = $gateway; + $this->gateway = $gateway; } - /** - * @return array - * Part of the interface of orchestrator plugin to treat GET method - */ + /** + * @return array + * Part of the interface of orchestrator plugin to treat GET method + */ public function processEndPointGet (): array { - // Retrieve tasks of type 'archive' - return $this->gateway->getObjectTypeTask('archive'); + // Retrieve tasks of type 'archive' + return $this->gateway->getObjectTypeTask('archive'); } - /** - * @param array|null $data - * @return array - * @throws Exception - * Note: Part of the interface of orchestrator plugin to treat PATCH method - */ + /** + * @param array|null $data + * @return array + * @throws Exception + * Note: Part of the interface of orchestrator plugin to treat PATCH method + */ public function processEndPointPatch (array $data = NULL): array { - $result = []; - $archiveTasks = $this->gateway->getObjectTypeTask('archive'); + $result = []; + $archiveTasks = $this->gateway->getObjectTypeTask('archive'); - // Initialize the WebServiceCall object for login - $webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST'); - $webServiceCall->setCurlSettings(); // Perform login and set the token + // Initialize the WebServiceCall object for login + $webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST'); + $webServiceCall->setCurlSettings(); // Perform login and set the token foreach ($archiveTasks as $task) { try { @@ -43,95 +43,143 @@ class Archive implements EndpointInterface continue; } - // Receive null or 'toBeArchived' - $supannState = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]); + // Retrieve the desired supann status from the main task + $desiredSupannStatus = $this->getArchiveTaskBehaviorFromMainTask($task['fdtasksgranularmaster'][0]); - if ($supannState !== 'toBeArchived') { + // Retrieve the current supann status of the user + $currentSupannStatus = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]); + + // Check if the current supann status matches the desired status + if (!$this->isSupannStatusMatching($desiredSupannStatus, $currentSupannStatus)) { // The task does not meet the criteria for archiving and can therefore be suppressed $result[$task['dn']]['result'] = "User does not meet the criteria for archiving."; $this->gateway->removeSubTask($task['dn']); continue; } - // Set the archive endpoint and method using the same WebServiceCall object - $archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]); - $webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request - $response = $webServiceCall->execute(); + // Set the archive endpoint and method using the same WebServiceCall object + $archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]); + $webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request + $response = $webServiceCall->execute(); - // Check if the HTTP status code is 204 + // Check if the HTTP status code is 204 if ($webServiceCall->getHttpStatusCode() === 204) { - $result[$task['dn']]['result'] = "User successfully archived."; + $result[$task['dn']]['result'] = "User " . $task['fdtasksgranulardn'][0] . " successfully archived."; $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2'); } else { throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode()); } } catch (Exception $e) { - $result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage(); - $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage()); + $result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage(); + $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage()); } } - return $result; + return $result; } - /** - * @param array|null $data - * @return array - * Note: Part of the interface of orchestrator plugin to treat POST method - */ + /** + * @param array|null $data + * @return array + * Note: Part of the interface of orchestrator plugin to treat POST method + */ public function processEndPointPost (array $data = NULL): array { - return []; + return []; } - /** - * @param array|null $data - * @return array - * Note: Part of the interface of orchestrator plugin to treat DELETE method - */ + /** + * @param array|null $data + * @return array + * Note: Part of the interface of orchestrator plugin to treat DELETE method + */ public function processEndPointDelete (array $data = NULL): array { - return []; + return []; } - /** - * Retrieve the supannAccountStatus of a user - * @param string $userDn - * @return string|null - */ - private function getUserSupannAccountStatus (string $userDn): ?string + /** + * Retrieve the supannAccountStatus of a user + * @param string $userDn + * @return array + */ + private function getUserSupannAccountStatus (string $userDn): array { - $supannState = $this->gateway->getLdapTasks( + return $this->gateway->getLdapTasks( '(objectClass=supannPerson)', ['supannRessourceEtatDate'], '', $userDn ); + } - if ($this->hasToBeArchived($supannState)) { - return 'toBeArchived'; - } - - return NULL; + /** + * @param string $taskDN + * @return array + * Note: Retrieve the desired supann status from the main task attributes. + */ + private function getArchiveTaskBehaviorFromMainTask (string $taskDN): array + { + return $this->gateway->getLdapTasks( + '(objectClass=*)', + ['fdArchiveTaskResource', 'fdArchiveTaskState', 'fdArchiveTaskSubState'], + '', + $taskDN + ); } - private function hasToBeArchived (array $supannState): bool + /** + * @param array $desiredStatus + * @param array $currentStatus + * @return bool + * Note: Compare the desired supann status with the current status to determine if they match. + */ + private function isSupannStatusMatching (array $desiredStatus, array $currentStatus): bool { - if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) { + if (empty($currentStatus[0]['supannressourceetatdate'])) { return FALSE; } - foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) { - // Skip non-numeric keys (e.g., 'count') + // Extract the desired attributes + $desiredAttributes = $this->extractDesiredAttributes($desiredStatus); + + if (!$desiredAttributes['resource'] || !$desiredAttributes['state']) { + return FALSE; + } + + // Check if any of the current supannressourceetatdate values match the desired attributes + foreach ($currentStatus[0]['supannressourceetatdate'] as $key => $resource) { if (!is_numeric($key)) { continue; } - if (strpos($value, '{COMPTE}I:toBeArchived') !== FALSE) { + if ($this->doesResourceMatch($resource, $desiredAttributes)) { return TRUE; } } return FALSE; } + + private function extractDesiredAttributes (array $desiredStatus): array + { + return [ + 'resource' => $desiredStatus[0]['fdarchivetaskresource'][0] ?? NULL, + 'state' => $desiredStatus[0]['fdarchivetaskstate'][0] ?? NULL, + 'substate' => $desiredStatus[0]['fdarchivetasksubstate'][0] ?? NULL, + ]; + } + + private function doesResourceMatch (string $resource, array $desiredAttributes): bool + { + // Extract parts from the resource string + $parts = explode(':', $resource); + $resourcePart = str_replace(['{', '}'], '', $parts[0]); + $substatePart = $parts[1] ?? ''; + + $resourceMatch = $resourcePart === $desiredAttributes['resource'] . $desiredAttributes['state']; + $substateMatch = empty($desiredAttributes['substate']) || $substatePart === $desiredAttributes['substate']; + + return $resourceMatch && $substateMatch; + } } \ No newline at end of file diff --git a/plugins/tasks/Audit.php b/plugins/tasks/Audit.php index 94818316140c49b7b8f0ed19d0a8373639baa358..281f5bd00553208c9ba55528c6fc91fbac58ec0b 100644 --- a/plugins/tasks/Audit.php +++ b/plugins/tasks/Audit.php @@ -4,12 +4,12 @@ class Audit implements EndpointInterface { private TaskGateway $gateway; - private Utils $utils; + private orchLibraryUtils $utils; public function __construct (TaskGateway $gateway) { $this->gateway = $gateway; - $this->utils = new Utils(); + $this->utils = new orchLibraryUtils(); } /** diff --git a/plugins/tasks/Notifications.php b/plugins/tasks/Notifications.php index 4547b87f2ab471069783e77b48e8f4e960529e5c..a56062fb6973f784d434aa11e4c501aa4218b11f 100644 --- a/plugins/tasks/Notifications.php +++ b/plugins/tasks/Notifications.php @@ -4,12 +4,12 @@ class Notifications implements EndpointInterface { private TaskGateway $gateway; - private Utils $utils; + private orchLibraryUtils $utils; public function __construct (TaskGateway $gateway) { $this->gateway = $gateway; - $this->utils = new Utils(); + $this->utils = new orchLibraryUtils(); } /** diff --git a/plugins/tasks/Reminder.php b/plugins/tasks/Reminder.php index 180eca7d5bf34d8f84c19f4d302089012aef0382..72724b595d4c8085f36bd1becb98dbaacd7bc709 100644 --- a/plugins/tasks/Reminder.php +++ b/plugins/tasks/Reminder.php @@ -4,12 +4,12 @@ class Reminder implements EndpointInterface { private TaskGateway $gateway; - private ReminderTokenUtils $reminderTokenUtils; + private orchLibraryReminderTokenUtils $reminderTokenUtils; public function __construct (TaskGateway $gateway) { $this->gateway = $gateway; - $this->reminderTokenUtils = new ReminderTokenUtils(); + $this->reminderTokenUtils = new orchLibraryReminderTokenUtils(); } /**