From a87cb4204cf80d51fce70f6745a41005ce308667 Mon Sep 17 00:00:00 2001 From: Andy Zhao Date: Wed, 21 Mar 2018 16:16:18 -0400 Subject: [PATCH] Improve spam moderation (#101) * Add a missing bounty hunter * Add a msg about updating social usernames * Add mailto: link for yo@dev in terms * Use render partial for help tag * Scrub all user info for banish user button * Silently prevent updating profile for banned users * Add Slack alert for less than 1 week old accts * Adjust oauth mock data for tests * Remove line about signing in/out * Change range to one week prior --- app/controllers/internal/users_controller.rb | 20 +++++++++++++++++++- app/controllers/users_controller.rb | 2 +- app/services/authorization_service.rb | 15 +++++++++++++++ spec/rails_helper.rb | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index 42bb0d01c..674bee291 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -18,10 +18,28 @@ class Internal::UsersController < Internal::ApplicationController def strip_user(user) return unless user.comments.where("created_at < ?", 7.days.ago).empty? - user.summary = "" + new_name = "spam_#{rand(10000)}" + new_username = "spam_#{rand(10000)}" + if User.find_by(name: new_name) || User.find_by(username: new_username) + new_name = "spam_#{rand(10000)}" + new_username = "spam_#{rand(10000)}" + end + user.name = new_name + user.username = new_username user.twitter_username = "" user.github_username = "" user.website_url = "" + user.summary = "" + user.location = "" + user.education = "" + user.employer_name = "" + user.employer_url = "" + user.employment_title = "" + user.mostly_work_with = "" + user.currently_learning = "" + user.currently_hacking_on = "" + user.available_for = "" + user.email_public = false user.add_role :banned unless user.notes.where(reason: "banned").any? user.notes.create!(reason: "banned", content: "spam account") diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8d1cf70cd..d84e00918 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -29,7 +29,7 @@ class UsersController < ApplicationController @user = current_user @tab_list = tab_list(@user) @tab = params["user"]["tab"] || "profile" - if @user.update(user_params) + if !@user.banned && @user.update(user_params) RssReader.new.delay.fetch_user(@user) if @user.feed_url.present? notice = "Your profile was successfully updated." follow_hiring_tag(@user) diff --git a/app/services/authorization_service.rb b/app/services/authorization_service.rb index 0cb4ee804..f830b6ee8 100644 --- a/app/services/authorization_service.rb +++ b/app/services/authorization_service.rb @@ -17,6 +17,7 @@ class AuthorizationService end set_identity(identity, user) user.skip_confirmation! + flag_spam_user(user) if account_less_than_a_week_old?(identity) user end @@ -108,4 +109,18 @@ class AuthorizationService signed_in_resource && Identity.where(provider: identity.provider, user_id: signed_in_resource.id).any? end + + def account_less_than_a_week_old?(identity) + range = (Time.now.beginning_of_day - 1.week)..(Time.now) + range.cover? Time.parse(identity.auth_data_dump.extra.raw_info.created_at) + end + + def flag_spam_user(user) + SlackBot.ping( + "Potential spam user! https://dev.to/#{user.username}", + channel: "abuse-reports", + username: "spam_account_checker_bot", + icon_emoji: ":exclamation:", + ) + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6e278a4a4..8c14dd90e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -138,7 +138,7 @@ RSpec.configure do |config| raw_info.verified = true raw_info.followers_count = 100 raw_info.friends_count = 1000 - raw_info.created_at = Time.now + raw_info.created_at = "2017-06-08T13:09:47+0000" extra_info = Hashie::Mash.new extra_info.raw_info = raw_info