New job (default off) to detect whether users have uploaded custom avatars by contacting Gravatar.

This commit is contained in:
Robin Ward 2013-09-11 15:14:18 -04:00
parent fcff4e80d1
commit 06ea8140aa
3 changed files with 33 additions and 0 deletions

View File

@ -254,6 +254,9 @@ class SiteSetting < ActiveRecord::Base
client_setting(:allow_uploaded_avatars, true)
client_setting(:allow_animated_avatars, false)
setting(:detect_custom_avatars, false)
setting(:max_daily_gravatar_crawls, 500)
def self.generate_api_key!
self.api_key = SecureRandom.hex(32)
end

View File

@ -672,6 +672,10 @@ en:
allow_animated_avatars: "Allow users to use animated gif for avatars. WARNING: it is highly recommended to run the avatars:regenerate rake task after changing that setting."
default_digest_email_frequency: "How often users receive digest emails by default. They can change this setting in their preferences."
detect_custom_avatars: "Whether or not to check that users have uploaded custom avatars"
max_daily_gravatar_crawls: "The maximum amount of times Discourse will check gravatar for custom avatars in a day"
notification_types:
mentioned: "%{display_username} mentioned you in %{link}"
liked: "%{display_username} liked your post in %{link}"

View File

@ -0,0 +1,26 @@
require_dependency 'avatar_detector'
module Jobs
class DetectAvatars < Jobs::Scheduled
recurrence { daily.hour_of_day(8) }
def execute(args)
return unless SiteSetting.detect_custom_avatars?
# Find a random sampling of users of trust level 1 or higher who don't have a custom avatar.
user_stats = UserStat.where('user_stats.has_custom_avatar = false AND users.trust_level > 0')
.includes(:user)
.order("random()")
.limit(SiteSetting.max_daily_gravatar_crawls)
if user_stats.present?
user_stats.each do |us|
us.update_column(:has_custom_avatar, true) if AvatarDetector.new(us.user).has_custom_avatar?
end
end
end
end
end