mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
New job (default off) to detect whether users have uploaded custom avatars by contacting Gravatar.
This commit is contained in:
parent
fcff4e80d1
commit
06ea8140aa
3 changed files with 33 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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}"
|
||||
|
|
26
lib/jobs/detect_avatars.rb
Normal file
26
lib/jobs/detect_avatars.rb
Normal 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
|
Loading…
Reference in a new issue