Project

General

Profile

Feature #30998 » 30998-v3.patch

Go MAEDA, 2021-12-18 08:42

View differences:

app/models/user.rb
866 866
    project_ids.map(&:to_i)
867 867
  end
868 868

  
869
  def self.prune(age=7.days)
870
    User.where("created_on < ? AND status = ?", Time.now - age, STATUS_REGISTERED).destroy_all
871
  end
872

  
869 873
  protected
870 874

  
871 875
  def validate_password_length
lib/tasks/redmine.rake
40 40
    end
41 41
  end
42 42

  
43
  namespace :users do
44
    desc 'Removes registered users that have not been activated after seven days.'
45
    task :prune => :environment do
46
      User.prune
47
    end
48
  end
49

  
43 50
  namespace :watchers do
44 51
    desc 'Removes watchers from what they can no longer view.'
45 52
    task :prune => :environment do
test/unit/user_test.rb
1348 1348
    cv2a.reload
1349 1349
    assert_equal @dlopper.id.to_s, cv2a.value
1350 1350
  end
1351

  
1352
  def test_prune_should_destroy_unactivated_old_users
1353
    User.generate!(:status => User::STATUS_REGISTERED, :created_on => 6.days.ago)
1354
    User.generate!(:status => User::STATUS_REGISTERED, :created_on => 7.day.ago)
1355
    User.generate!(:status => User::STATUS_REGISTERED)
1356

  
1357
    assert_difference 'User.count', -2 do
1358
      User.prune
1359
    end
1360
  end
1351 1361
end
(3-3/4)