diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1bdd0f0d7..ff0935592 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -240,6 +240,7 @@ test:integration:es_mysql: - export ES_URL="http://localhost:9200" - rake db:create - rake db:migrate + - ruby -I test/ test/integration/elasticsearch_active_test.rb - ruby -I test/ test/integration/elasticsearch_test.rb - ruby -I test/ test/controllers/search_controller_test.rb - ruby -I test/ test/integration/report_test.rb @@ -259,6 +260,7 @@ test:integration:es_postgresql: - export ES_URL="http://localhost:9200" - rake db:create - rake db:migrate + - ruby -I test/ test/integration/elasticsearch_active_test.rb - ruby -I test/ test/integration/elasticsearch_test.rb - ruby -I test/ test/controllers/search_controller_test.rb - ruby -I test/ test/integration/report_test.rb diff --git a/app/assets/javascripts/app/controllers/users.coffee b/app/assets/javascripts/app/controllers/users.coffee index 32a4d4db9..2aca442d0 100644 --- a/app/assets/javascripts/app/controllers/users.coffee +++ b/app/assets/javascripts/app/controllers/users.coffee @@ -27,23 +27,20 @@ class Index extends App.ControllerSubContent e.preventDefault() $(e.target).toggleClass('active') query = @searchInput.val().trim() - if query - @delay( @search, 220, 'search' ) - return - @recent() + @query = query + @delay(@search, 220, 'search') ) # start search @searchInput.bind( 'keyup', (e) => query = @searchInput.val().trim() - return if !query return if query is @query @query = query - @delay( @search, 220, 'search' ) + @delay(@search, 220, 'search') ) # show last 20 users - @recent() + @search() renderResult: (user_ids = []) -> @stopLoading() @@ -143,43 +140,21 @@ class Index extends App.ControllerSubContent App.Ajax.request( id: 'search' type: 'GET' - url: "#{@apiPath}/users/search" + url: "#{@apiPath}/users/search?sort_by=created_at" data: - query: @query - limit: 140 + query: @query || '*' + limit: 50 role_ids: role_ids full: true processData: true, success: (data, status, xhr) => App.Collection.loadAssets(data.assets) @renderResult(data.user_ids) + @stopLoading() done: => @stopLoading() ) - recent: => - role_ids = [] - @$('.tab.active').each( (i,d) -> - role_ids.push $(d).data('id') - ) - @startLoading(@$('.table-overview')) - App.Ajax.request( - id: 'search' - type: 'GET' - url: "#{@apiPath}/users/recent" - data: - limit: 50 - role_ids: role_ids - full: true - processData: true - success: (data, status, xhr) => - App.Collection.loadAssets(data.assets) - @renderResult(data.user_ids) - @stopLoading() - error: => - @stopLoading() - ) - new: (e) -> e.preventDefault() new App.ControllerGenericNew( @@ -191,7 +166,7 @@ class Index extends App.ControllerSubContent navupdate: '#users' genericObject: 'User' container: @el.closest('.content') - callback: @recent + callback: @search ) import: (e) -> diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c652313dd..e7c03202b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -476,67 +476,6 @@ class UsersController < ApplicationController render json: list, status: :ok end - # @path [GET] /users/recent - # - # @tag Search - # @tag User - # - # @summary Recent creates Users. - # @notes Recent creates Users. - # - # @parameter limit [Integer] The limit of search results. - # @parameter role_ids(multi) [Array] A list of Role identifiers to which the Users have to be allocated to. - # @parameter full [Boolean] Defines if the result should be - # true: { user_ids => [1,2,...], assets => {...} } - # or false: [{:id => user.id, :label => "firstname lastname ", :value => "firstname lastname "},...]. - # - # @response_message 200 [Array] A list of User records matching the search term. - # @response_message 401 Invalid session. - def recent - - if !current_user.permissions?('admin.user') - response_access_deny - return - end - - # do query - user_all = if params[:role_ids].present? - User.joins(:roles).where('roles.id' => params[:role_ids]).where('users.id != 1').order('users.created_at DESC').limit(params[:limit] || 20) - else - User.where('id != 1').order('created_at DESC').limit(params[:limit] || 20) - end - - # build result list - if !response_full? - 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 - end - - # return result - render json: users - return - end - - user_ids = [] - assets = {} - user_all.each do |user| - assets = user.assets(assets) - user_ids.push user.id - end - - # return result - render json: { - assets: assets, - user_ids: user_ids.uniq, - } - end - # @path [GET] /users/history/{id} # # @tag History diff --git a/config/routes/user.rb b/config/routes/user.rb index 3e5b72985..a8fb0c5df 100644 --- a/config/routes/user.rb +++ b/config/routes/user.rb @@ -3,7 +3,6 @@ Zammad::Application.routes.draw do # users match api_path + '/users/search', to: 'users#search', via: %i[get post option] - match api_path + '/users/recent', to: 'users#recent', via: %i[get post] match api_path + '/users/password_reset', to: 'users#password_reset_send', via: :post match api_path + '/users/password_reset_verify', to: 'users#password_reset_verify', via: :post match api_path + '/users/password_change', to: 'users#password_change', via: :post