diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f7e7c5a81..e77c687bf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -81,13 +81,17 @@ class UsersController < ApplicationController end def deactivate - unless current_user != @user && (current_user.support? || current_user.data_coordinator?) + if current_user.can_toggle_active?(@user) + render "toggle-active", locals: { action: "deactivate" } + else redirect_to user_path(@user) end end def reactivate - unless current_user != @user && (current_user.support? || current_user.data_coordinator?) + if current_user.can_toggle_active?(@user) + render "toggle-active", locals: { action: "reactivate" } + else redirect_to user_path(@user) end end diff --git a/app/models/user.rb b/app/models/user.rb index b6e53d219..f6a20c722 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -135,4 +135,8 @@ class User < ApplicationRecord end end end + + def can_toggle_active?(user) + self != user && (support? || data_coordinator?) + end end diff --git a/app/views/users/deactivate.html.erb b/app/views/users/deactivate.html.erb deleted file mode 100644 index ce5b64f1e..000000000 --- a/app/views/users/deactivate.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<% content_for :title, current_user == @user ? "Your account" : "#{@user.name.presence || @user.email}’s account" %> - -
Deactivating this user will mean they can no longer access this service to submit CORE data.
-Any logs this user has already submitted will not be affected.
- <%= f.govuk_text_field :active, - value: false, - hidden: true %> - - <%= f.govuk_submit "I’m sure - deactivate this user" %> -- <%= govuk_link_to("No - I’ve changed my mind", user_path(@user)) %> -
-- <%= govuk_link_to("No - I’ve changed my mind", user_path(@user)) %> -
-Deactivating this user will mean they can no longer access this service to submit CORE data.
+Any logs this user has already submitted will not be affected.
+ <% end %> + <% active_value = action == "deactivate" ? false : true %> ++ <%= govuk_link_to("No - I’ve changed my mind", user_path(@user)) %> +
+