Skip to content

Commit

Permalink
Add script + changelog genouest#555
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLamarley committed Dec 30, 2024
1 parent fa802ec commit fa76cf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.4.32 (Unreleased)

* Adding a tool script to delete users accounts in pending email approval
* Clearer error message when adding a website
* Add User, Project and Group static classes to front end (refactor)
* Add checks for website owner update
Expand Down
30 changes: 30 additions & 0 deletions tools/delete_pending_email_approvals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Define the database and collection
DB_NAME="gomngr"
COLLECTION="users"

# Default value for DAYS_TO_DELETE
DAYS_TO_DELETE=30

# Check if an argument is provided and override the default
if [ "$1" ]; then
DAYS_TO_DELETE=$1
fi

EXPIRATION_THRESHOLD=$(($(date +%s%3N) - (DAYS_TO_DELETE * 24 * 60 * 60 * 1000)))

# Execute the MongoDB command to find and delete matching users
mongo "$DB_NAME" --quiet --eval "
db.$COLLECTION.find({
status: 'Waiting for email approval',
registration: { \$lt: $EXPIRATION_THRESHOLD }
}).forEach(
function(elm) {
db.$COLLECTION.remove({ _id: elm._id });
print('Deleted user with ID: ' + elm._id);
}
);
"

echo "Cleanup script executed. Users in 'pending email approval' stage with 'registration' older than $DAYS_TO_DELETE days have been deleted."

0 comments on commit fa76cf1

Please sign in to comment.