<%= 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 %>
##
# 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)
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
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