]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #5690 from tomhughes/ruby34
authorAndy Allan <git@gravitystorm.co.uk>
Sun, 16 Feb 2025 14:48:26 +0000 (14:48 +0000)
committerGitHub <noreply@github.com>
Sun, 16 Feb 2025 14:48:26 +0000 (14:48 +0000)
Add ruby 3.4 to test matrix

app/controllers/accounts_controller.rb
app/controllers/concerns/user_methods.rb
app/controllers/reports_controller.rb
app/models/user.rb
test/controllers/reports_controller_test.rb

index 085d1bfea055091af3a074b552713edea291980c..d02943640147a37476832d74fed15a107a314af2 100644 (file)
@@ -31,7 +31,7 @@ class AccountsController < ApplicationController
        (params[:user][:auth_provider] == current_user.auth_provider &&
         params[:user][:auth_uid] == current_user.auth_uid)
       update_user(current_user, user_params)
-      if current_user.errors.count.zero?
+      if current_user.errors.empty?
         redirect_to edit_account_path
       else
         render :edit
index d79ed48d2ca742be14faad6db9f637b09dd247e4..447aea3fce3013ac2734992c4c8648ad612ce339 100644 (file)
@@ -59,8 +59,9 @@ module UserMethods
             # Ignore errors sending email
           end
         else
-          current_user.errors.add(:new_email, current_user.errors[:email])
-          current_user.errors.add(:email, [])
+          current_user.errors.delete(:email).each do |error|
+            current_user.errors.add(:new_email, error)
+          end
         end
 
         user.restore_email!
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 21fe2181b20abe9bfce7b196699d6fc368aca722..8d061e26bb626cd7c1a42fe9d6c6fb8e72e044fe 100644 (file)
@@ -359,7 +359,7 @@ class User < ApplicationRecord
     trace_score = traces.size * 50
     diary_entry_score = diary_entries.visible.inject(0) { |acc, elem| acc + elem.body.spam_score }
     diary_comment_score = diary_comments.visible.inject(0) { |acc, elem| acc + elem.body.spam_score }
-    report_score = Report.where(:category => "spam", :issue => issues.with_status("open")).count * 20
+    report_score = Report.where(:category => "spam", :issue => issues.with_status("open")).distinct.count(:user_id) * 20
 
     score = description.spam_score / 4.0
     score += diary_entries.visible.where("created_at > ?", 1.day.ago).count * 10
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