Implemented issue #2136 - Improve admin -> user -> default shown users are sometimes different with and/or without search text -> unify search.

This commit is contained in:
Martin Edenhofer 2018-07-19 16:28:08 +02:00
parent f2ff8ee532
commit 29c61f0586
4 changed files with 11 additions and 96 deletions

View file

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

View file

@ -27,23 +27,20 @@ class Index extends App.ControllerSubContent
e.preventDefault()
$(e.target).toggleClass('active')
query = @searchInput.val().trim()
if query
@query = query
@delay(@search, 220, 'search')
return
@recent()
)
# start search
@searchInput.bind( 'keyup', (e) =>
query = @searchInput.val().trim()
return if !query
return if query is @query
@query = query
@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) ->

View file

@ -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<String>] 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 <email>", :value => "firstname lastname <email>"},...].
#
# @response_message 200 [Array<User>] 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

View file

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