docbrown/app/services/users/resolve_spam_reports.rb
Anna Buianova 1008f0af7d
Automatically resolve spam reports when the offending user is marked as spam (#20781)
* Start resolving spam reports automatically after assigning spam role

* Specs for resolving spam reports + async resolving
2024-03-21 17:31:43 +00:00

35 lines
1 KiB
Ruby

module Users
class ResolveSpamReports
def self.call(...)
new(...).call
end
def initialize(user)
@user = user
end
def call
relation = FeedbackMessage.where(status: "Open", category: "spam")
# profile reports by url and by path
profile_reports = relation.where(reported_url: [URL.url(user.path), user.path])
profile_reports.update_all(status: "Resolved")
# articles can be reported by url or by path
article_paths = user.articles.map(&:path)
article_paths += article_paths.map { |p| URL.url(p) }
article_reports = relation.where(reported_url: article_paths)
article_reports.update_all(status: "Resolved")
# comments can be reported by url or by path
comment_paths = user.comments.map(&:path)
comment_paths += comment_paths.map { |p| URL.url(p) }
comment_reports = relation.where(reported_url: comment_paths)
comment_reports.update_all(status: "Resolved")
end
private
attr_reader :user
end
end