Small code layout improvements.

This commit is contained in:
Martin Edenhofer 2017-10-02 12:31:59 +02:00
parent 1f83f3b358
commit b76be9eebc
5 changed files with 20 additions and 22 deletions

View file

@ -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

View file

@ -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]

View file

@ -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
}

View file

@ -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

View file

@ -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
}