diff --git a/app/views/users/deactivate.html.erb b/app/views/users/deactivate.html.erb index 57a0dbcb0..b78303ba7 100644 --- a/app/views/users/deactivate.html.erb +++ b/app/views/users/deactivate.html.erb @@ -1,7 +1,7 @@ <% content_for :title, current_user == @user ? "Your account" : "#{@user.name.presence || @user.email}’s account" %>
- <%= form_with model: @user, url: user_path(@user), method: "post", local: true do |f| %> + <%= form_for(@user, as: :user, html: { method: :patch }) do |f| %>

<%= @user.name %> @@ -10,6 +10,10 @@

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)) %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 416e83958..8607f4f1d 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -6,7 +6,11 @@ <%= content_for(:title) %>

<% if can_toggle_active?(@user, current_user) %> - <%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %> + <% if @user.active? %> + <%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %> + <% else %> + This user has been deactivated. + <% end %> <% end %>

diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 6637b5040..d27d4ea10 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -505,6 +505,17 @@ RSpec.describe UsersController, type: :request do it "allows deactivating the user" do expect(page).to have_link("Deactivate user", href: "/users/#{other_user.id}/deactivate") end + + context "when user is deactivated" do + before do + other_user.update!(active: false) + get "/users/#{other_user.id}", headers:, params: {} + end + + it "shows if user is not active" do + expect(page).to have_content("This user has been deactivated.") + end + end end context "when the user is not part of the same organisation as the current user" do