]> git.openstreetmap.org Git - rails.git/commitdiff
Allow to edit inactive blocks
authorAnton Khorev <tony29@yandex.ru>
Wed, 24 Jul 2024 01:22:49 +0000 (04:22 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 24 Jul 2024 01:43:13 +0000 (04:43 +0300)
app/controllers/user_blocks_controller.rb
config/locales/en.yml
test/controllers/user_blocks_controller_test.rb

index 9ee3712265701fc336f6d8ed86d94aa770ca6a8f..3ab217a601fc5bfe1319aefffb5bb2ce8510314b 100644 (file)
@@ -142,9 +142,6 @@ class UserBlocksController < ApplicationController
     if UserBlock::PERIODS.exclude?(@block_period)
       flash[:error] = t("user_blocks.filter.block_period")
 
     if UserBlock::PERIODS.exclude?(@block_period)
       flash[:error] = t("user_blocks.filter.block_period")
 
-    elsif @user_block && !@user_block.active?
-      flash[:error] = t("user_blocks.filter.block_expired")
-
     else
       @valid_params = true
     end
     else
       @valid_params = true
     end
index 1def0f3eb9aaff088b76029fdfa1907bd22401f7..2b83fec1f9d4097cb4e8036f1e2cc8314fe3bd47 100644 (file)
@@ -2935,7 +2935,6 @@ en:
       show: "View this block"
       back: "View all blocks"
     filter:
       show: "View this block"
       back: "View all blocks"
     filter:
-      block_expired: "The block has already expired and cannot be edited."
       block_period: "The blocking period must be one of the values selectable in the drop-down list."
     create:
       flash: "Created a block on user %{name}."
       block_period: "The blocking period must be one of the values selectable in the drop-down list."
     create:
       flash: "Created a block on user %{name}."
index b6aaf4ca8267256ece52d00f6eb70c4c29c27e94..328e2cc404ee6839aebe2d504c884cf41f7de141 100644 (file)
@@ -406,6 +406,43 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
   end
 
     assert_select "p", "Sorry, the user block with ID 99999 could not be found."
   end
 
+  ##
+  # test the update action on expired blocks
+  def test_update_expired
+    creator_user = create(:moderator_user)
+    other_moderator_user = create(:moderator_user)
+    block = create(:user_block, :expired, :creator => creator_user, :reason => "Original Reason")
+
+    session_for(other_moderator_user)
+    put user_block_path(block,
+                        :user_block_period => "0",
+                        :user_block => { :needs_view => false, :reason => "Updated Reason" })
+    assert_redirected_to edit_user_block_path(block)
+    assert_equal "Only the moderator who created this block can edit it.", flash[:error]
+    block.reload
+    assert_not block.active?
+    assert_equal "Original Reason", block.reason
+
+    session_for(creator_user)
+    put user_block_path(block,
+                        :user_block_period => "0",
+                        :user_block => { :needs_view => false, :reason => "Updated Reason" })
+    assert_redirected_to user_block_path(block)
+    assert_equal "Block updated.", flash[:notice]
+    block.reload
+    assert_not block.active?
+    assert_equal "Updated Reason", block.reason
+
+    put user_block_path(block,
+                        :user_block_period => "0",
+                        :user_block => { :needs_view => true, :reason => "Updated Reason 2" })
+    assert_redirected_to user_block_path(block)
+    assert_equal "Block updated.", flash[:notice]
+    block.reload
+    assert_predicate block, :active?
+    assert_equal "Updated Reason 2", block.reason
+  end
+
   ##
   # test the revoke action
   def test_revoke
   ##
   # test the revoke action
   def test_revoke