]> git.openstreetmap.org Git - rails.git/commitdiff
Add extra user transitions needed by the administrators
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 2 Feb 2022 16:37:50 +0000 (16:37 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 2 Feb 2022 16:37:50 +0000 (16:37 +0000)
app/controllers/users_controller.rb
app/models/user.rb
app/views/users/show.html.erb
config/locales/en.yml
test/system/user_status_change_test.rb [new file with mode: 0644]

index ea04e14f6a9d4757d693e547f8e8cbadd8c4d2b4..39a191d841effafde6ca2a9d4b5a90f70270d57f 100644 (file)
@@ -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
 
index 123ef3230e39fd025dc3e06bd1c1a2e219486d8c..cc12adecc467c66a39aab7adab446cc0d4a5ccfb 100644 (file)
@@ -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
index b3502f29ec738d933bc2fb982950e38ea797f6f5..8987785da38a79023ddc74c209c31a707e397fa7 100644 (file)
                 </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") } %>
index 3055905cabe712835335a2da0d8199b2c32c5b54..95d2e721976fc59008a46bb317f2c510882572ba 100644 (file)
@@ -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 (file)
index 0000000..30b9237
--- /dev/null
@@ -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