Corrected with rubocop cop 'Style/Next'.

This commit is contained in:
Thorsten Eckel 2015-05-07 11:04:40 +02:00
parent 7efe34e53b
commit 1ac1cf4184
20 changed files with 360 additions and 322 deletions

View file

@ -218,8 +218,6 @@ Metrics/AbcSize:
Style/RedundantSelf: Style/RedundantSelf:
Enabled: false Enabled: false
Style/Next:
Enabled: false
Style/CommentIndentation: Style/CommentIndentation:
Enabled: false Enabled: false
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:

View file

@ -233,28 +233,28 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
provider_map.each {|provider, settings| provider_map.each {|provider, settings|
domains.each {|domain_to_check| domains.each {|domain_to_check|
if domain_to_check =~ /#{settings[:domain]}/i
# probe inbound next if domain_to_check !~ /#{settings[:domain]}/i
result = email_probe_inbound( settings[:inbound] )
if result[:result] != 'ok'
render json: result
return # rubocop:disable Lint/NonLocalExitFromIterator
end
# probe outbound # probe inbound
result = email_probe_outbound( settings[:outbound], params[:email] ) result = email_probe_inbound( settings[:inbound] )
if result[:result] != 'ok' if result[:result] != 'ok'
render json: result render json: result
return # rubocop:disable Lint/NonLocalExitFromIterator
end
render json: {
result: 'ok',
setting: settings,
}
return # rubocop:disable Lint/NonLocalExitFromIterator return # rubocop:disable Lint/NonLocalExitFromIterator
end end
# probe outbound
result = email_probe_outbound( settings[:outbound], params[:email] )
if result[:result] != 'ok'
render json: result
return # rubocop:disable Lint/NonLocalExitFromIterator
end
render json: {
result: 'ok',
setting: settings,
}
return # rubocop:disable Lint/NonLocalExitFromIterator
} }
} }
@ -394,11 +394,12 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
logger.info "INBOUND PROBE: #{config.inspect}" logger.info "INBOUND PROBE: #{config.inspect}"
result = email_probe_inbound( config ) result = email_probe_inbound( config )
logger.info "INBOUND RESULT: #{result.inspect}" logger.info "INBOUND RESULT: #{result.inspect}"
if result[:result] == 'ok'
success = true next if result[:result] != 'ok'
settings[:inbound] = config
break success = true
end settings[:inbound] = config
break
} }
if !success if !success
@ -543,11 +544,12 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
logger.info "OUTBOUND PROBE: #{config.inspect}" logger.info "OUTBOUND PROBE: #{config.inspect}"
result = email_probe_outbound( config, params[:email] ) result = email_probe_outbound( config, params[:email] )
logger.info "OUTBOUND RESULT: #{result.inspect}" logger.info "OUTBOUND RESULT: #{result.inspect}"
if result[:result] == 'ok'
success = true next if result[:result] != 'ok'
settings[:outbound] = config
break success = true
end settings[:outbound] = config
break
} }
if !success if !success
@ -635,66 +637,66 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
return # rubocop:disable Lint/NonLocalExitFromIterator return # rubocop:disable Lint/NonLocalExitFromIterator
end end
if found && found == 'verify ok' next if !found
next if found != 'verify ok'
# remember address # remember address
address = EmailAddress.where( email: params[:meta][:email] ).first address = EmailAddress.where( email: params[:meta][:email] ).first
if !address if !address
address = EmailAddress.first address = EmailAddress.first
end end
if address if address
address.update_attributes( address.update_attributes(
realname: params[:meta][:realname], realname: params[:meta][:realname],
email: params[:meta][:email], email: params[:meta][:email],
active: 1, active: 1,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
else else
EmailAddress.create( EmailAddress.create(
realname: params[:meta][:realname], realname: params[:meta][:realname],
email: params[:meta][:email], email: params[:meta][:email],
active: 1,
updated_by_id: 1,
created_by_id: 1,
)
end
# store mailbox
Channel.create(
area: 'Email::Inbound',
adapter: params[:inbound][:adapter],
options: params[:inbound][:options],
group_id: 1,
active: 1, active: 1,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
# save settings
if params[:outbound][:adapter] =~ /^smtp$/i
smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
smtp.options = params[:outbound][:options]
smtp.active = true
smtp.save!
sendmail = Channel.where( adapter: 'Sendmail' ).first
sendmail.active = false
sendmail.save!
else
sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
sendmail.options = {}
sendmail.active = true
sendmail.save!
smtp = Channel.where( adapter: 'SMTP' ).first
smtp.active = false
smtp.save
end
render json: {
result: 'ok',
}
return # rubocop:disable Lint/NonLocalExitFromIterator
end end
# store mailbox
Channel.create(
area: 'Email::Inbound',
adapter: params[:inbound][:adapter],
options: params[:inbound][:options],
group_id: 1,
active: 1,
updated_by_id: 1,
created_by_id: 1,
)
# save settings
if params[:outbound][:adapter] =~ /^smtp$/i
smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
smtp.options = params[:outbound][:options]
smtp.active = true
smtp.save!
sendmail = Channel.where( adapter: 'Sendmail' ).first
sendmail.active = false
sendmail.save!
else
sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
sendmail.options = {}
sendmail.active = true
sendmail.save!
smtp = Channel.where( adapter: 'SMTP' ).first
smtp.active = false
smtp.save
end
render json: {
result: 'ok',
}
return # rubocop:disable Lint/NonLocalExitFromIterator
} }
# check delivery for 30 sek. # check delivery for 30 sek.
@ -768,14 +770,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
'Recipient address rejected' => true, 'Recipient address rejected' => true,
} }
white_map.each {|key, message| white_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i
result = { next if e.message !~ /#{Regexp.escape(key)}/i
result: 'ok',
settings: params, result = {
notice: e.message, result: 'ok',
} settings: params,
return result notice: e.message,
end }
return result
} }
end end
message_human = '' message_human = ''

