Skip to content

Automatically delete users account requests in stage "pending email approval". after X days #555#576

Open
BobLamarley wants to merge 3 commits intogenouest:masterfrom
BobLamarley:Automatic-clean-users-accounts-requests-pending-after-delay#555
Open

Automatically delete users account requests in stage "pending email approval". after X days #555#576
BobLamarley wants to merge 3 commits intogenouest:masterfrom
BobLamarley:Automatic-clean-users-accounts-requests-pending-after-delay#555

Conversation

@BobLamarley
Copy link
Contributor

@BobLamarley BobLamarley commented Dec 30, 2024

Origin:

#555

What I’ve done:

  • The script searches for all users who have been in the “pending approval” status for more than the specified number of days (provided via the command argument).
  • It sends an email to each affected user and a single summary email to the admin, listing all the users who were deleted.

Key Details:

  • This is a Node.js script rather than a Bash script, as it leverages maisrv functions to send emails.

  • To run the script, you’ll need to set the NODE_CONFIG_DIR environment variable to point to the configuration directory:

    export NODE_CONFIG_DIR=path/to/config
  • Usage: To run the script manually, use the following command:

    node delete_pending_email_approvals.js --days 30
  • Scheduling: You can also schedule this script using cron. For example, to run it every minute:

    * * * * * /path/to/node /path/to/delete_pending_email_approvals.js --days 30

@BobLamarley BobLamarley marked this pull request as draft December 30, 2024 08:54
@BobLamarley BobLamarley changed the title Add script + changelog #555 Automatically delete users account requests in stage "pending email approval". after X days #555 Dec 30, 2024
from bash to node script to send mail
@BobLamarley BobLamarley marked this pull request as ready for review December 30, 2024 13:17
@mboudet
Copy link
Member

mboudet commented Jan 14, 2025

I'd rather avoid adding deps if we can avoid it. Can you use commander as a CLI tool? We already use it in the various scripts in the bin folder.

Ok, we already use 'commandLineArgs' actually (well, Roscoff / IFB do at least), it just wasn't in the package.json file. I guess it's fine.

Comment on lines +67 to +70
console.log(`User with UID ${user.uid} deleted.`);

const userMessage = `Your account has been deleted due to inactivity for over ${DAYS_TO_DELETE} days. If this was an error, please contact support.`;
await notify([user.email], 'Account Deletion Notice', userMessage);
Copy link
Member

@mboudet mboudet Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't send a mail to an user who did not validate their email address. If it's invalid, you want to avoid sending an email to it to avoid reducing your own email reputation with rejections.

In any case, it's less an 'inactivity' issue, and more 'you did not validate your mail'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants