Project

General

Profile

Actions

Feature #30998

closed

Add an rake task to prune registered users after a certain number of days

Added by David Demelier about 5 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Accounts / authentication
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

Hello,

Unfortunately I'm not enough skilled in ruby to propose a patch.

Like many other people, I'm affected by spammers that half-register themselves but do not complete inscriptions due their fake emails. So I constantly have a pile of half-registered users that pollute my database.

It could be nice if there was an option to automatically delete accounts that were not successfully registered after a given amount of time (example, 1 day by default or something like that).

What do you think?


Files

30998.patch (1.63 KB) 30998.patch Yuichi HARADA, 2021-04-19 02:31
30998-v2.patch (1.67 KB) 30998-v2.patch Go MAEDA, 2021-06-30 17:04
30998-v3.patch (1.53 KB) 30998-v3.patch Go MAEDA, 2021-12-18 08:42
0001-Add-tasks-to-prune-registered-users-after-a-certain-.patch (2.26 KB) 0001-Add-tasks-to-prune-registered-users-after-a-certain-.patch Marius BĂLTEANU, 2022-03-18 22:57

Related issues

Has duplicate Redmine - Feature #38541: Automatic deletion of unactivated accountsClosed

Actions
Actions #1

Updated by David Demelier about 5 years ago

For those who are interested, I usually process this easily by:

delete from users where status = 2;

Not sure if it's really safe while redmine is running though.

Actions #2

Updated by Go MAEDA about 3 years ago

How about adding a rake task redmine:users:prune to remove users who have not completed their registration?

Redmine already has a similarly named rake task redmine:attachments:prune (source:tags/4.2.0/lib/tasks/redmine.rake#L20). The rake task deletes files that have been uploaded but not attached to an issue or wiki page.

Actions #3

Updated by Yuichi HARADA about 3 years ago

Go MAEDA wrote:

How about adding a rake task redmine:users:prune to remove users who have not completed their registration?

+1
I created a rake task redmine:users:prune.

diff --git a/app/models/user.rb b/app/models/user.rb
index a3d2449d2..af65d5aaa 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -887,6 +887,10 @@ class User < Principal
     project_ids.map(&:to_i)
   end

+  def self.prune(age=1.day)
+    User.where("created_on < ? AND status = ?", Time.now - age, STATUS_REGISTERED).destroy_all
+  end
+
   protected

   def validate_password_length
diff --git a/lib/tasks/redmine.rake b/lib/tasks/redmine.rake
index 2bebaf18c..8cdf6f80f 100644
--- a/lib/tasks/redmine.rake
+++ b/lib/tasks/redmine.rake
@@ -40,6 +40,13 @@ namespace :redmine do
     end
   end

+  namespace :users do
+    desc 'Remove users who could not be activated after one day.'
+    task :prune => :environment do
+      User.prune
+    end
+  end
+
   namespace :watchers do
     desc 'Removes watchers from what they can no longer view.'
     task :prune => :environment do
Actions #4

Updated by Go MAEDA almost 3 years ago

  • Target version set to Candidate for next major release
Actions #5

Updated by Go MAEDA almost 3 years ago

Thank you for the patch.

I have changed the patch to remove users registered more than 7 days ago. I think one day is too short.

Suppose that you set "Self-registration" to "manual account activation" and run the rake task every day. When the admin receives a notification that a user has registered, the admin must activate the user within one day or the user will be deleted. All users who register after Friday afternoon may be deleted by Monday morning.

Actions #6

Updated by Go MAEDA over 2 years ago

Updated the patch for the trunk r21318. Setting the target version to 5.0.0.

Actions #7

Updated by Marius BĂLTEANU over 2 years ago

The rake task should accept the number of days as parameter in order to make this configurable. Also, the default value should be at least 7 days or even 30 days. One day is too less.

Actions #9

Updated by Marius BĂLTEANU about 2 years ago

  • Assignee set to Go MAEDA
Actions #10

Updated by Go MAEDA about 2 years ago

Marius BALTEANU wrote:

Go Maeda, what do you think about the following implementation?

Looks nice, thank you!

Actions #11

Updated by Go MAEDA about 2 years ago

  • Subject changed from Delete account not fully registered after an amount of time to Add an rake task to prune registered users after a certain number of days
  • Status changed from New to Closed
  • Resolution set to Fixed

Committed the patch. Thank you.

Actions #12

Updated by Go MAEDA 11 months ago

  • Has duplicate Feature #38541: Automatic deletion of unactivated accounts added
Actions

Also available in: Atom PDF