diff --git a/app/controllers/support_interface/support_users_controller.rb b/app/controllers/support_interface/support_users_controller.rb index 8d82d308da8..f5ab8ce8a06 100644 --- a/app/controllers/support_interface/support_users_controller.rb +++ b/app/controllers/support_interface/support_users_controller.rb @@ -1,7 +1,8 @@ module SupportInterface class SupportUsersController < SupportInterfaceController def index - @support_users = params[:removed] == 'true' ? SupportUser.discarded : SupportUser.kept + unsorted_support_users = params[:removed] == 'true' ? SupportUser.discarded : SupportUser.kept + @support_users = unsorted_support_users.order!(last_signed_in_at: :asc) end def show diff --git a/app/views/support_interface/support_users/index.html.erb b/app/views/support_interface/support_users/index.html.erb index e0208c1dabd..60cd8e2210c 100644 --- a/app/views/support_interface/support_users/index.html.erb +++ b/app/views/support_interface/support_users/index.html.erb @@ -6,6 +6,7 @@ Email + Last Login Date DfE Sign-in UID Actions @@ -16,6 +17,9 @@ <%= govuk_link_to support_user.display_name, support_interface_support_user_path(support_user) %> + + + <%= support_user.last_signed_in_at&.to_fs(:govuk_date_and_time) || 'Not signed in yet' %> <%= support_user.dfe_sign_in_uid %> diff --git a/spec/system/support_interface/managing_support_users_spec.rb b/spec/system/support_interface/managing_support_users_spec.rb index 9b41a120394..c2e2b3d26ed 100644 --- a/spec/system/support_interface/managing_support_users_spec.rb +++ b/spec/system/support_interface/managing_support_users_spec.rb @@ -7,7 +7,7 @@ given_i_am_a_support_user when_i_visit_the_support_console - and_i_click_the_manange_support_users_link + and_i_click_the_manage_support_users_link and_i_click_the_add_user_link and_i_enter_the_users_email_and_dsi_uid and_i_click_add_user @@ -23,6 +23,37 @@ then_i_see_an_error end + scenario 'orders users by last login date', :with_audited do + given_i_am_a_support_user + + when_i_visit_the_support_console + and_there_are_other_support_users_in_the_db + and_i_click_the_manage_support_users_link + and_i_see_the_last_login_date_column + then_i_see_users_ordered_by_oldest_login + end + + def then_i_see_users_ordered_by_oldest_login + emails = page.all('tbody .govuk-table__row td:first-child a.govuk-link').map(&:text) + + expect(emails).to eq([ + 'isignedinyesterday@msn.com', + 'user@apply-support.com', + 'isignedintoday@msn.com', + 'isignedintomorrow@msn.com', + ]) + end + + def and_i_see_the_last_login_date_column + expect(page).to have_css('th.govuk-table__header', text: 'Last Login Date') + end + + def and_there_are_other_support_users_in_the_db + SupportUser.create(email_address: 'isignedinyesterday@msn.com', last_signed_in_at: Time.zone.yesterday, dfe_sign_in_uid: 'Y') + SupportUser.create(email_address: 'isignedintoday@msn.com', last_signed_in_at: Time.zone.now, dfe_sign_in_uid: 'TD') + SupportUser.create(email_address: 'isignedintomorrow@msn.com', last_signed_in_at: Time.zone.tomorrow, dfe_sign_in_uid: 'TM') + end + def given_i_am_a_support_user sign_in_as_support_user end @@ -31,7 +62,7 @@ def when_i_visit_the_support_console visit support_interface_path end - def and_i_click_the_manange_support_users_link + def and_i_click_the_manage_support_users_link click_link_or_button 'Settings' click_link_or_button 'Support users' end