View file

@ -107,17 +107,18 @@ returns
# set relations # set relations
self.class.reflect_on_all_associations.map { |assoc| self.class.reflect_on_all_associations.map { |assoc|
real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids'
if params.key?( real_key.to_sym )
list_of_items = params[ real_key.to_sym ] next if !params.key?( real_key.to_sym )
if params[ real_key.to_sym ].class != Array
list_of_items = [ params[ real_key.to_sym ] ] list_of_items = params[ real_key.to_sym ]
end if params[ real_key.to_sym ].class != Array
list = [] list_of_items = [ params[ real_key.to_sym ] ]
list_of_items.each {|item|
list.push( assoc.klass.find(item) )
}
self.send( assoc.name.to_s + '=', list )
end end
list = []
list_of_items.each {|item|
list.push( assoc.klass.find(item) )
}
self.send( assoc.name.to_s + '=', list )
} }
end end

View file

@ -66,35 +66,37 @@ class Channel::EmailParser
# set all headers # set all headers
mail.header.fields.each { |field| mail.header.fields.each { |field|
if field.name
# full line, encode, ready for storage next if !field.name
data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
# if we need to access the lines by objects later again # full line, encode, ready for storage
data[ "raw-#{field.name.downcase}".to_sym ] = field data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
end
# if we need to access the lines by objects later again
data[ "raw-#{field.name.downcase}".to_sym ] = field
} }
# get sender # get sender
from = nil from = nil
['from', 'reply-to', 'return-path'].each { |item| ['from', 'reply-to', 'return-path'].each { |item|
if !from
if mail[ item.to_sym ] next if !mail[ item.to_sym ]
from = mail[ item.to_sym ].value
end from = mail[ item.to_sym ].value
end
break if from
} }
# set x-any-recipient # set x-any-recipient
data['x-any-recipient'.to_sym] = '' data['x-any-recipient'.to_sym] = ''
['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item| ['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item|
if mail[item.to_sym]
if data['x-any-recipient'.to_sym] != '' next if !mail[item.to_sym]
data['x-any-recipient'.to_sym] += ', '
end if data['x-any-recipient'.to_sym] != ''
data['x-any-recipient'.to_sym] += mail[item.to_sym].to_s data['x-any-recipient'.to_sym] += ', '
end end
data['x-any-recipient'.to_sym] += mail[item.to_sym].to_s
} }
# set extra headers # set extra headers
@ -374,16 +376,18 @@ class Channel::EmailParser
# create to and cc user # create to and cc user
['raw-to', 'raw-cc'].each { |item| ['raw-to', 'raw-cc'].each { |item|
if mail[item.to_sym] && mail[item.to_sym].tree
items = mail[item.to_sym].tree next if !mail[item.to_sym]
items.addresses.each {|item| next if !mail[item.to_sym].tree
user_create(
firstname: item.display_name, items = mail[item.to_sym].tree
lastname: '', items.addresses.each {|item|
email: item.address, user_create(
) firstname: item.display_name,
} lastname: '',
end email: item.address,
)
}
} }
# set current user # set current user
@ -541,18 +545,19 @@ class Channel::EmailParser
if mail[ header.to_sym ] if mail[ header.to_sym ]
Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}" Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}"
item_object.class.reflect_on_all_associations.map { |assoc| item_object.class.reflect_on_all_associations.map { |assoc|
if assoc.name.to_s == key_short
Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[ header.to_sym ]}"
item = assoc.class_name.constantize
if item.respond_to?(:name) next if assoc.name.to_s != key_short
if item.lookup( name: mail[ header.to_sym ] )
item_object[key] = item.lookup( name: mail[ header.to_sym ] ).id Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[ header.to_sym ]}"
end item = assoc.class_name.constantize
elsif item.respond_to?(:login)
if item.lookup( login: mail[ header.to_sym ] ) if item.respond_to?(:name)
item_object[key] = item.lookup( login: mail[ header.to_sym ] ).id if item.lookup( name: mail[ header.to_sym ] )
end item_object[key] = item.lookup( name: mail[ header.to_sym ] ).id
end
elsif item.respond_to?(:login)
if item.lookup( login: mail[ header.to_sym ] )
item_object[key] = item.lookup( login: mail[ header.to_sym ] ).id
end end
end end
} }

