Fixes #3190 - Finding a user by email address not possible.

This commit is contained in:
Rolf Schmidt 2020-09-24 13:34:04 +02:00 committed by Thorsten Eckel
parent d41643a568
commit a49ff87ef2
6 changed files with 122 additions and 5 deletions

View file

@ -75,9 +75,6 @@ class App.SearchableAjaxSelect extends App.SearchableSelect
# refresh elements # refresh elements
@refreshElements() @refreshElements()
# execute filter
@filterByQuery originalQuery
renderResponseItemAjax: (elem, data) -> renderResponseItemAjax: (elem, data) ->
result = _.find(data.details, (detailElem) -> detailElem.type == elem.type and detailElem.id == elem.id) result = _.find(data.details, (detailElem) -> detailElem.type == elem.type and detailElem.id == elem.id)

View file

@ -0,0 +1,21 @@
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/form_autocompletion_ajax.js", nonce: true %>
<style type="text/css">
body {
padding-top: 0px;
}
</style>
<%= javascript_tag nonce: true do -%>
<% end -%>
<div id="qunit" class="u-dontfold"></div>
<div>
<form class="form-stacked pull-left">
<div id="forms"></div>
<button type="submit" class="btn btn-primary submit">Submit</button>
</form>
</div>

View file

@ -19,6 +19,7 @@ Zammad::Application.routes.draw do
match '/tests_form_validation', to: 'tests#form_validation', via: :get match '/tests_form_validation', to: 'tests#form_validation', via: :get
match '/tests_form_column_select', to: 'tests#form_column_select', via: :get match '/tests_form_column_select', to: 'tests#form_column_select', via: :get
match '/tests_form_searchable_select', to: 'tests#form_searchable_select', via: :get match '/tests_form_searchable_select', to: 'tests#form_searchable_select', via: :get
match '/tests_form_autocompletion_ajax', to: 'tests#form_autocompletion_ajax', via: :get
match '/tests_form_ticket_perform_action', to: 'tests#form_ticket_perform_action', via: :get match '/tests_form_ticket_perform_action', to: 'tests#form_ticket_perform_action', via: :get
match '/tests_form_sla_times', to: 'tests#form_sla_times', via: :get match '/tests_form_sla_times', to: 'tests#form_sla_times', via: :get
match '/tests_form_skip_rendering', to: 'tests#form_skip_rendering', via: :get match '/tests_form_skip_rendering', to: 'tests#form_skip_rendering', via: :get

View file

@ -0,0 +1,71 @@
function check_ajax_field(field, value, count, callback, waitTotal = 30000, wait = 0) {
$elementInput = $('[name="' + field + '"].js-shadow + .js-input')
if ($elementInput.val() != value) {
$elementInput.focus().val(value).trigger('input')
}
var $element = $('[name="' + field + '"]').closest('.searchableSelect').find('.js-optionsList')
var entries = $element.find('li:not(.is-hidden)').length
var match = entries == count
if (match || wait >= waitTotal) {
equal(entries, count, 'search result found for email address ' + value)
callback()
return
}
wait += 100
if (wait % 3000 == 0) {
ok(true, 'check_ajax_field for ' + field + ' waiting ' + wait)
}
setTimeout(function() {
check_ajax_field(field, value, count, callback, waitTotal, wait)
}, 100)
}
test( "autocompletion_ajax check", function(assert) {
var done = assert.async(1)
$('#forms').append('<hr><h1>autocompletion_ajax check</h1><form id="form1"></form>')
var el = $('#form1')
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{
name: 'autocompletion_ajax1',
display: 'AutocompletionAjax1',
tag: 'autocompletion_ajax',
relation: 'User'
},
]
},
autofocus: true
})
new Promise( (resolve, reject) => {
App.Auth.login({
data: {
username: 'master@example.com',
password: 'test',
},
success: resolve,
error: resolve
});
})
.then( function() {
return new Promise( (resolve, reject) => {
notEqual(App.Session.get(), undefined, 'User is logged in so the api requests will work')
check_ajax_field('autocompletion_ajax1', 'master@example.com', 1, resolve)
})
})
.then( function() {
return new Promise( (resolve, reject) => {
check_ajax_field('autocompletion_ajax1', 'xxx@example.com', 0, resolve)
})
})
.finally(done)
})

View file

@ -57,6 +57,22 @@ RSpec.describe 'Data Privacy', type: :system, searchindex: true, authenticated_a
DataPrivacyTaskJob.perform_now DataPrivacyTaskJob.perform_now
expect(page).to have_text('completed', wait: 5) expect(page).to have_text('completed', wait: 5)
end end
it 'deletes customer by email' do
visit 'system/data_privacy'
click '.js-new'
find(:css, '.js-input').send_keys(customer.email)
expect(page).to have_css('.searchableSelect-option-text', wait: 5)
click '.searchableSelect-option-text'
fill_in 'Are you sure?', with: 'DELETE'
expect(page).to have_text('DELETE ORGANIZATION?', wait: 5)
click '.js-submit'
expect(page).to have_text('in process', wait: 5)
DataPrivacyTaskJob.perform_now
expect(page).to have_text('completed', wait: 5)
end
end end
end end

View file

@ -14,8 +14,8 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we
def async_q_unit_tests(*args) def async_q_unit_tests(*args)
q_unit_tests(*args) do q_unit_tests(*args) do
wait(10, interval: 4).until_constant do wait(120, interval: 3).until_constant do
find('.total').text page.has_css?('.total', wait: 0) ? find('.total').text : nil
end end
end end
end end
@ -131,6 +131,17 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we
end end
end end
context 'Form AJAX', searchindex: true do
before do
configure_elasticsearch
rebuild_searchindex
end
it 'autocompletion ajax' do
async_q_unit_tests('form_autocompletion_ajax')
end
end
context 'Table' do context 'Table' do
it 'Base' do it 'Base' do