Some new rubocop checks.

This commit is contained in:
Martin Edenhofer 2015-04-27 23:27:51 +02:00
parent 5b98be93e1
commit a2d49cefc5
26 changed files with 1178 additions and 1138 deletions

View file

@ -31,12 +31,11 @@ returns
return data if !self['created_by_id'] && !self['updated_by_id'] return data if !self['created_by_id'] && !self['updated_by_id']
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end
} }
data data
end end

View file

@ -16,7 +16,6 @@ class Locale < ApplicationModel
raise "Can't load locales from #{url}: #{result.error}" if !result.success? raise "Can't load locales from #{url}: #{result.error}" if !result.success?
result.data.each {|locale| result.data.each {|locale|
puts locale.inspect
exists = Locale.where(locale: locale['locale']).first exists = Locale.where(locale: locale['locale']).first
if exists if exists
exists.update(locale.symbolize_keys!) exists.update(locale.symbolize_keys!)

View file

@ -40,12 +40,11 @@ returns
end end
end end
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] next if !self[ item ]
if !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end
} }
data data
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::ActivityStreamLog class Ticket
module ActivityStreamLog
=begin =begin
@ -35,5 +36,5 @@ returns
created_by_id: user_id, created_by_id: user_id,
) )
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Article < ApplicationModel class Ticket
class Article < ApplicationModel
load 'ticket/article/assets.rb' load 'ticket/article/assets.rb'
include Ticket::Article::Assets include Ticket::Article::Assets
load 'ticket/article/history_log.rb' load 'ticket/article/history_log.rb'
@ -47,4 +48,5 @@ class Ticket::Article < ApplicationModel
validates :name, presence: true validates :name, presence: true
latest_change_support latest_change_support
end end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Article::ActivityStreamLog class Ticket
class Article
module ActivityStreamLog
=begin =begin
@ -36,5 +38,6 @@ returns
created_by_id: user_id, created_by_id: user_id,
) )
end end
end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Article::Assets class Ticket
class Article
module Assets
=begin =begin
@ -42,14 +44,14 @@ returns
end end
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end
} }
data data
end end
end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Article::HistoryLog class Ticket
class Article
module HistoryLog
=begin =begin
@ -27,5 +29,6 @@ returns
data[:created_by_id] = user_id data[:created_by_id] = user_id
History.add(data) History.add(data)
end end
end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Assets class Ticket
module Assets
=begin =begin
@ -30,14 +31,13 @@ returns
data[ Ticket.to_app_model ][ self.id ] = self.attributes_with_associations data[ Ticket.to_app_model ][ self.id ] = self.attributes_with_associations
end end
['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item| ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item|
if self[ item ] next if !self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end
} }
data data
end end
end
end end

View file

@ -1,4 +1,6 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Counter < ApplicationModel class Ticket
class Counter < ApplicationModel
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Escalation class Ticket
module Escalation
=begin =begin
@ -259,10 +260,10 @@ returns
diff = escalation_time_diff( last_state_change, history_item['created_at'], sla_selected ) diff = escalation_time_diff( last_state_change, history_item['created_at'], sla_selected )
if counted if counted
# puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}" # puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
total_time_without_pending = total_time_without_pending + diff total_time_without_pending = total_time_without_pending + diff
else else
# puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}" # puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
end end
total_time = total_time + diff total_time = total_time + diff
@ -280,7 +281,7 @@ returns
# if last state isnt pending, count rest # if last state isnt pending, count rest
if !last_state_is_pending && last_state_change && last_state_change < end_time if !last_state_is_pending && last_state_change && last_state_change < end_time
diff = escalation_time_diff( last_state_change, end_time, sla_selected ) diff = escalation_time_diff( last_state_change, end_time, sla_selected )
# puts "Diff count last state was not pending #{diff.to_s} - #{last_state_change} - #{end_time}" # puts "Diff count last state was not pending #{diff.to_s} - #{last_state_change} - #{end_time}"
total_time_without_pending = total_time_without_pending + diff total_time_without_pending = total_time_without_pending + diff
total_time = total_time + diff total_time = total_time + diff
end end
@ -288,7 +289,7 @@ returns
# if we have not had any state change # if we have not had any state change
if !last_state_change if !last_state_change
diff = escalation_time_diff( start_time, end_time, sla_selected ) diff = escalation_time_diff( start_time, end_time, sla_selected )
# puts 'Diff state has not changed ' + diff.to_s # puts 'Diff state has not changed ' + diff.to_s
total_time_without_pending = total_time_without_pending + diff total_time_without_pending = total_time_without_pending + diff
total_time = total_time + diff total_time = total_time + diff
end end
@ -320,4 +321,5 @@ returns
return check_time if escalation_time > check_time return check_time if escalation_time > check_time
return escalation_time return escalation_time
end end
end
end end

View file