View file

@ -10,9 +10,9 @@ module Channel::Filter::Database
filters.each {|filter| filters.each {|filter|
Rails.logger.info " proccess filter #{filter.name} ..." Rails.logger.info " proccess filter #{filter.name} ..."
match = true match = true
loop = false looped = false
filter[:match].each {|key, value| filter[:match].each {|key, value|
loop = true looped = true
begin begin
scan = [] scan = []
if mail if mail
@ -31,12 +31,14 @@ module Channel::Filter::Database
Rails.logger.error e.inspect Rails.logger.error e.inspect
end end
} }
if loop && match
filter[:perform].each {|key, value| next if !looped
Rails.logger.info " perform '#{ key.downcase }' = '#{value}'" next if !match
mail[ key.downcase.to_sym ] = value
} filter[:perform].each {|key, value|
end Rails.logger.info " perform '#{ key.downcase }' = '#{value}'"
mail[ key.downcase.to_sym ] = value
}
} }
end end

View file

@ -37,12 +37,14 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
# add history record # add history record
recipient_list = '' recipient_list = ''
[:to, :cc].each { |key| [:to, :cc].each { |key|
if record[key] && record[key] != ''
if recipient_list != '' next if !record[key]
recipient_list += ',' next if record[key] == ''
end
recipient_list += record[key] if recipient_list != ''
recipient_list += ','
end end
recipient_list += record[key]
} }
return if recipient_list == '' return if recipient_list == ''

View file

@ -313,14 +313,15 @@ class Package < ApplicationModel
def self.reload_classes def self.reload_classes
%w(app lib).each {|dir| %w(app lib).each {|dir|
Dir.glob( Rails.root.join( dir + '/**/*') ).each {|entry| Dir.glob( Rails.root.join( dir + '/**/*') ).each {|entry|
if entry =~ /\.rb$/
begin next if entry !~ /\.rb$/
load entry
rescue => e begin
logger.error "TRIED TO RELOAD '#{entry}'" load entry
logger.error 'ERROR: ' + e.inspect rescue => e
logger.error 'Traceback: ' + e.backtrace.inspect logger.error "TRIED TO RELOAD '#{entry}'"
end logger.error 'ERROR: ' + e.inspect
logger.error 'Traceback: ' + e.backtrace.inspect
end end
} }
} }
@ -396,11 +397,11 @@ class Package < ApplicationModel
(1..position).each {|count| (1..position).each {|count|
tmp_path = tmp_path + '/' + directories[count].to_s tmp_path = tmp_path + '/' + directories[count].to_s
} }
if tmp_path != ''
if !File.exist?(tmp_path) next if tmp_path == ''
Dir.mkdir( tmp_path, 0755) next if File.exist?(tmp_path)
end
end Dir.mkdir(tmp_path, 0755)
} }
# install file # install file

View file

