Fixed bug: OTRS import throws an exception if no Article From is present.
This commit is contained in:
parent
a306078ebb
commit
68bab40c13
2 changed files with 23 additions and 1 deletions
|
@ -13,6 +13,7 @@ module Import
|
||||||
|
|
||||||
def find(article)
|
def find(article)
|
||||||
email = local_email(article['From'])
|
email = local_email(article['From'])
|
||||||
|
return if !email
|
||||||
user = ::User.find_by(email: email)
|
user = ::User.find_by(email: email)
|
||||||
user ||= ::User.find_by(login: email)
|
user ||= ::User.find_by(login: email)
|
||||||
user
|
user
|
||||||
|
@ -20,7 +21,9 @@ module Import
|
||||||
|
|
||||||
def local_email(from)
|
def local_email(from)
|
||||||
# TODO: should get unified with User#check_email
|
# TODO: should get unified with User#check_email
|
||||||
extract_email(from).downcase
|
email = extract_email(from)
|
||||||
|
return if !email
|
||||||
|
email.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -47,4 +47,23 @@ RSpec.describe Import::OTRS::ArticleCustomer do
|
||||||
expect(User.last.email).to eq('user@example.com')
|
expect(User.last.email).to eq('user@example.com')
|
||||||
expect(User.last.login).to eq('user@example.com')
|
expect(User.last.login).to eq('user@example.com')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '.find' do
|
||||||
|
|
||||||
|
it 'returns nil if no email could be found' do
|
||||||
|
expect(described_class.find({})).to be nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context '.local_email' do
|
||||||
|
|
||||||
|
it 'returns nil if no email could be found' do
|
||||||
|
expect(described_class.local_email(nil)).to be nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the parameter if no email could be found' do
|
||||||
|
not_an_email = 'thisisnotanemail'
|
||||||
|
expect(described_class.local_email(not_an_email)).to eq(not_an_email)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue