From 6c4b028232f5ad687c0def013b8de6a2b4013b4f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 19 Aug 2024 15:21:59 +0300 Subject: [PATCH 1/1] Record revokers when deactivating blocks by editing --- app/controllers/user_blocks_controller.rb | 1 + .../user_blocks_controller_test.rb | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/controllers/user_blocks_controller.rb b/app/controllers/user_blocks_controller.rb index 962eff04c..ae6e3c1cd 100644 --- a/app/controllers/user_blocks_controller.rb +++ b/app/controllers/user_blocks_controller.rb @@ -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" diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index e6782a64d..696d3c8d0 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -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 -- 2.39.5