From 2731e7244ac554c4a17f69347851f8f829cd1caa Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 2 Feb 2022 16:37:50 +0000 Subject: [PATCH] Add extra user transitions needed by the administrators --- app/controllers/users_controller.rb | 2 ++ app/models/user.rb | 11 +++++++++ app/views/users/show.html.erb | 12 ++++++++++ config/locales/en.yml | 2 ++ test/system/user_status_change_test.rb | 32 ++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 test/system/user_status_change_test.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ea04e14f6..39a191d84 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -202,8 +202,10 @@ class UsersController < ApplicationController 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 diff --git a/app/models/user.rb b/app/models/user.rb index 123ef3230..cc12adecc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -181,10 +181,21 @@ class User < ApplicationRecord 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 diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index b3502f29e..8987785da 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -145,12 +145,24 @@ <% end %> + <% if @user.may_unsuspend? %> +
  • + <%= link_to t(".unsuspend_user"), set_status_user_path(:event => "unsuspend", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %> +
  • + <% end %> + <% if @user.may_confirm? %>
  • <%= link_to t(".confirm_user"), set_status_user_path(:event => "confirm", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %>
  • <% end %> + <% if @user.may_unconfirm? %> +
  • + <%= link_to t(".unconfirm_user"), set_status_user_path(:event => "unconfirm", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %> +
  • + <% end %> + <% if @user.may_hide? %>
  • <%= link_to t(".hide_user"), set_status_user_path(:event => "hide", :display_name => @user.display_name), :method => :post, :data => { :confirm => t(".confirm") } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3055905ca..95d2e7219 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2588,6 +2588,8 @@ en: 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" diff --git a/test/system/user_status_change_test.rb b/test/system/user_status_change_test.rb new file mode 100644 index 000000000..30b923732 --- /dev/null +++ b/test/system/user_status_change_test.rb @@ -0,0 +1,32 @@ +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 -- 2.43.2