]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5094'
authorTom Hughes <tom@compton.nu>
Mon, 19 Aug 2024 17:16:51 +0000 (18:16 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 19 Aug 2024 17:16:51 +0000 (18:16 +0100)
app/controllers/user_blocks_controller.rb
test/controllers/user_blocks_controller_test.rb

index 962eff04ce06306cb97906d9d4a0edf2c126e4bc..ae6e3c1cd5f4f3b7fc26646cd8ae346ebdb75cb1 100644 (file)
@@ -72,6 +72,7 @@ class UserBlocksController < ApplicationController
         @user_block.reason = params[:user_block][:reason]
         @user_block.needs_view = params[:user_block][:needs_view]
         @user_block.ends_at = Time.now.utc + @block_period.hours
+        @user_block.revoker = current_user if user_block_was_active && !@user_block.active?
         if !user_block_was_active && @user_block.active?
           flash.now[:error] = t(".inactive_block_cannot_be_reactivated")
           render :action => "edit"
index e6782a64d0d3910393c70b026f1350b738211e3e..696d3c8d04fb3400fcda186289a4dce30c6d4a95 100644 (file)
@@ -493,6 +493,28 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
     check_inactive_block_updates(block)
   end
 
+  ##
+  # test the update action revoking the block
+  def test_revoke_using_update
+    moderator_user = create(:moderator_user)
+    block = create(:user_block, :creator => moderator_user)
+
+    session_for(moderator_user)
+    put user_block_path(block,
+                        :user_block_period => "24",
+                        :user_block => { :needs_view => false, :reason => "Updated Reason" })
+    block.reload
+    assert_predicate block, :active?
+    assert_nil block.revoker
+
+    put user_block_path(block,
+                        :user_block_period => "0",
+                        :user_block => { :needs_view => false, :reason => "Updated Reason" })
+    block.reload
+    assert_not_predicate block, :active?
+    assert_equal moderator_user, block.revoker
+  end
+
   ##
   # test the revoke action
   def test_revoke