diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e77c687bf..85cfad9f5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -37,6 +37,8 @@ class UsersController < ApplicationController flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password") redirect_to account_path else + flash[:notice] = I18n.t("devise.activation.deactivated", user_name: @user.name) if user_params[:active] == "false" + flash[:notice] = I18n.t("devise.activation.reactivated", user_name: @user.name) if user_params[:active] == "true" redirect_to user_path(@user) end elsif user_params.key?("password") diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 33a4fda96..9a32b8ea1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -9,7 +9,11 @@ <% if @user.active? %> <%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %> <% else %> - This user has been deactivated. <%= govuk_link_to "Reactivate user", "/users/#{@user.id}/reactivate" %> +
+ + This user has been deactivated. <%= govuk_link_to "Reactivate user", "/users/#{@user.id}/reactivate" %> + +
<% end %> <% end %> diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 707e8cffa..5c609382d 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -54,6 +54,10 @@ en: send_instructions: "You will receive an email in a few minutes with instructions for how to unlock your account" send_paranoid_instructions: "If your account exists, you will receive an email in a few minutes with instructions for how to unlock it" unlocked: "Your account has been successfully unlocked. Sign in to continue." + activation: + deactivated: "%{user_name} has been deactivated." + reactivated: "%{user_name} has been reactivated." + errors: messages: already_confirmed: "Email has already been confirmed. Sign in." diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index d5445c386..cdbfe1348 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -376,6 +376,62 @@ RSpec.describe "User Features" do )).to be_a(User) end end + + context "when deactivating a user" do + let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } + let!(:other_user) { FactoryBot.create(:user, name: "Other name", organisation: user.organisation) } + + before do + visit("/logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") + click_button("Sign in") + visit("/users/#{other_user.id}") + click_link("Deactivate user") + end + + it "allows to cancel user deactivation" do + click_link("No - I’ve changed my mind") + expect(page).to have_current_path("/users/#{other_user.id}") + expect(page).to have_no_content("This user has been deactivated.") + expect(page).to have_no_css(".govuk-notification-banner.govuk-notification-banner--success") + end + + it "allows to deactivate the user" do + click_button("I’m sure - deactivate this user") + expect(page).to have_current_path("/users/#{other_user.id}") + expect(page).to have_content("This user has been deactivated.") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + end + end + + context "when reactivating a user" do + let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } + let!(:other_user) { FactoryBot.create(:user, name: "Other name", active: false, organisation: user.organisation) } + + before do + visit("/logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") + click_button("Sign in") + visit("/users/#{other_user.id}") + click_link("Reactivate user") + end + + it "allows to cancel user reactivation" do + click_link("No - I’ve changed my mind") + expect(page).to have_current_path("/users/#{other_user.id}") + expect(page).to have_content("This user has been deactivated.") + expect(page).to have_no_css(".govuk-notification-banner.govuk-notification-banner--success") + end + + it "allows to reactivate the user" do + click_button("I’m sure - reactivate this user") + expect(page).to have_current_path("/users/#{other_user.id}") + expect(page).to have_no_content("This user has been deactivated.") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + end + end end context "when the user is a customer support person" do