]> git.openstreetmap.org Git - rails.git/commitdiff
Remove duration controls for blocks that can only be revoked by editing
authorAnton Khorev <tony29@yandex.ru>
Wed, 21 Aug 2024 13:58:34 +0000 (16:58 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 22 Aug 2024 11:01:54 +0000 (14:01 +0300)
app/views/user_blocks/edit.html.erb
test/controllers/user_blocks_controller_test.rb
test/factories/user_blocks.rb
test/system/user_blocks_test.rb

index 2d8956ffca730f29c1498074e05110c3a681ca48..aaa2fcaa4372222716698a2545260335593a5b88 100644 (file)
@@ -9,7 +9,7 @@
 <%= bootstrap_form_for(@user_block) do |f| %>
   <%= f.richtext_field :reason, :cols => 80, :rows => 20, :format => @user_block.reason_format %>
 
-  <% if @user_block.active? %>
+  <% if @user_block.active? && @user_block.creator == current_user %>
     <%= f.form_group do %>
       <%= label_tag "user_block_period", t(".period"), :class => "form-label" %>
       <%= select_tag "user_block_period",
     <% end %>
   <% else %>
     <div class="alert alert-info">
-      <%= t "user_blocks.update.inactive_block_cannot_be_reactivated" %>
+      <% if @user_block.active? %>
+        <%= t "user_blocks.update.only_creator_can_edit_without_revoking" %>
+      <% else %>
+        <%= t "user_blocks.update.inactive_block_cannot_be_reactivated" %>
+      <% end %>
     </div>
 
     <%= hidden_field_tag "user_block_period", 0 %>
-    <%= f.hidden_field :needs_view %>
+    <%= hidden_field_tag "user_block[needs_view]", false %>
   <% end %>
 
   <%= f.primary %>
index dbeb7569f4c7ab8b692ad6563ded69841fdcd642..2cbfb37b4845829d2c8d9806414add8c56435182 100644 (file)
@@ -252,7 +252,9 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
   ##
   # test the edit action
   def test_edit
-    active_block = create(:user_block)
+    creator_user = create(:moderator_user)
+    other_moderator_user = create(:moderator_user)
+    active_block = create(:user_block, :creator => creator_user)
 
     # Check that the block edit page requires us to login
     get edit_user_block_path(:id => active_block)
@@ -266,16 +268,34 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
     assert_redirected_to :controller => "errors", :action => "forbidden"
 
     # Login as a moderator
-    session_for(create(:moderator_user))
+    session_for(other_moderator_user)
 
     # Check that the block edit page loads for moderators
     get edit_user_block_path(:id => active_block)
     assert_response :success
     assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
+    assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
+      assert_select "textarea#user_block_reason", :count => 1
+      assert_select "select#user_block_period", :count => 0
+      assert_select "input#user_block_needs_view[type='checkbox']", :count => 0
+      assert_select "input#user_block_period[type='hidden']", :count => 1
+      assert_select "input#user_block_needs_view[type='hidden']", :count => 1
+      assert_select "input[type='submit'][value='Update block']", :count => 1
+    end
+
+    # Login as the block creator
+    session_for(creator_user)
+
+    # Check that the block edit page loads for the creator
+    get edit_user_block_path(:id => active_block)
+    assert_response :success
+    assert_select "h1 a[href='#{user_path active_block.user}']", :text => active_block.user.display_name
     assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
       assert_select "textarea#user_block_reason", :count => 1
       assert_select "select#user_block_period", :count => 1
       assert_select "input#user_block_needs_view[type='checkbox']", :count => 1
+      assert_select "input#user_block_period[type='hidden']", :count => 0
+      assert_select "input#user_block_needs_view[type='hidden']", :count => 0
       assert_select "input[type='submit'][value='Update block']", :count => 1
     end
 
index 82c2fbe6e8f694b87578e1dbbe2bdb9f8726c667..8bdd6875e014ed8e364871b41781cfccd31cfa84 100644 (file)
@@ -7,6 +7,12 @@ FactoryBot.define do
     user
     creator :factory => :moderator_user
 
+    trait :zero_hour do
+      now = Time.now.utc
+      created_at { now }
+      ends_at { now }
+    end
+
     trait :needs_view do
       needs_view { true }
       deactivates_at { nil }
index 89f98d759afcc89c85132fdee6c23c7cc0d8949b..b4b7ada7aa947414407254b92f7b15ac91304eeb 100644 (file)
@@ -98,4 +98,22 @@ class UserBlocksSystemTest < ApplicationSystemTestCase
     click_on "Update block"
     assert_text(/Reason for block:\s+Editing expired blocks works/)
   end
+
+  test "other moderator can revoke 0-hour blocks" do
+    creator_user = create(:moderator_user)
+    other_moderator_user = create(:moderator_user)
+    block = create(:user_block, :zero_hour, :needs_view, :creator => creator_user, :reason => "Testing revoking 0-hour blocks")
+    sign_in_as(other_moderator_user)
+
+    visit edit_user_block_path(block)
+    assert_field "Reason", :with => "Testing revoking 0-hour blocks"
+    assert_no_select "user_block_period"
+    assert_no_field "Needs view"
+
+    fill_in "Reason", :with => "Revoking 0-hour blocks works"
+    click_on "Update block"
+    assert_text(/Revoker:\s+#{Regexp.escape other_moderator_user.display_name}/)
+    assert_text(/Status:\s+Ended/)
+    assert_text(/Reason for block:\s+Revoking 0-hour blocks works/)
+  end
 end