@ -46,12 +46,13 @@ class Store
content = item.content content = item.content
sha = Digest::SHA256.hexdigest( content ) sha = Digest::SHA256.hexdigest( content )
logger.info "CHECK: Store::File.find(#{item.id}) " logger.info "CHECK: Store::File.find(#{item.id}) "
if sha != item.sha
success = false next if sha == item.sha
logger.error "DIFF: sha diff of Store::File.find(#{item.id}) "
if fix_it success = false
item.update_attribute( :sha, sha ) logger.error "DIFF: sha diff of Store::File.find(#{item.id}) "
end if fix_it
item.update_attribute( :sha, sha )
end end
} }
success success

View file

@ -189,15 +189,16 @@ returns
[ 'tickets.group_id', 'group_id' ] [ 'tickets.group_id', 'group_id' ]
] ]
map.each {|item| map.each {|item|
if sla.condition[ item[0] ]
if sla.condition[ item[0] ].class == String next if !sla.condition[ item[0] ]
sla.condition[ item[0] ] = [ sla.condition[ item[0] ] ]
end if sla.condition[ item[0] ].class == String
if sla.condition[ item[0] ].include?( self[ item[1] ].to_s ) sla.condition[ item[0] ] = [ sla.condition[ item[0] ] ]
hit = true end
else if sla.condition[ item[0] ].include?( self[ item[1] ].to_s )
hit = false hit = true
end else
hit = false
end end
} }
if hit if hit

View file

@ -73,12 +73,17 @@ returns
# replace e.g. 'current_user.id' with current_user.id # replace e.g. 'current_user.id' with current_user.id
overview.condition.each { |item, value| overview.condition.each { |item, value|
if value && value.class.to_s == 'String'
parts = value.split( '.', 2 ) next if !value
if parts[0] && parts[1] && parts[0] == 'current_user' next if value.class.to_s != 'String'
overview.condition[item] = data[:current_user][parts[1].to_sym]
end parts = value.split( '.', 2 )
end
next if !parts[0]
next if !parts[1]
next if parts[0] != 'current_user'
overview.condition[item] = data[:current_user][parts[1].to_sym]
} }
} }

View file

@ -64,12 +64,13 @@ returns
end end
state_types.each {|type| state_types.each {|type|
state_type = Ticket::StateType.where( name: type ).first state_type = Ticket::StateType.where( name: type ).first
if state_type
state_type.states.each {|state| next if !state_type
assets = state.assets(assets)
state_ids.push state.id state_type.states.each {|state|
} assets = state.assets(assets)
end state_ids.push state.id
}
} }
filter[:state_id] = state_ids filter[:state_id] = state_ids

View file

@ -83,21 +83,22 @@ returns
end end
# check file size # check file size
if attachment.content && attachment.content.size / 1024 <= attachment_max_size_in_mb * 1024 next if !attachment.content
next if attachment.content.size / 1024 > attachment_max_size_in_mb * 1024
# check ignored files # check ignored files
if attachment.filename next if !attachment.filename
filename_extention = attachment.filename.downcase
filename_extention.gsub!(/^.*(\..+?)$/, '\\1') filename_extention = attachment.filename.downcase
if !attachments_ignore.include?( filename_extention.downcase ) filename_extention.gsub!(/^.*(\..+?)$/, '\\1')
data = {
'_name' => attachment.filename, next if attachments_ignore.include?( filename_extention.downcase )
'_content' => Base64.encode64( attachment.content )
} data = {
article_attributes['attachments'].push data '_name' => attachment.filename,
end '_content' => Base64.encode64( attachment.content )
end }
end article_attributes['attachments'].push data
} }
attributes['articles'].push article_attributes attributes['articles'].push article_attributes
} }

View file

@ -45,16 +45,15 @@ returns
user_auth = backend.check( username, password, config_item, user ) user_auth = backend.check( username, password, config_item, user )
# auth ok # auth not ok
if user_auth next if !user_auth
Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user_auth.login} ok." Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user_auth.login} ok."
# remember last login date # remember last login date
user_auth.update_last_login user_auth.update_last_login
return user_auth return user_auth
end
} }
nil nil
end end

View file

@ -522,18 +522,20 @@ module Import::OTRS
created_by_id: history['CreateBy'] created_by_id: history['CreateBy']
) )
end end
if history['ArticleID'] && history['ArticleID'] != 0
History.add( next if !history['ArticleID']
id: history['HistoryID'], next if history['ArticleID'] == 0
o_id: history['ArticleID'],
history_type: 'created', History.add(
history_object: 'Ticket::Article', id: history['HistoryID'],
related_o_id: history['TicketID'], o_id: history['ArticleID'],
related_history_object: 'Ticket', history_type: 'created',
created_at: history['CreateTime'], history_object: 'Ticket::Article',
created_by_id: history['CreateBy'] related_o_id: history['TicketID'],
) related_history_object: 'Ticket',
end created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
} }
end end
} }

