From b76be9eebc52b4abb39d0ec2b59b767ecb280561 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 2 Oct 2017 12:31:59 +0200 Subject: [PATCH] Small code layout improvements. --- app/controllers/cti_controller.rb | 2 +- app/models/avatar.rb | 2 +- app/models/channel/email_parser.rb | 34 ++++++++++++--------------- app/models/channel/filter/database.rb | 2 ++ lib/auto_wizard.rb | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/controllers/cti_controller.rb b/app/controllers/cti_controller.rb index 61383428b..03ac19142 100644 --- a/app/controllers/cti_controller.rb +++ b/app/controllers/cti_controller.rb @@ -22,7 +22,7 @@ class CtiController < ApplicationController def done log = Cti::Log.find(params['id']) log.done = params['done'] - log.save + log.save! render json: {} end diff --git a/app/models/avatar.rb b/app/models/avatar.rb index cb4159e09..2684fe7bb 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -151,7 +151,7 @@ add avatar by url data[:full][:mime_type] = mime_type # try zammad backend to find image based on email - elsif data[:url] && data[:url] =~ /@/ + elsif data[:url].present? && data[:url] =~ /@/ # check if source ist already updated within last 3 minutes if avatar_already_exists && avatar_already_exists.source_url == data[:url] diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 9b59f8c21..1f6711239 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -693,7 +693,7 @@ returns def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false) - # loop all x-zammad-hedaer-* headers + # loop all x-zammad-header-* headers item_object.attributes.each { |key, _value| # ignore read only attributes @@ -711,37 +711,33 @@ returns # only set value on _id if value/reference lookup exists if mail[ header.to_sym ] - Rails.logger.info "header #{header} found #{mail[header.to_sym]}" + Rails.logger.info "set_attributes_by_x_headers header #{header} found #{mail[header.to_sym]}" item_object.class.reflect_on_all_associations.map { |assoc| next if assoc.name.to_s != key_short - Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[header.to_sym]}" + Rails.logger.info "set_attributes_by_x_headers found #{assoc.class_name} lookup for '#{mail[header.to_sym]}'" item = assoc.class_name.constantize assoc_object = nil - assoc_has_object = false if item.respond_to?(:name) - assoc_has_object = true - if item.lookup(name: mail[header.to_sym]) - assoc_object = item.lookup(name: mail[header.to_sym]) - end - elsif item.respond_to?(:login) - assoc_has_object = true - if item.lookup(login: mail[header.to_sym]) - assoc_object = item.lookup(login: mail[header.to_sym]) - end + assoc_object = item.lookup(name: mail[header.to_sym]) + end + if !assoc_object && item.respond_to?(:login) + assoc_object = item.lookup(login: mail[header.to_sym]) end - next if assoc_has_object == false + if assoc_object.blank? - if assoc_object - item_object[key] = assoc_object.id + # no assoc exists, remove header + mail.delete(header.to_sym) next end - # no assoc exists, remove header - mail.delete(header.to_sym) + Rails.logger.info "set_attributes_by_x_headers assign #{item_object.class} #{key}=#{assoc_object.id}" + + item_object[key] = assoc_object.id + } end end @@ -752,7 +748,7 @@ returns header = "x-zammad-#{header_name}-#{suffix}-#{key}" end if mail[header.to_sym] - Rails.logger.info "header #{header} found #{mail[header.to_sym]}" + Rails.logger.info "set_attributes_by_x_headers header #{header} found. Assign #{key}=#{mail[header.to_sym]}" item_object[key] = mail[header.to_sym] end } diff --git a/app/models/channel/filter/database.rb b/app/models/channel/filter/database.rb index 06077abe7..d65db45b2 100644 --- a/app/models/channel/filter/database.rb +++ b/app/models/channel/filter/database.rb @@ -59,6 +59,8 @@ module Channel::Filter::Database match_rule = $2 end + value ||= '' + if regexp == false match_rule_quoted = Regexp.quote(match_rule).gsub(/\\\*/, '.*') return true if value =~ /#{match_rule_quoted}/i diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 9e71fbeed..6b6067682 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -124,7 +124,7 @@ returns UserInfo.current_user_id = admin_user.id # fetch org logo - if admin_user.email + if admin_user.email.present? Service::Image.organization_suggest(admin_user.email) end }