From 7b7150735e9c66705ef8ae53d59d8975e0f3fdf6 Mon Sep 17 00:00:00 2001 From: Ted Date: Mon, 23 May 2022 13:37:11 +0100 Subject: [PATCH] Made search work for data co-ordinators Co-authored-by: baarkerlounger --- app/controllers/organisations_controller.rb | 11 +++++++- app/views/users/index.html.erb | 3 +- spec/requests/users_controller_spec.rb | 31 +++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 8468a3f9f..e05b600ca 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -17,7 +17,7 @@ class OrganisationsController < ApplicationController end def users - @pagy, @users = pagy(@organisation.users.where(active: true)) + @pagy, @users = pagy(filtered_users) render "users/index" end @@ -58,6 +58,15 @@ class OrganisationsController < ApplicationController private + def filtered_users + search_param = params["user-search-field"] + if search_param + User.where("name ILIKE ?", "%#{search_param}%").where(active: true) + else + User.all.where(active: true) + end + end + def org_params params.require(:organisation).permit(:name, :address_line1, :address_line2, :postcode, :phone) end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 74c671e39..dfb6c6929 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -8,7 +8,8 @@ <%= govuk_button_link_to "Invite user", new_user_path, html: { method: :get } %> <% end %> -<%= form_with model: @user, url: users_path(), method: "get", local: true do |f| %> +<% path = current_user.support? ? users_path : users_organisation_path(current_user.organisation) %> +<%= form_with model: @user, url: path, method: "get", local: true do |f| %>