Fixes #3050 - newly created users are only shown in the admin interface after reload
This commit is contained in:
parent
d09a3c5b85
commit
30654f8d7d
4 changed files with 79 additions and 8 deletions
|
@ -179,9 +179,21 @@ class User extends App.ControllerSubContent
|
|||
navupdate: '#users'
|
||||
genericObject: 'User'
|
||||
container: @el.closest('.content')
|
||||
callback: @search
|
||||
callback: @newUserAddedCallback
|
||||
)
|
||||
|
||||
# GitHub Issue #3050
|
||||
# resets search input value to empty after new user added
|
||||
# resets any active role tab
|
||||
newUserAddedCallback: =>
|
||||
@searchInput.val('')
|
||||
@query = ''
|
||||
@resetActiveTabs()
|
||||
@search()
|
||||
|
||||
resetActiveTabs: ->
|
||||
@$('.tab.active').removeClass('active')
|
||||
|
||||
import: (e) ->
|
||||
e.preventDefault()
|
||||
new App.Import(
|
||||
|
|
|
@ -91,6 +91,8 @@ returns
|
|||
# enable search only for agents and admins
|
||||
return [] if !search_preferences(current_user)
|
||||
|
||||
is_query = query.present? && query != '*'
|
||||
|
||||
# lookup for roles of permission
|
||||
if params[:permissions].present?
|
||||
params[:role_ids] ||= []
|
||||
|
@ -99,7 +101,7 @@ returns
|
|||
end
|
||||
|
||||
# try search index backend
|
||||
if SearchIndexBackend.enabled?
|
||||
if SearchIndexBackend.enabled? && is_query
|
||||
query_extension = {}
|
||||
if params[:role_ids].present?
|
||||
query_extension['bool'] ||= {}
|
||||
|
@ -162,12 +164,15 @@ returns
|
|||
end
|
||||
end
|
||||
|
||||
statement.where(
|
||||
'(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
|
||||
)
|
||||
.order(Arel.sql(order_sql))
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
if is_query
|
||||
statement = statement.where(
|
||||
'(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
|
||||
)
|
||||
end
|
||||
|
||||
statement.order(Arel.sql(order_sql))
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1434,6 +1434,37 @@ RSpec.describe 'User', type: :request do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/users/search, checks ES Usage', searchindex: true, authenticated_as: :agent do
|
||||
let!(:agent) { create(:agent) }
|
||||
|
||||
def make_request(params)
|
||||
get '/api/v1/users/search', params: params, as: :json
|
||||
end
|
||||
|
||||
before do
|
||||
# create some users that can be found
|
||||
create(:agent, firstname: 'Test-Agent1')
|
||||
create(:agent, firstname: 'Test-Agent2')
|
||||
|
||||
configure_elasticsearch(rebuild: true)
|
||||
end
|
||||
|
||||
it 'uses elasticsearch when query is non empty' do
|
||||
# Check if ES is used
|
||||
allow(SearchIndexBackend).to receive(:search)
|
||||
|
||||
make_request(query: 'Test')
|
||||
expect(SearchIndexBackend).to have_received(:search)
|
||||
end
|
||||
|
||||
it 'does not uses elasticsearch when query is empty' do
|
||||
allow(SearchIndexBackend).to receive(:search)
|
||||
|
||||
make_request(query: '')
|
||||
expect(SearchIndexBackend).not_to have_received(:search)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/users/avatar', authenticated_as: :user do
|
||||
let(:user) { create(:user) }
|
||||
let(:base64) { 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' }
|
||||
|
|
|
@ -50,4 +50,27 @@ RSpec.describe 'Manage > Users', type: :system do
|
|||
expect(page).to have_text("Zammad looks like this for \"#{user.firstname} #{user.lastname}\"", wait: 10)
|
||||
end
|
||||
end
|
||||
|
||||
# Fixes GitHub Issue #3050 - Newly created users are only shown in the admin interface after reload
|
||||
describe 'adding a new user', authenticated_as: -> { user } do
|
||||
let(:user) { create(:admin) }
|
||||
|
||||
it 'newly added user is visible in the user list' do
|
||||
visit '#manage/users'
|
||||
|
||||
within(:active_content) do
|
||||
find('[data-type=new]').click
|
||||
|
||||
find('[name=firstname]').fill_in with: 'NewTestUserFirstName'
|
||||
find('[name=lastname]').fill_in with: 'User'
|
||||
find('span.label-text', text: 'Customer').first(:xpath, './/..').click
|
||||
|
||||
click '.js-submit'
|
||||
|
||||
expect(page).to have_css('table.user-list td', text: 'NewTestUserFirstName')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue