From e52a489dc49b5e1de892a102462fdd2aae1fcac9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 25 Sep 2014 01:12:23 +0200 Subject: [PATCH] Added user search. --- app/controllers/users_controller.rb | 49 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3ebbfce45..75497aab0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -337,26 +337,47 @@ curl http://localhost/api/v1/users/2.json -v -u #{login}:#{password} -H "Content return end - # do query - user_all = User.search( + query_params = { :query => params[:term], :limit => params[:limit], :current_user => current_user, - ) - - # build result list - users = [] - user_all.each do |user| - realname = user.firstname.to_s + ' ' + user.lastname.to_s - if user.email && user.email.to_s != '' - realname = realname + ' <' + user.email.to_s + '>' - end - a = { :id => user.id, :label => realname, :value => realname } - users.push a + } + if params[:role_ids] && !params[:role_ids].empty? + query_params[:role_ids] = params[:role_ids] end + # do query + user_all = User.search(query_params) + + # build result list + if !params[:full] + users = [] + user_all.each { |user| + realname = user.firstname.to_s + ' ' + user.lastname.to_s + if user.email && user.email.to_s != '' + realname = realname + ' <' + user.email.to_s + '>' + end + a = { :id => user.id, :label => realname, :value => realname } + users.push a + } + + # return result + render :json => users + return + end + + user_ids = [] + assets = {} + user_all.each { |user| + assets = user.assets(assets) + user_ids.push user.id + } + # return result - render :json => users + render :json => { + :assets => assets, + :user_ids => user_ids, + } end # GET /api/v1/users/history/1