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
This commit is contained in:
Andy Zhao 2018-03-21 16:16:18 -04:00 committed by Ben Halpern
parent f5913399aa
commit a87cb4204c
4 changed files with 36 additions and 3 deletions

View file

@ -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")

View file

@ -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)

View file

@ -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

View file

@ -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