diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-08-26 11:39:40 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-08-26 11:39:40 -0500 |
commit | 35636272c0164372954b52a8a957ba08d645330d (patch) | |
tree | fb1b15318990752739bc903e8e8037bb2768094c /app/workers | |
parent | 89f49712acae3cd5b20b73975ee584ebcab2efcd (diff) |
detect spam registrations + include account approvals/rejections in transparancy log
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/registration_janitor_worker.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/workers/registration_janitor_worker.rb b/app/workers/registration_janitor_worker.rb new file mode 100644 index 000000000..e3130a6bb --- /dev/null +++ b/app/workers/registration_janitor_worker.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class RegistrationJanitorWorker + include Sidekiq::Worker + include LogHelper + + def perform(user_id) + user = User.find(user_id) + janitor = janitor_account || Account.representative + + spam_triggers = ENV.fetch('REGISTRATION_SPAM_TRIGGERS', '').split('|').map { |phrase| phrase.strip } + + intro = user.invite_request&.text + # normalize it + intro = intro.gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '').strip.downcase unless intro.nil? + + return user.notify_staff_about_pending_account! unless intro.blank? || intro.split.count < 5 || spam_triggers.any? { |phrase| phrase.in?(intro) } + + user_friendly_action_log(janitor, :reject_registration, user.account.username, "Registration was spam filtered.") + Form::AccountBatch.new(current_account: janitor, account_ids: user.account.id, action: 'reject').save + rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid + true + end + + private + + def janitor_account + account_id = ENV.fetch('JANITOR_USER', '').to_i + return if account_id == 0 + Account.find_by(id: account_id) + end +end |