Small code layout cleanup.
This commit is contained in:
parent
2c39eb47de
commit
036a2f6274
|
@ -58,7 +58,7 @@ class Authorization < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
# save/update avatar
|
# save/update avatar
|
||||||
if hash['info']['image']
|
if hash['info'].present? && hash['info']['image'].present?
|
||||||
avatar = Avatar.add(
|
avatar = Avatar.add(
|
||||||
object: 'User',
|
object: 'User',
|
||||||
o_id: user.id,
|
o_id: user.id,
|
||||||
|
|
|
@ -104,6 +104,7 @@ add avatar by url
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch image based on http url
|
# fetch image based on http url
|
||||||
|
if data[:url].present?
|
||||||
if data[:url] =~ /^http/
|
if data[:url] =~ /^http/
|
||||||
|
|
||||||
# check if source ist already updated within last 2 minutes
|
# check if source ist already updated within last 2 minutes
|
||||||
|
@ -144,14 +145,12 @@ add avatar by url
|
||||||
end
|
end
|
||||||
data[:resize][:content] = response.body
|
data[:resize][:content] = response.body
|
||||||
data[:resize][:mime_type] = mime_type
|
data[:resize][:mime_type] = mime_type
|
||||||
if !data[:full]
|
data[:full] ||= {}
|
||||||
data[:full] = {}
|
|
||||||
end
|
|
||||||
data[:full][:content] = response.body
|
data[:full][:content] = response.body
|
||||||
data[:full][:mime_type] = mime_type
|
data[:full][:mime_type] = mime_type
|
||||||
|
|
||||||
# try zammad backend to find image based on email
|
# try zammad backend to find image based on email
|
||||||
elsif data[:url].present? && data[:url] =~ /@/
|
elsif data[:url] =~ /@/
|
||||||
|
|
||||||
# check if source ist already updated within last 3 minutes
|
# check if source ist already updated within last 3 minutes
|
||||||
if avatar_already_exists && avatar_already_exists.source_url == data[:url]
|
if avatar_already_exists && avatar_already_exists.source_url == data[:url]
|
||||||
|
@ -161,26 +160,25 @@ add avatar by url
|
||||||
# fetch image
|
# fetch image
|
||||||
image = Service::Image.user(data[:url])
|
image = Service::Image.user(data[:url])
|
||||||
return if !image
|
return if !image
|
||||||
if !data[:resize]
|
data[:resize] ||= {}
|
||||||
data[:resize] = {}
|
|
||||||
end
|
|
||||||
data[:resize] = image
|
data[:resize] = image
|
||||||
if !data[:full]
|
data[:full] ||= {}
|
||||||
data[:full] = {}
|
|
||||||
end
|
|
||||||
data[:full] = image
|
data[:full] = image
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# check if avatar need to be updated
|
# check if avatar need to be updated
|
||||||
|
if data[:resize].present? && data[:resize][:content].present?
|
||||||
record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content])
|
record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content])
|
||||||
if avatar_already_exists && avatar_already_exists.store_hash == record[:store_hash]
|
if avatar_already_exists && avatar_already_exists.store_hash == record[:store_hash]
|
||||||
avatar_already_exists.touch
|
avatar_already_exists.touch
|
||||||
return avatar_already_exists
|
return avatar_already_exists
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# store images
|
# store images
|
||||||
object_name = "Avatar::#{data[:object]}"
|
object_name = "Avatar::#{data[:object]}"
|
||||||
if data[:full]
|
if data[:full].present?
|
||||||
store_full = Store.add(
|
store_full = Store.add(
|
||||||
object: "#{object_name}::Full",
|
object: "#{object_name}::Full",
|
||||||
o_id: data[:o_id],
|
o_id: data[:o_id],
|
||||||
|
@ -194,7 +192,7 @@ add avatar by url
|
||||||
record[:store_full_id] = store_full.id
|
record[:store_full_id] = store_full.id
|
||||||
record[:store_hash] = Digest::MD5.hexdigest(data[:full][:content])
|
record[:store_hash] = Digest::MD5.hexdigest(data[:full][:content])
|
||||||
end
|
end
|
||||||
if data[:resize]
|
if data[:resize].present?
|
||||||
store_resize = Store.add(
|
store_resize = Store.add(
|
||||||
object: "#{object_name}::Resize",
|
object: "#{object_name}::Resize",
|
||||||
o_id: data[:o_id],
|
o_id: data[:o_id],
|
||||||
|
@ -206,9 +204,11 @@ add avatar by url
|
||||||
created_by_id: data[:created_by_id],
|
created_by_id: data[:created_by_id],
|
||||||
)
|
)
|
||||||
record[:store_resize_id] = store_resize.id
|
record[:store_resize_id] = store_resize.id
|
||||||
record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content] )
|
record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return if record[:store_resize_id].blank? || record[:store_hash].blank?
|
||||||
|
|
||||||
# update existing
|
# update existing
|
||||||
if avatar_already_exists
|
if avatar_already_exists
|
||||||
avatar_already_exists.update!(record)
|
avatar_already_exists.update!(record)
|
||||||
|
|
|
@ -38,7 +38,7 @@ set config setting
|
||||||
end
|
end
|
||||||
setting.state_current = { value: value }
|
setting.state_current = { value: value }
|
||||||
setting.save!
|
setting.save!
|
||||||
logger.info "Setting.set(#{name}, #{value.inspect})"
|
logger.info "Setting.set('#{name}', #{value.inspect})"
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -72,7 +72,7 @@ reset config setting to default
|
||||||
return true if !force && setting.state_current == setting.state_initial
|
return true if !force && setting.state_current == setting.state_initial
|
||||||
setting.state_current = setting.state_initial
|
setting.state_current = setting.state_initial
|
||||||
setting.save!
|
setting.save!
|
||||||
logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})"
|
logger.info "Setting.reset('#{name}', #{setting.state_current.inspect})"
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
Loading…
Reference in a new issue