]> git.openstreetmap.org Git - rails.git/commitdiff
Make reports trigger a spam check on the reported user
authorTom Hughes <tom@compton.nu>
Sun, 16 Feb 2025 13:34:12 +0000 (13:34 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 16 Feb 2025 14:08:23 +0000 (14:08 +0000)
app/controllers/reports_controller.rb
test/controllers/reports_controller_test.rb

index 5c70d970408f595411fd70c097c8c389ddd7e933..e2ec400a57665ba92483cfefc3ebde36007878b9 100644 (file)
@@ -29,6 +29,8 @@ class ReportsController < ApplicationController
       @report.issue.reopen unless @report.issue.open?
       @report.issue.save!
 
+      @report.issue.reported_user&.spam_check
+
       redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report")
     else
       flash.now[:notice] = t(".provide_details")
index 25b80e8f4bb418e9231088921b5fa2d08ae66836..a7f65de629a23206657af397ffdf015db2dfdc3f 100644 (file)
@@ -111,4 +111,42 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
 
     assert_equal 2, issue.reports.count
   end
+
+  def test_spam_reports_can_suspend
+    target_user = create(:user)
+
+    session_for(create(:user))
+
+    post reports_path(:report => {
+                        :details => "Spammer",
+                        :category => "spam",
+                        :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+                      })
+    assert_equal "active", target_user.reload.status
+
+    session_for(create(:user))
+
+    post reports_path(:report => {
+                        :details => "Spammer",
+                        :category => "spam",
+                        :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+                      })
+    assert_equal "active", target_user.reload.status
+
+    post reports_path(:report => {
+                        :details => "Spammer",
+                        :category => "spam",
+                        :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+                      })
+    assert_equal "active", target_user.reload.status
+
+    session_for(create(:user))
+
+    post reports_path(:report => {
+                        :details => "Spammer",
+                        :category => "spam",
+                        :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+                      })
+    assert_equal "suspended", target_user.reload.status
+  end
 end