def set_status
@user.activate! if params[:event] == "activate"
@user.confirm! if params[:event] == "confirm"
+ @user.unconfirm! if params[:event] == "unconfirm"
@user.hide! if params[:event] == "hide"
@user.unhide! if params[:event] == "unhide"
+ @user.unsuspend! if params[:event] == "unsuspend"
redirect_to user_path(:display_name => params[:display_name])
end
transitions :from => [:pending, :active, :suspended], :to => :confirmed
end
+ # To unconfirm an account is to make it subject to future spam scoring again
+ event :unconfirm do
+ transitions :from => :confirmed, :to => :active
+ end
+
+ # Accounts can be automatically suspended by spam_check
event :suspend do
transitions :from => [:pending, :active], :to => :suspended
end
+ # Unsuspending an account moves it back to active without overriding the spam scoring
+ event :unsuspend do
+ transitions :from => :suspended, :to => :active
+ end
+
# Mark the account as deleted but keep all data intact
event :hide do
transitions :from => [:pending, :active, :confirmed, :suspended], :to => :deleted
</li>
<% end %>
+ <% if @user.may_unsuspend? %>
+ <li>
+ <%= link_to t(".unsuspend_user"), set_status_user_path(:event => "unsuspend", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %>
+ </li>
+ <% end %>
+
<% if @user.may_confirm? %>
<li>
<%= link_to t(".confirm_user"), set_status_user_path(:event => "confirm", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %>
</li>
<% end %>
+ <% if @user.may_unconfirm? %>
+ <li>
+ <%= link_to t(".unconfirm_user"), set_status_user_path(:event => "unconfirm", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %>
+ </li>
+ <% end %>
+
<% if @user.may_hide? %>
<li>
<%= link_to t(".hide_user"), set_status_user_path(:event => "hide", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %>
activate_user: "Activate this User"
deactivate_user: "Deactivate this User"
confirm_user: "Confirm this User"
+ unconfirm_user: "Unconfirm this User"
+ unsuspend_user: "Unsuspend this User"
hide_user: "Hide this User"
unhide_user: "Unhide this User"
delete_user: "Delete this User"
--- /dev/null
+require "application_system_test_case"
+
+class UserStatusChangeTest < ApplicationSystemTestCase
+ def setup
+ admin = create(:administrator_user)
+ sign_in_as(admin)
+ end
+
+ test "Admin can unsuspend a user" do
+ user = create(:user, :suspended)
+ visit user_path(user)
+ accept_confirm do
+ click_on "Unsuspend"
+ end
+
+ assert_no_content "Unsuspend"
+ user.reload
+ assert_equal "active", user.status
+ end
+
+ test "Admin can confirm a user" do
+ user = create(:user, :suspended)
+ visit user_path(user)
+ accept_confirm do
+ click_on "Confirm"
+ end
+
+ assert_no_content "Unsuspend"
+ user.reload
+ assert_equal "confirmed", user.status
+ end
+end