Remove duration controls for blocks that can only be revoked by editing
This commit is contained in:
parent
5e7ab68721
commit
11a7bf7e0e
4 changed files with 53 additions and 5 deletions
|
@ -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",
|
||||
|
@ -23,11 +23,15 @@
|
|||
<% 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 %>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue