diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb
index e2a3ec92d..3cb02b769 100644
--- a/app/helpers/tag_helper.rb
+++ b/app/helpers/tag_helper.rb
@@ -14,6 +14,7 @@ module TagHelper
deactivated: "Deactivated",
deleted: "Deleted",
merged: "Merged",
+ unconfirmed: "Unconfirmed",
}.freeze
COLOUR = {
@@ -29,6 +30,7 @@ module TagHelper
deactivated: "grey",
deleted: "red",
merged: "orange",
+ unconfirmed: "red",
}.freeze
def status_tag(status, classes = [])
diff --git a/app/models/user.rb b/app/models/user.rb
index 0fc21172a..25599da56 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -237,6 +237,16 @@ class User < ApplicationRecord
active_unread_notifications.last
end
+ def status
+ if active == false
+ :deactivated
+ elsif confirmed? == false
+ :unconfirmed
+ else
+ :active
+ end
+ end
+
protected
# Checks whether a password is needed or not. For validations only.
diff --git a/app/views/users/_user_list.html.erb b/app/views/users/_user_list.html.erb
index fd854b53b..19e206b03 100644
--- a/app/views/users/_user_list.html.erb
+++ b/app/views/users/_user_list.html.erb
@@ -50,7 +50,7 @@
<% end %>
<% end %>
<% row.with_cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %>
- <% row.with_cell(text: user.active? ? user.last_sign_in_at&.to_formatted_s(:govuk_date) : "Deactivated") %>
+ <% row.with_cell(text: user.active? ? user.last_sign_in_at&.to_formatted_s(:govuk_date) : status_tag(user.status)) %>
<%= govuk_link_to users_path(user) do %>
User <%= user.id %>
<% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index a8f12cd36..bf2877fbc 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -112,6 +112,12 @@
row.with_action
end
end %>
+
+ <%= summary_list.with_row do |row|
+ row.with_key { "Status" }
+ row.with_value { status_tag(@user.status) }
+ row.with_action
+ end %>
<% end %>
@@ -123,7 +129,7 @@
<% end %>
<% else %>
- This user has been deactivated. <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %>
+ <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %>
<% end %>
<% end %>
diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb
index e898c1b0a..180a92aec 100644
--- a/spec/features/user_spec.rb
+++ b/spec/features/user_spec.rb
@@ -487,7 +487,7 @@ RSpec.describe "User Features" do
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_content("Deactivated")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
end
end
@@ -517,7 +517,7 @@ RSpec.describe "User Features" do
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_content("Deactivated")
expect(page).to have_no_css(".govuk-notification-banner.govuk-notification-banner--success")
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index c272320b2..774a7893b 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -481,4 +481,41 @@ RSpec.describe User, type: :model do
end
end
end
+
+ describe "#status" do
+ let(:user) { create(:user) }
+
+ it "returns :deactivated for deactivated users" do
+ user.active = false
+
+ expect(user.status).to eq(:deactivated)
+ end
+
+ it "returns :unconfirmed for a user with no confirmed_at" do
+ user.confirmed_at = nil
+
+ expect(user.status).to eq(:unconfirmed)
+ end
+
+ it "returns :deactivated for a user with no confirmed_at and active false" do
+ user.confirmed_at = nil
+ user.active = false
+
+ expect(user.status).to eq(:deactivated)
+ end
+
+ it "returns :unconfirmed for a user with no confirmed_at and active true" do
+ user.confirmed_at = nil
+ user.active = true
+
+ expect(user.status).to eq(:unconfirmed)
+ end
+
+ it "returns :active for a user with active status and confirmation date" do
+ user.active = true
+ user.confirmed_at = Time.zone.yesterday
+
+ expect(user.status).to eq(:active)
+ end
+ end
end
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 48cc0f064..ddc457f6c 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -622,7 +622,7 @@ RSpec.describe UsersController, type: :request do
end
it "shows if user is not active" do
- expect(page).to have_content("This user has been deactivated.")
+ expect(page).to have_content("Deactivated")
end
it "allows reactivating the user" do
@@ -1467,7 +1467,7 @@ RSpec.describe UsersController, type: :request do
end
it "shows if user is not active" do
- expect(page).to have_content("This user has been deactivated.")
+ expect(page).to have_content("Deactivated")
end
it "allows reactivating the user" do