Skip to content

Commit b27fbb8

Browse files
committed
Mark spammers comments when banned
1 parent 2c1774b commit b27fbb8

6 files changed

+30
-17
lines changed

app/models/protip.rb

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ class Protip < ActiveRecord::Base
136136
event :mark_as_spam do
137137
transition any => :marked_as_spam
138138
end
139+
140+
after_transition any => :marked_as_spam do |protip|
141+
protip.spam!
142+
end
139143
end
140144

141145
class << self

app/services/deindex_user_protips_service.rb

-8
This file was deleted.

app/services/index_user_protips_service.rb

-7
This file was deleted.

app/services/user_banner_service.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
class UserBannerService
22
def self.ban(user)
33
user.update_attribute(:banned_at, Time.now.utc)
4-
DeindexUserProtipsService.run(user)
4+
UserProtipsService.deindex_all_for(user)
5+
UserCommentsService.deindex_all_for(user)
56
end
67

78
def self.unban(user)
89
user.update_attribute(:banned_at, nil)
9-
IndexUserProtipsService.run(user)
10+
UserProtipsService.reindex_all_for(user)
1011
end
1112
end

app/services/user_comments_service.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module UserCommentsService
2+
def self.deindex_all_for(user)
3+
user.comments.each do |comment|
4+
comment.mark_as_spam
5+
end
6+
end
7+
end
8+

app/services/user_protips_service.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module UserProtipsService
2+
def self.deindex_all_for(user)
3+
user.protips.each do |protip|
4+
protip.mark_as_spam
5+
ProtipIndexer.new(protip).remove
6+
end
7+
end
8+
9+
def self.reindex_all_for(user)
10+
user.protips.each do |protip|
11+
ProtipIndexer.new(protip).store
12+
end
13+
end
14+
end
15+

0 commit comments

Comments
 (0)