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| %>