View file

@ -747,18 +747,20 @@ module Import::OTRS2
created_by_id: history['CreateBy'] created_by_id: history['CreateBy']
) )
end end
if history['ArticleID'] && history['ArticleID'] != 0
History.add( next if !history['ArticleID']
id: history['HistoryID'], next if history['ArticleID'] == 0
o_id: history['ArticleID'],
history_type: 'created', History.add(
history_object: 'Ticket::Article', id: history['HistoryID'],
related_o_id: history['TicketID'], o_id: history['ArticleID'],
related_history_object: 'Ticket', history_type: 'created',
created_at: history['CreateTime'], history_object: 'Ticket::Article',
created_by_id: history['CreateBy'] related_o_id: history['TicketID'],
) related_history_object: 'Ticket',
end created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
} }
} }
end end
@ -974,11 +976,12 @@ module Import::OTRS2
# lookup by groups # lookup by groups
user['GroupIDs'].each {|group_id, permissions| user['GroupIDs'].each {|group_id, permissions|
queues.each {|queue_lookup| queues.each {|queue_lookup|
if queue_lookup['GroupID'] == group_id
if permissions && permissions.include?('rw') next if queue_lookup['GroupID'] != group_id
queue_ids.push queue_lookup['QueueID'] next if !permissions
end next if !permissions.include?('rw')
end
queue_ids.push queue_lookup['QueueID']
} }
} }
@ -996,14 +999,18 @@ module Import::OTRS2
role_ids = [] role_ids = []
user['GroupIDs'].each {|group_id, permissions| user['GroupIDs'].each {|group_id, permissions|
groups.each {|group_lookup| groups.each {|group_lookup|
if group_id == group_lookup['ID']
if group_lookup['Name'] == 'admin' && permissions && permissions.include?('rw') next if group_id != group_lookup['ID']
roles.push 'Admin' next if permissions
end
if group_lookup['Name'] =~ /^(stats|report)/ && permissions && ( permissions.include?('ro') || permissions.include?('rw') ) if group_lookup['Name'] == 'admin' && permissions.include?('rw')
roles.push 'Report' roles.push 'Admin'
end
end end
next if group_lookup['Name'] !~ /^(stats|report)/
next if !( permissions.include?('ro') || permissions.include?('rw') )
roles.push 'Report'
} }
} }
roles.each {|role| roles.each {|role|

View file

@ -63,11 +63,12 @@ module NotificationFactory
object_refs = object_refs.send( method.to_sym ) object_refs = object_refs.send( method.to_sym )
# add body quote # add body quote
if object_name == 'article' && method == 'body' next if object_name != 'article'
if data[:objects][:article].content_type == 'text/html' next if method != 'body'
object_refs = object_refs.html2text.chomp
end next if data[:objects][:article].content_type != 'text/html'
end
object_refs = object_refs.html2text.chomp
} }
if !value if !value
placeholder = object_refs placeholder = object_refs

View file

@ -470,14 +470,16 @@ returns
# spool to recipient list # spool to recipient list
if message_parsed['recipient'] && message_parsed['recipient']['user_id'] if message_parsed['recipient'] && message_parsed['recipient']['user_id']
message_parsed['recipient']['user_id'].each { |user_id| message_parsed['recipient']['user_id'].each { |user_id|
if current_user_id == user_id
item = { next if current_user_id != user_id
type: 'direct',
message: message_parsed, item = {
} type: 'direct',
data.push item message: message_parsed,
end }
data.push item
} }
# spool to every client # spool to every client
@ -521,16 +523,16 @@ returns
next if !user next if !user
# start client thread # start client thread
if !@@client_threads[client_id] next if @@client_threads[client_id]
@@client_threads[client_id] = true
@@client_threads[client_id] = Thread.new { @@client_threads[client_id] = true
thread_client(client_id) @@client_threads[client_id] = Thread.new {
@@client_threads[client_id] = nil thread_client(client_id)
Rails.logger.debug "close client (#{client_id}) thread" @@client_threads[client_id] = nil
ActiveRecord::Base.connection.close Rails.logger.debug "close client (#{client_id}) thread"
} ActiveRecord::Base.connection.close
sleep 0.5 }
end sleep 0.5
} }
# system settings # system settings

