From 07148462ddab948f95871aff02e3a2b31176707c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 25 Sep 2014 01:13:17 +0200 Subject: [PATCH] Added user search. --- app/models/user/search.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/user/search.rb b/app/models/user/search.rb index 58e1ecdb6..602e86244 100644 --- a/app/models/user/search.rb +++ b/app/models/user/search.rb @@ -41,9 +41,15 @@ returns # fallback do sql query # - stip out * we already search for *query* - query.gsub! '*', '' - users = User.where( - '(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", - ).order('firstname').limit(limit) + if params[:role_ids] + users = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where( + '(users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", + ).order('firstname').limit(limit) + else + users = User.where( + '(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", + ).order('firstname').limit(limit) + end return users end