Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJason Robinson <mail@jasonrobinson.me>2014-09-30 00:20:36 +0400
committerJason Robinson <mail@jasonrobinson.me>2014-10-16 23:53:08 +0400
commit69c35669585896249db1eb3e3487a30ae09cff46 (patch)
tree941488aaa4cbb611c926a626a8e02e939a281472 /app
parentef71c5719072d6dc314bf567c4300eb96e0dddfc (diff)
Maintenance feature to remove old users
Add Sidetiq webview to the Sidekiq monitoring panel Add rake task maintenance:queue_users_for_removal This basically just triggers an immediate run of the normal maintenance remove old users functionality that is normally (if enabled) scheduled to run once a day via sidetiq Add extra safety when checking for user removal due to inactivity. Now also user.last_seen will also be checked to make sure a user will not be removed in the event that the Devise rememember me login functionality has stopped the users remove_after timestamp from being removed. Add initializer for maintenance job. Add warning about mail being disabled if remove_old_users maintenance is enabled.
Diffstat (limited to 'app')
-rw-r--r--app/mailers/maintenance.rb15
-rw-r--r--app/models/user.rb18
-rw-r--r--app/views/maintenance/account_removal_warning.markerb2
-rw-r--r--app/workers/queue_users_for_removal.rb41
-rw-r--r--app/workers/remove_old_user.rb27
5 files changed, 102 insertions, 1 deletions
diff --git a/app/mailers/maintenance.rb b/app/mailers/maintenance.rb
new file mode 100644
index 000000000..d44b28f51
--- /dev/null
+++ b/app/mailers/maintenance.rb
@@ -0,0 +1,15 @@
+class Maintenance < ActionMailer::Base
+ default :from => AppConfig.mail.sender_address
+
+ def account_removal_warning(user)
+ @user = user
+ @login_url = new_user_session_path
+ @pod_url = AppConfig.environment.url
+ @after_days = AppConfig.settings.maintenance.remove_old_users.after_days.to_s
+ @remove_after = @user.remove_after
+ mail(:to => @user.email, :subject => I18n.t('notifier.remove_old_user.subject')) do |format|
+ format.text
+ format.html
+ end
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 5f7a5fd22..35fe032f9 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -481,12 +481,28 @@ class User < ActiveRecord::Base
end
end
+ def flag_for_removal(remove_after)
+ # flag inactive user for future removal
+ if AppConfig.settings.maintenance.remove_old_users.enable?
+ self.remove_after = remove_after
+ self.save
+ end
+ end
+
+ def after_database_authentication
+ # remove any possible remove_after timestamp flag set by maintenance.remove_old_users
+ unless self.remove_after.nil?
+ self.remove_after = nil
+ self.save
+ end
+ end
+
private
def clearable_fields
self.attributes.keys - ["id", "username", "encrypted_password",
"created_at", "updated_at", "locked_at",
"serialized_private_key", "getting_started",
"disable_mail", "show_community_spotlight_in_stream",
- "email"]
+ "email", "remove_after"]
end
end
diff --git a/app/views/maintenance/account_removal_warning.markerb b/app/views/maintenance/account_removal_warning.markerb
new file mode 100644
index 000000000..7303bafae
--- /dev/null
+++ b/app/views/maintenance/account_removal_warning.markerb
@@ -0,0 +1,2 @@
+<%= t('notifier.remove_old_user.body', pod_url: @pod_url, login_url: @login_url, after_days: @after_days, remove_after: @remove_after) %>
+
diff --git a/app/workers/queue_users_for_removal.rb b/app/workers/queue_users_for_removal.rb
new file mode 100644
index 000000000..63efa3365
--- /dev/null
+++ b/app/workers/queue_users_for_removal.rb
@@ -0,0 +1,41 @@
+# Copyright (c) 2010-2011, Diaspora Inc. This file is
+# licensed under the Affero General Public License version 3 or later. See
+# the COPYRIGHT file.
+
+module Workers
+ class QueueUsersForRemoval < Base
+ include Sidetiq::Schedulable
+
+ sidekiq_options queue: :maintenance
+
+ recurrence { daily }
+
+ def perform
+ # Queue users for removal due to inactivity
+ if AppConfig.settings.maintenance.remove_old_users.enable?
+ users = User.where("last_seen < ? and locked_at is null and remove_after is null",
+ Time.now - (AppConfig.settings.maintenance.remove_old_users.after_days.to_i).days)
+ .order(:last_seen)
+ .limit(AppConfig.settings.maintenance.remove_old_users.limit_removals_to_per_day)
+
+ # deliver to be closed emails to account holders
+ # and queue accounts for closing to sidekiq
+ # for those who have not signed in, skip warning and queue removal
+ # in +1 days
+ users.find_each do |user|
+ if user.sign_in_count > 0
+ remove_at = Time.now + AppConfig.settings.maintenance.remove_old_users.warn_days.to_i.days
+ else
+ remove_at = Time.now
+ end
+ user.flag_for_removal(remove_at)
+ if user.sign_in_count > 0
+ # send a warning
+ Maintenance.account_removal_warning(user).deliver
+ end
+ Workers::RemoveOldUser.perform_in(remove_at+1.day, user.id)
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/workers/remove_old_user.rb b/app/workers/remove_old_user.rb
new file mode 100644
index 000000000..d8619b4bf
--- /dev/null
+++ b/app/workers/remove_old_user.rb
@@ -0,0 +1,27 @@
+# Copyright (c) 2010-2011, Diaspora Inc. This file is
+# licensed under the Affero General Public License version 3 or later. See
+# the COPYRIGHT file.
+
+module Workers
+ class RemoveOldUser < Base
+ sidekiq_options queue: :maintenance
+
+ def safe_remove_after
+ # extra safety time to compare in addition to remove_after
+ Time.now-
+ (AppConfig.settings.maintenance.remove_old_users.after_days.to_i).days-
+ (AppConfig.settings.maintenance.remove_old_users.warn_days.to_i).days
+ end
+
+ def perform(user_id)
+ # if user has been flagged as to be removed (see settings.maintenance.remove_old_users)
+ # and hasn't logged in since that flag has been set, we remove the user
+ if AppConfig.settings.maintenance.remove_old_users.enable?
+ user = User.find(user_id)
+ if user.remove_after < Time.now and user.last_seen < self.safe_remove_after
+ user.close_account!
+ end
+ end
+ end
+ end
+end \ No newline at end of file