docbrown/app/controllers/api/v0/users_controller.rb
Andy Zhao 7c843ba354 Prevent Less than 1 day old accounts from Following Other Users (#159)
* Show empty array of users for potential spammers

* Use user columns for better accuracy and perf

* Use user instead of identity for flagging

* Fix boolean

* Add page skipping logic for young accounts

* Fix test and show team to follow for spammers

* Fix broken link

* Remove page skip logic for back button
2018-03-29 17:12:30 -04:00

25 lines
859 B
Ruby

module Api
module V0
class UsersController < ApplicationController
def index
if !user_signed_in? || less_than_one_day_old?(current_user)
usernames = ["ben", "jess", "peter", "maestromac", "andy", "lianafelt"]
@users = User.where(username: usernames)
return
end
if params[:state] == "follow_suggestions"
@users = UserFollowSuggester.new(current_user).suggestions
end
end
def less_than_one_day_old?(user)
range = (Time.now.beginning_of_day - 1.day)..(Time.now)
user_identity_age = user.github_created_at ||
user.twitter_created_at ||
Time.parse(user.identity.first.auth_data_dump.extra.raw_info.created_at)
# last one is a fallback in case both are nil
range.cover? user_identity_age
end
end
end
end