Browse Source

Add flash banner for successful toggle, fix styles

pull/624/head
Kat 3 years ago
parent
commit
0b564b5b34
  1. 2
      app/controllers/users_controller.rb
  2. 6
      app/views/users/show.html.erb
  3. 4
      config/locales/devise.en.yml
  4. 56
      spec/features/user_spec.rb

2
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")

6
app/views/users/show.html.erb

@ -9,7 +9,11 @@
<% if @user.active? %>
<%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %>
<% else %>
<span class="app-!-colour-muted govuk-!-margin-right-2">This user has been deactivated. <%= govuk_link_to "Reactivate user", "/users/#{@user.id}/reactivate" %></span>
<p>
<span class="app-!-colour-muted govuk-!-margin-right-2">
This user has been deactivated. <%= govuk_link_to "Reactivate user", "/users/#{@user.id}/reactivate" %>
</span>
</p>
<% end %>
<% end %>

4
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."

56
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

Loading…
Cancel
Save