From 9ea6e77fef1f638c07ff3b95877b9000d6ec78ad Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 30 May 2022 09:18:33 +0100 Subject: [PATCH] Show deactivated user in the user list --- app/controllers/modules/search_filter.rb | 2 +- app/models/user.rb | 1 - app/views/users/_user_list.html.erb | 2 +- spec/controllers/modules/search_filter_spec.rb | 8 ++++---- spec/requests/organisations_controller_spec.rb | 4 ++-- spec/requests/users_controller_spec.rb | 10 +++++++--- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/modules/search_filter.rb b/app/controllers/modules/search_filter.rb index 09c387ee4..c32298987 100644 --- a/app/controllers/modules/search_filter.rb +++ b/app/controllers/modules/search_filter.rb @@ -8,6 +8,6 @@ module Modules::SearchFilter end def filtered_users(base_collection, search_term = nil) - filtered_collection(base_collection, search_term).filter_by_active.includes(:organisation) + filtered_collection(base_collection, search_term).includes(:organisation) end end diff --git a/app/models/user.rb b/app/models/user.rb index 97cc43c62..b6e53d219 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,7 +34,6 @@ class User < ApplicationRecord scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_email, ->(email) { where("email ILIKE ?", "%#{email}%") } - scope :filter_by_active, -> { where(active: true) } scope :search_by, ->(param) { search_by_name(param).or(search_by_email(param)) } def case_logs diff --git a/app/views/users/_user_list.html.erb b/app/views/users/_user_list.html.erb index a934e211e..b0a9cb52b 100644 --- a/app/views/users/_user_list.html.erb +++ b/app/views/users/_user_list.html.erb @@ -47,7 +47,7 @@ ) : "" %> <% end %> <% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %> - <% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %> + <% row.cell(text: user.active? ? user.last_sign_in_at&.to_formatted_s(:govuk_date) : "Deactivated") %> <% end %> <% end %> <% end %> diff --git a/spec/controllers/modules/search_filter_spec.rb b/spec/controllers/modules/search_filter_spec.rb index 4db149e69..b46878d82 100644 --- a/spec/controllers/modules/search_filter_spec.rb +++ b/spec/controllers/modules/search_filter_spec.rb @@ -40,16 +40,16 @@ RSpec.describe Modules::SearchFilter do context "when given a search term" do let(:search_term) { "Blogg" } - it "filters the collection on search term and active users" do - expect(instance.filtered_users(user_list, search_term).count).to eq(1) + it "filters the collection on search term" do + expect(instance.filtered_users(user_list, search_term).count).to eq(2) end end context "when not given a search term" do let(:search_term) { nil } - it "filters the collection on active users" do - expect(instance.filtered_users(user_list, search_term).count).to eq(6) + it "returns all the users" do + expect(instance.filtered_users(user_list, search_term).count).to eq(7) end end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 74c1fe6b6..841439ea9 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -134,12 +134,12 @@ RSpec.describe OrganisationsController, type: :request do it "shows only active users in the current user's organisation" do expect(page).to have_content(user.name) expect(page).to have_content(other_user.name) - expect(page).not_to have_content(inactive_user.name) + expect(page).to have_content(inactive_user.name) expect(page).not_to have_content(other_org_user.name) end it "shows the pagination count" do - expect(page).to have_content("2 total users") + expect(page).to have_content("3 total users") end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index d27d4ea10..8e6e44385 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -900,15 +900,19 @@ RSpec.describe UsersController, type: :request do get "/users", headers:, params: {} end - it "shows all active users" do + it "shows all users" do expect(page).to have_content(user.name) expect(page).to have_content(other_user.name) - expect(page).not_to have_content(inactive_user.name) + expect(page).to have_content(inactive_user.name) expect(page).to have_content(other_org_user.name) end + it "shows last logged in as deactivated for inactive users" do + expect(page).to have_content("Deactivated") + end + it "shows the pagination count" do - expect(page).to have_content("3 total users") + expect(page).to have_content("4 total users") end it "shows the download csv link" do