Skip to content

Commit

Permalink
Leaf 4210 - updated sync services to clean system admins
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Jan 23, 2024
1 parent 4849fed commit 3f123e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
7 changes: 4 additions & 3 deletions LEAF_Request_Portal/sources/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function deactivateMember($member, $groupID): void
*
* @return void
*/
public function removeMember($member, $groupID): void
public function removeMember($member, $groupID, $backupID = ''): void
{
if (is_numeric($groupID) && $member != '') {
$this->dataActionLogger->logAction(DataActions::PRUNE, LoggableTypes::EMPLOYEE, [
Expand All @@ -428,12 +428,13 @@ public function removeMember($member, $groupID): void
]);

$vars = array(':userID' => $member,
':groupID' => $groupID);
':groupID' => $groupID,
':backupID' => $backupID);
$sql = 'DELETE
FROM `users`
WHERE (`userID` = :userID
AND `groupID` = :groupID
AND `backupID` = "")
AND `backupID` = :backupID)
OR (`groupID` = :groupID
AND `backupID` = :userID)';

Expand Down
50 changes: 50 additions & 0 deletions LEAF_Request_Portal/sources/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,59 @@ public function syncSystem(\Orgchart\Group $nexus_group): string
$this->updateGroup($group['groupID'], $oc_db);
}

$this->cleanupSystemAdmin();

return 'Syncing has finished. You are set to go.';
}

/**
*
* @return void
*
*/
private function cleanupSystemAdmin(): void
{
// get all portal users with groupID = 1
$groups = new Group($this->db, $this->login);

$admins = $groups->getMembers(1);

// create an array of users with their backups
$admin_list = array();

foreach ($admins['data'] as $admin) {
if ($admin['backupID'] != '') {
$admin_list[$admin['backupID']]['backup'][] = $admin['userName'];
}
}

// get all primary users from nexus with their backups
$dir = new VAMC_Directory();
$oc_db = OC_DB;
$employee = new \Orgchart\Employee($oc_db, $this->login);
$check_list = array();

foreach ($admin_list as $key => $admin) {
$nexus_user = $dir->lookupLogin($key, false, true, false);
$backups = $employee->getBackups($nexus_user[0]['empUID']);
$check_list[$key]['backup'] = array();

foreach ($backups as $backup) {
$check_list[$key]['backup'][] = $backup['userName'];
}
}

// check that all the backups are still there, if not remove them from portal

foreach ($admin_list as $key => $user) {
foreach ($user['backup'] as $backup) {
if (!in_array($backup, $check_list[$key]['backup'])) {
$groups->removeMember($backup, 1, $key);
}
}
}
}

/**
* getOrgchartImportTags retrieves
*
Expand Down

0 comments on commit 3f123e2

Please sign in to comment.