View file

@ -56,16 +56,15 @@ returns
user_auth = backend.check( params, config_item ) user_auth = backend.check( params, config_item )
# auth ok # auth not ok
if user_auth next if !user_auth
Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user.login} ok." Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user.login} ok."
# remember last login date # remember last login date
user_auth.update_last_login user_auth.update_last_login
return user_auth return user_auth
end
} }
nil nil
end end

View file

@ -35,17 +35,21 @@ put working hours matrix and timezone in function, returns UTC working hours mat
working_hours = {} working_hours = {}
[:Mon, :Tue, :Wed, :Thu, :Fri, :Sat, :Sun].each {|day| [:Mon, :Tue, :Wed, :Thu, :Fri, :Sat, :Sun].each {|day|
working_hours[day] = [] working_hours[day] = []
if config[day.to_s] == true || config[day.to_s] == day.to_s
config_ok = true next if !config[day.to_s]
(0..23).each {|hour| if config[day.to_s] != true && config[day.to_s] != day.to_s
time = Time.parse("1977-10-27 #{hour}:00:00") next
if time >= beginning_of_workday && time <= end_of_workday
working_hours[day].push true
else
working_hours[day].push nil
end
}
end end
config_ok = true
(0..23).each {|hour|
time = Time.parse("1977-10-27 #{hour}:00:00")
if time >= beginning_of_workday && time <= end_of_workday
working_hours[day].push true
else
working_hours[day].push nil
end
}
} }
if !config_ok if !config_ok
@ -67,23 +71,24 @@ put working hours matrix and timezone in function, returns UTC working hours mat
} }
(1..hours_to_shift).each {|count| (1..hours_to_shift).each {|count|
working_hours.each {|day, value| working_hours.each {|day, value|
if working_hours[day]
to_move = working_hours[day].shift next if !working_hours[day]
if day == :Mon
move_items[:Tue].push to_move to_move = working_hours[day].shift
elsif day == :Tue if day == :Mon
move_items[:Wed].push to_move move_items[:Tue].push to_move
elsif day == :Wed elsif day == :Tue
move_items[:Thu].push to_move move_items[:Wed].push to_move
elsif day == :Thu elsif day == :Wed
move_items[:Fri].push to_move move_items[:Thu].push to_move
elsif day == :Fri elsif day == :Thu
move_items[:Sat].push to_move move_items[:Fri].push to_move
elsif day == :Sat elsif day == :Fri
move_items[:Sun].push to_move move_items[:Sat].push to_move
elsif day == :Sun elsif day == :Sat
move_items[:Mon].push to_move move_items[:Sun].push to_move
end elsif day == :Sun
move_items[:Mon].push to_move
end end
} }
} }

View file

@ -198,13 +198,14 @@ EventMachine.run {
log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'" log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'"
else else
data['recipient']['user_id'].each { |user_id| data['recipient']['user_id'].each { |user_id|
if local_client[:user]['id'].to_i == user_id.to_i
log 'notice', "send broadcast from (#{client_id}) to (user_id=#{user_id})", local_client_id next if local_client[:user]['id'].to_i != user_id.to_i
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
@clients[ local_client_id ][:websocket].send( "[#{msg}]" ) log 'notice', "send broadcast from (#{client_id}) to (user_id=#{user_id})", local_client_id
else if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
Sessions.send( local_client_id, data ) @clients[ local_client_id ][:websocket].send( "[#{msg}]" )
end else
Sessions.send( local_client_id, data )
end end
} }
end end
@ -296,19 +297,20 @@ EventMachine.run {
# close unused web socket sessions # close unused web socket sessions
@clients.each { |client_id, client| @clients.each { |client_id, client|
if ( client[:last_ping] + idle_time_in_sec ) < Time.now
log 'notice', 'closing idle websocket connection', client_id
# remember to not use this connection anymore next if ( client[:last_ping] + idle_time_in_sec ) >= Time.now
client[:disconnect] = true
# try to close regular log 'notice', 'closing idle websocket connection', client_id
client[:websocket].close_websocket
# delete session from client list # remember to not use this connection anymore
sleep 0.3 client[:disconnect] = true
@clients.delete(client_id)
end # try to close regular
client[:websocket].close_websocket
# delete session from client list
sleep 0.3
@clients.delete(client_id)
} }
# close unused ajax long polling sessions # close unused ajax long polling sessions