Skip to content

Commit

Permalink
Fixes #5166 - After Znuny import in Zammad: Users without a valid ema…
Browse files Browse the repository at this point in the history
…il address gives an 500 error in Zammad when creating a new mail
  • Loading branch information
zammad-sync committed May 17, 2024
1 parent e8508ec commit 48881ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,14 @@ def search
users = []
user_all.each do |user|
realname = user.fullname

# improve realname, if possible
if user.email.present? && realname != user.email
realname = Channel::EmailBuild.recipient_line realname, user.email
begin
realname = Channel::EmailBuild.recipient_line(realname, user.email)
rescue Mail::Field::IncompleteParseError
# mute if parsing of recipient_line was not successful / #5166
end
end
a = if params[:term]
{ id: user.id, label: realname, value: user.email, inactive: !user.active }
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,30 @@ def make_request(image_hash, params: {})
end
end

describe 'GET /api/v1/users/search, with invalid attributes', authenticated_as: :agent do
let(:agent) { create(:agent) }
let(:customer_invalid) do
create(
:customer,
login: 'customer1@example.com',
firstname: 'Some',
lastname: 'Customer1',
email: 'customer1@example.com',
)
end

context 'when email address is invalid' do
before do
customer_invalid.update_attribute(:email, 'eee lala')
post '/api/v1/users/search', params: { term: 'Customer1' }, as: :json
end

it 'succeeds' do
expect(response).to have_http_status(:success)
end
end
end

describe 'PUT /api/v1/users/{id}', authenticated_as: :admin do
let(:admin) { create(:admin) }
let(:agent) { create(:agent) }
Expand Down

0 comments on commit 48881ba

Please sign in to comment.