Skip to content

Commit

Permalink
feat: do not process users on hold and enable deletes (#308)
Browse files Browse the repository at this point in the history
* feat: do not process users on hold

* fix: uncomment delete code
  • Loading branch information
NithinKuruba authored Jul 19, 2023
1 parent e986480 commit b1b0e0d
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions docker/kc-cron-job/remove-inactive-idir-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,6 @@ function handleError(error) {
}
}

function ignoreError(prom, errorValue = null) {
return prom.then(
(data) => data,
(err) => {
console.error(err);
return errorValue;
},
);
}

async function getUserRolesMappings(adminClient, userId) {
try {
const clientRoles = [];
Expand Down Expand Up @@ -339,20 +329,19 @@ async function removeUserFromCssApp(userGuid) {
'Content-Type': 'application/json',
Authorization: process.env.CSS_API_AUTH_SECRET,
};
const a = await axios.delete(`${process.env.CSS_API_URL}/users/${userGuid}`, { headers });
return a.status === 204 ? true : false;
const deleteRes = await axios.delete(`${process.env.CSS_API_URL}/users/${userGuid}`, { headers });
return deleteRes.status === 204 ? true : false;
} catch (err) {
console.error(err);
return false;
}
}

async function removeUserFromKc(adminClient, id) {
try {
await adminClient.users.del({ realm: 'standard', id });
return true;
} catch (err) {
console.error(err);
return false;
}
}

Expand All @@ -378,13 +367,16 @@ async function removeStaleUsersByEnv(env = 'dev', pgClient, runnerName, startFro
for (let x = 0; x < users.length; x++) {
const { id, username } = users[x];
const idir_user_guid = String(users[x].attributes.idir_user_guid).toLowerCase();
const displayName = String(users[x].attributes.display_name).toLowerCase();
// ignore the users with `hold` in their displayname
if (displayName && displayName.startsWith('hold -')) continue;
log(`[${runnerName}] processing user ${username}`);
if (username.includes('@idir')) {
const userExistsAtWb = await checkUserExistsAtIDIM({ property: 'userGuid', matchKey: idir_user_guid, env });
if (!userExistsAtWb) {
const { realmRoles, clientRoles } = await getUserRolesMappings(adminClient, id);
// await removeUserFromKc(adminClient, id);
// const userDeletedAtCss = await removeUserFromCssApp(idir_user_guid);
await removeUserFromKc(adminClient, id);
const userDeletedAtCss = await removeUserFromCssApp(idir_user_guid);
const values = [
env,
id,
Expand Down

0 comments on commit b1b0e0d

Please sign in to comment.