Skip to content

Commit

Permalink
Make users searchable and add deactivated users
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism committed Jul 17, 2024
1 parent 60b756c commit ff3491e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
14 changes: 9 additions & 5 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
class Admin::UsersController < AdminController
def index
if @team.present?
@users = @team.users
@active_users_count = User.active_users.count

if params[:search_for].present?
search_string = "%#{params[:search_for].downcase}%"
@users = User.where("LOWER(full_name) like ? OR LOWER(email) like ?", search_string, search_string)
.order(:full_name)
.page(params[:page]).per(10)
.decorate
else
@users = User.all
@users = User.unscoped
.order(:full_name)
.page(params[:page]).per(100)
.decorate

@active_users_count = User.active_users.count
end
end
end
9 changes: 9 additions & 0 deletions app/views/admin/users/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
= @active_users_count
= " #{ 'active user'.pluralize(@active_users_count)}"

.grid-row
= form_with method: :get do |f|
= f.text_field :search_for, value: params[:search_for]
= f.submit "Search"

.grid-row
.column-full.table-container.container
table.users.table-font-xsmall.report
Expand All @@ -23,6 +28,8 @@
= t('.full_name')
th scope='col'
= t('.email')
th scope='col'
= t('.deactivated')
th scope='col'
= t('.teams')
th scope='col'
Expand All @@ -34,6 +41,8 @@
= user.full_name
td aria-label="#{t('.email')}"
= user.email
td aria-label="#{t('.deactivated')}"
= user.deactivated? ? user.deleted_at.strftime("%d/%m/%Y") : "No"
td aria-label="#{t('.teams')}"
ul
- user.teams.each do |team|
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ en:
users:
index:
cases: Cases
deactivated: Deactivated
email: Email
full_name: Name
heading: Users
Expand Down
19 changes: 14 additions & 5 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
describe Admin::UsersController do
describe "GET index" do
let(:admin) { create :admin }
let(:manager) { create :manager }
let(:dacu) { find_or_create :team_dacu }

context "when authenticated admin" do
before { sign_in admin }
before do
User.first.soft_delete
sign_in admin
end

it "retrieves all the users" do
it "retrieves all the users including soft deleted" do
get :index

expect(assigns(:users)).to match_array User.all
expect(assigns(:users)).to match_array User.unscoped
end

it "renders the index view" do
get :index

expect(response).to have_rendered("admin/users/index")
end

context "when searching" do
it "retrieves users matching the search term" do
get :index, params: { search_for: "Branston" }

expect(assigns(:users)).to match_array User.where(full_name: "branston registry responding user")
end
end
end
end
end

0 comments on commit ff3491e

Please sign in to comment.