Browse Source

CLDC-2742 Update user status display behaviour (#2307)

* feat: use status tags to show user active status

* feat: add unconfirmed status

* feat: update tests

* refactor: erblinting

* feat: update tests

* refactor: lint
pull/2319/head
natdeanlewissoftwire 9 months ago committed by GitHub
parent
commit
73aec51425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/helpers/tag_helper.rb
  2. 10
      app/models/user.rb
  3. 2
      app/views/users/_user_list.html.erb
  4. 8
      app/views/users/show.html.erb
  5. 4
      spec/features/user_spec.rb
  6. 37
      spec/models/user_spec.rb
  7. 4
      spec/requests/users_controller_spec.rb

2
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 = [])

10
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.

2
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 %>
<span class="govuk-visually-hidden">User </span><%= user.id %>
<% end %>

8
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 %>
<div class="govuk-button-group">
@ -123,7 +129,7 @@
<% end %>
<% else %>
<span class="app-!-colour-muted govuk-!-margin-right-2">
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) %>
</span>
<% end %>
<% end %>

4
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

37
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

4
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

Loading…
Cancel
Save