@ -1,4 +1,6 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Flag < ApplicationModel class Ticket
class Flag < ApplicationModel
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::HistoryLog class Ticket
module HistoryLog
=begin =begin
@ -77,5 +78,5 @@ returns
assets: assets, assets: assets,
} }
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Number class Ticket
class Number
include ApplicationLib include ApplicationLib
=begin =begin
@ -55,4 +56,5 @@ returns
end end
adapter adapter
end end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Number::Date class Ticket
class Number
module Date
extend self extend self
def generate def generate
@ -8,7 +10,7 @@ module Ticket::Number::Date
# get config # get config
config = Setting.get('ticket_number_date') config = Setting.get('ticket_number_date')
t = Time.now t = Time.zone.now
date = t.strftime('%Y-%m-%d') date = t.strftime('%Y-%m-%d')
# read counter # read counter
@ -64,6 +66,7 @@ module Ticket::Number::Date
end end
number number
end end
def check(string) def check(string)
# get config # get config
@ -73,11 +76,13 @@ module Ticket::Number::Date
ticket = nil ticket = nil
# probe format # probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i then if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i
ticket = Ticket.where( number: $1 ).first ticket = Ticket.where( number: $1 ).first
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i then elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i
ticket = Ticket.where( number: $1 ).first ticket = Ticket.where( number: $1 ).first
end end
ticket ticket
end end
end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Number::Increment class Ticket
class Number
module Increment
extend self extend self
def generate def generate
@ -77,11 +79,13 @@ module Ticket::Number::Increment
ticket = nil ticket = nil
# probe format # probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i then if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i
ticket = Ticket.where( number: $1 ).first ticket = Ticket.where( number: $1 ).first
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i then elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i
ticket = Ticket.where( number: $1 ).first ticket = Ticket.where( number: $1 ).first
end end
ticket ticket
end end
end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Overviews class Ticket
module Overviews
=begin =begin
@ -189,6 +190,7 @@ returns
end end
private private
def self._condition(condition) def self._condition(condition)
sql = '' sql = ''
bind = [nil] bind = [nil]
@ -247,4 +249,5 @@ returns
bind[0] = sql bind[0] = sql
bind bind
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Permission class Ticket
module Permission
=begin =begin
@ -43,5 +44,5 @@ returns
} }
false false
end end
end
end end

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Priority < ApplicationModel class Ticket
class Priority < ApplicationModel
self.table_name = 'ticket_priorities' self.table_name = 'ticket_priorities'
validates :name, presence: true validates :name, presence: true
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::ScreenOptions class Ticket
module ScreenOptions
=begin =begin
@ -173,5 +174,5 @@ returns
assets: assets, assets: assets,
} }
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Search class Ticket
module Search
=begin =begin
@ -63,9 +64,9 @@ returns
query_extention['bool']['must'] = [] query_extention['bool']['must'] = []
if current_user.is_role('Agent') if current_user.is_role('Agent')
groups = Group.joins(:users). groups = Group.joins(:users)
where( 'groups_users.user_id = ?', current_user.id ). .where( 'groups_users.user_id = ?', current_user.id )
where( 'groups.active = ?', true ) .where( 'groups.active = ?', true )
group_condition = [] group_condition = []
groups.each {|group| groups.each {|group|
group_condition.push group.name group_condition.push group.name
@ -113,18 +114,18 @@ returns
# - stip out * we already search for *query* - # - stip out * we already search for *query* -
if query if query
query.gsub! '*', '' query.gsub! '*', ''
tickets_all = Ticket.select('DISTINCT(tickets.id)'). tickets_all = Ticket.select('DISTINCT(tickets.id)')
where(access_condition). .where(access_condition)
where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ). .where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" )
joins(:articles). .joins(:articles)
order('`tickets`.`created_at` DESC'). .order('`tickets`.`created_at` DESC')
limit(limit) .limit(limit)
else else
tickets_all = Ticket.select('DISTINCT(tickets.id)'). tickets_all = Ticket.select('DISTINCT(tickets.id)')
where(access_condition). .where(access_condition)
where(params[:condition]). .where(params[:condition])
order('`tickets`.`created_at` DESC'). .order('`tickets`.`created_at` DESC')
limit(limit) .limit(limit)
end end
# build result list # build result list
@ -142,5 +143,5 @@ returns
} }
tickets tickets
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::SearchIndex class Ticket
module SearchIndex
=begin =begin
@ -105,5 +106,5 @@ returns
return if !attributes return if !attributes
SearchIndexBackend.add(self.class.to_s, attributes) SearchIndexBackend.add(self.class.to_s, attributes)
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::State < ApplicationModel class Ticket
class State < ApplicationModel
belongs_to :state_type, class_name: 'Ticket::StateType' belongs_to :state_type, class_name: 'Ticket::StateType'
validates :name, presence: true validates :name, presence: true
@ -50,4 +51,5 @@ returns:
return true if ignore_escalation.include?( self.name ) return true if ignore_escalation.include?( self.name )
false false
end end
end
end end

View file

@ -1,7 +1,9 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::StateType < ApplicationModel class Ticket
class StateType < ApplicationModel
has_many :states, class_name: 'Ticket::State' has_many :states, class_name: 'Ticket::State'
validates :name, presence: true validates :name, presence: true
latest_change_support latest_change_support
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Subject class Ticket
module Subject
=begin =begin
@ -75,4 +76,5 @@ returns
subject subject
end end
end
end end

View file

@ -75,12 +75,11 @@ returns
end end
end end
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] next if !self[ item ]
if !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( id: self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end
} }
data data
end end