Corrected with rubocop cop 'Style/GuardClause'.

This commit is contained in:
Thorsten Eckel 2015-04-30 17:25:04 +02:00
parent b47ffdd925
commit 2a036be4af
23 changed files with 310 additions and 294 deletions

View file

@ -35,15 +35,17 @@ class ApplicationController < ActionController::Base
# text/plain. # text/plain.
def cors_preflight_check def cors_preflight_check
if request.method == 'OPTIONS'
return if request.method != 'OPTIONS'
headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS' headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Accept-Language' headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Accept-Language'
headers['Access-Control-Max-Age'] = '1728000' headers['Access-Control-Max-Age'] = '1728000'
headers['Access-Control-Allow-Credentials'] = 'true' headers['Access-Control-Allow-Credentials'] = 'true'
render text: '', content_type: 'text/plain' render text: '', content_type: 'text/plain'
return false
end false
end end
private private
@ -90,10 +92,10 @@ class ApplicationController < ActionController::Base
end end
# fill user agent # fill user agent
if !session[:user_agent] return if session[:user_agent]
session[:user_agent] = request.env['HTTP_USER_AGENT'] session[:user_agent] = request.env['HTTP_USER_AGENT']
end end
end
def authentication_check_only def authentication_check_only

View file

@ -159,7 +159,8 @@ class TicketArticlesController < ApplicationController
) )
# find file # find file
if list return if !list
file = Store.find(list.first) file = Store.find(list.first)
send_data( send_data(
file.content, file.content,
@ -168,6 +169,5 @@ class TicketArticlesController < ApplicationController
disposition: 'inline' disposition: 'inline'
) )
end end
end
end end

View file

@ -531,11 +531,11 @@ class TicketsController < ApplicationController
end end
# remove attachments from upload cache # remove attachments from upload cache
if form_id return if !form_id
Store.remove( Store.remove(
object: 'UploadCache', object: 'UploadCache',
o_id: form_id, o_id: form_id,
) )
end end
end
end end

View file

@ -44,12 +44,12 @@ class ApplicationModel < ActiveRecord::Base
@@import_class_list = ['Ticket', 'Ticket::Article', 'History', 'Ticket::State', 'Ticket::StateType', 'Ticket::Priority', 'Group', 'User', 'Role' ] @@import_class_list = ['Ticket', 'Ticket::Article', 'History', 'Ticket::State', 'Ticket::StateType', 'Ticket::Priority', 'Group', 'User', 'Role' ]
def check_attributes_protected def check_attributes_protected
if !Setting.get('system_init_done') || ( Setting.get('import_mode') && @@import_class_list.include?( self.class.to_s ) )
# do noting, use id as it is # do noting, use id as it is
else return if !Setting.get('system_init_done') || ( Setting.get('import_mode') && @@import_class_list.include?( self.class.to_s ) )
self[:id] = nil self[:id] = nil
end end
end
=begin =begin
@ -197,15 +197,16 @@ returns
self.updated_by_id = UserInfo.current_user_id self.updated_by_id = UserInfo.current_user_id
end end
end end
if self.class.column_names.include? 'created_by_id'
if UserInfo.current_user_id return if !self.class.column_names.include? 'created_by_id'
return if !UserInfo.current_user_id
if self.created_by_id && self.created_by_id != UserInfo.current_user_id if self.created_by_id && self.created_by_id != UserInfo.current_user_id
logger.info "NOTICE create - self.created_by_id is different: #{self.created_by_id.to_s}/#{UserInfo.current_user_id.to_s}" logger.info "NOTICE create - self.created_by_id is different: #{self.created_by_id.to_s}/#{UserInfo.current_user_id.to_s}"
end end
self.created_by_id = UserInfo.current_user_id self.created_by_id = UserInfo.current_user_id
end end
end
end
=begin =begin
@ -223,10 +224,10 @@ returns
def fill_up_user_update def fill_up_user_update
return if !self.class.column_names.include? 'updated_by_id' return if !self.class.column_names.include? 'updated_by_id'
if UserInfo.current_user_id return if !UserInfo.current_user_id
self.updated_by_id = UserInfo.current_user_id self.updated_by_id = UserInfo.current_user_id
end end
end
def cache_update(o) def cache_update(o)
# puts 'u ' + self.class.to_s # puts 'u ' + self.class.to_s
@ -268,13 +269,14 @@ returns
key = self.class.to_s + ':f:' + self.name.to_s key = self.class.to_s + ':f:' + self.name.to_s
Cache.delete( key.to_s ) Cache.delete( key.to_s )
end end
if self[:login]
return if !self[:login]
key = self.class.to_s + '::' + self.login.to_s key = self.class.to_s + '::' + self.login.to_s
Cache.delete( key.to_s ) Cache.delete( key.to_s )
key = self.class.to_s + ':f:' + self.login.to_s key = self.class.to_s + ':f:' + self.login.to_s
Cache.delete( key.to_s ) Cache.delete( key.to_s )
end end
end
def self.cache_set(data_id, data, full = false) def self.cache_set(data_id, data, full = false)
if !full if !full
@ -962,10 +964,10 @@ store attachments for this object
self.attachments_buffer = attachments self.attachments_buffer = attachments
# update if object already exists # update if object already exists
if self.id && self.id != 0 return if !( self.id && self.id != 0 )
attachments_buffer_check attachments_buffer_check
end end
end
=begin =begin

View file

@ -91,8 +91,9 @@ class Channel::IMAP < Channel::EmailParser
end end
def disconnect def disconnect
if @imap
return if !@imap
@imap.disconnect() @imap.disconnect()
end end
end
end end

View file

@ -72,9 +72,10 @@ class Channel::POP3 < Channel::EmailParser
end end
def disconnect def disconnect
if @pop
return if !@pop
@pop.finish @pop.finish
end end
end
end end

View file

@ -13,10 +13,11 @@ class Channel::TWITTER2
end end
def disconnect def disconnect
if @client
return if !@client
@client = nil @client = nil
end end
end
def fetch (channel) def fetch (channel)
@ -288,7 +289,8 @@ class Channel::TWITTER2
return dm return dm
end end
if attr[:type] == 'twitter status' return if attr[:type] != 'twitter status'
message = client.update( message = client.update(
attr[:body].to_s, attr[:body].to_s,
{ {
@ -298,6 +300,4 @@ class Channel::TWITTER2
# puts message.inspect # puts message.inspect
return message return message
end end
end
end end

View file

@ -15,11 +15,12 @@ class Observer::Session < ActiveRecord::Observer
def check(record) def check(record)
return if !record.data return if !record.data
return if record[:request_type] return if record[:request_type]
# remember request type # remember request type
if record.data['request_type'] return if !record.data['request_type']
record[:request_type] = record.data['request_type'] record[:request_type] = record.data['request_type']
record.data.delete('request_type') record.data.delete('request_type')
end end
end
end end

View file

@ -44,7 +44,9 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
recipient_list += record[key] recipient_list += record[key]
end end
} }
if recipient_list != ''
return if recipient_list == ''
History.add( History.add(
o_id: record.id, o_id: record.id,
history_type: 'email', history_type: 'email',
@ -56,5 +58,4 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
created_by_id: record.created_by_id, created_by_id: record.created_by_id,
) )
end end
end
end end

View file

@ -14,9 +14,9 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
return if sender['name'] == 'Customer' return if sender['name'] == 'Customer'
# set from if not given # set from if not given
if !record.from return if record.from
user = User.find( record.created_by_id ) user = User.find( record.created_by_id )
record.from = "#{user.firstname} #{user.lastname}" record.from = "#{user.firstname} #{user.lastname}"
end end
end
end end

View file

@ -31,7 +31,7 @@ class Observer::Ticket::LastContact < ActiveRecord::Observer
end end
# if sender is not agent # if sender is not agent
if sender.name == 'Agent' return if sender.name != 'Agent'
# set last_contact_agent # set last_contact_agent
record.ticket.last_contact_agent = record.created_at record.ticket.last_contact_agent = record.created_at
@ -42,5 +42,4 @@ class Observer::Ticket::LastContact < ActiveRecord::Observer
# save ticket # save ticket
record.ticket.save record.ticket.save
end end
end
end end

View file

@ -128,7 +128,8 @@ class Observer::Ticket::Notification::BackgroundJob
end end
# add history record # add history record
if recipient_list != '' return if recipient_list == ''
History.add( History.add(
o_id: ticket.id, o_id: ticket.id,
history_type: 'notification', history_type: 'notification',
@ -137,7 +138,6 @@ class Observer::Ticket::Notification::BackgroundJob
created_by_id: ticket.updated_by_id ||  1 created_by_id: ticket.updated_by_id ||  1
) )
end end
end
def human_changes(user, record) def human_changes(user, record)

View file

@ -40,8 +40,8 @@ class Observer::Ticket::RefObjectTouch < ActiveRecord::Observer
end end
# touch new/current organization # touch new/current organization
if record.organization return if !record.organization
record.organization.touch record.organization.touch
end end
end
end end

View file

@ -42,9 +42,10 @@ class Observer::Ticket::UserTicketCounter < ActiveRecord::Observer
need_update = true need_update = true
customer[:preferences][:tickets_closed] = tickets_closed customer[:preferences][:tickets_closed] = tickets_closed
end end
if need_update
return if !need_update
customer.save customer.save
end end
end
end end

View file

@ -58,10 +58,11 @@ class Setting < ApplicationModel
self.state_initial = self.state self.state_initial = self.state
end end
def state_check def state_check
if self.state || self.state == false
if !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) return if !(self.state || self.state == false)
return if !( !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) )
self.state = { value: self.state } self.state = { value: self.state }
end end
end
end
end end

View file

@ -201,22 +201,24 @@ returns
end end
def check_title def check_title
if self.title
return if !self.title
self.title.gsub!(/\s|\t|\r/, ' ') self.title.gsub!(/\s|\t|\r/, ' ')
end end
end
def check_defaults def check_defaults
if !self.owner_id if !self.owner_id
self.owner_id = 1 self.owner_id = 1
end end
if self.customer_id
return if !self.customer_id
customer = User.find( self.customer_id ) customer = User.find( self.customer_id )
if self.organization_id != customer.organization_id return if self.organization_id == customer.organization_id
self.organization_id = customer.organization_id self.organization_id = customer.organization_id
end end
end
end
def reset_pending_time def reset_pending_time
@ -228,10 +230,10 @@ returns
current_state_type = Ticket::StateType.lookup( id: current_state.state_type_id ) current_state_type = Ticket::StateType.lookup( id: current_state.state_type_id )
# in case, set pending_time to nil # in case, set pending_time to nil
if current_state_type.name !~ /^pending/i return if current_state_type.name =~ /^pending/i
self.pending_time = nil self.pending_time = nil
end end
end
def destroy_dependencies def destroy_dependencies

View file

@ -30,10 +30,11 @@ class Ticket::Article < ApplicationModel
private private
def check_subject def check_subject
if self.subject
return if !self.subject
self.subject.gsub!(/\s|\t|\r/, ' ') self.subject.gsub!(/\s|\t|\r/, ' ')
end end
end
class Flag < ApplicationModel class Flag < ApplicationModel
end end

View file

@ -152,11 +152,12 @@ returns
if sla_selected.close_time && self.close_time_in_min if sla_selected.close_time && self.close_time_in_min
self.close_time_diff_in_min = sla_selected.close_time - self.close_time_in_min self.close_time_diff_in_min = sla_selected.close_time - self.close_time_in_min
end end
if self.changed?
return if !self.changed?
self.callback_loop = true self.callback_loop = true
self.save self.save
end end
end
=begin =begin

View file

@ -168,10 +168,10 @@ translate strings in ruby context, e. g. for notifications
private private
def set_initial def set_initial
if !target_initial
return if target_initial
self.target_initial = self.target self.target_initial = self.target
end end
end
def cache_clear def cache_clear
Cache.delete( 'Translation::' + self.locale.downcase ) Cache.delete( 'Translation::' + self.locale.downcase )
end end

View file

@ -449,10 +449,11 @@ returns
end end
def check_email def check_email
if self.email
return if !self.email
self.email = self.email.downcase self.email = self.email.downcase
end end
end
def check_login def check_login
@ -469,7 +470,8 @@ returns
end end
# check if login already exists # check if login already exists
if self.login return if !self.login
self.login = self.login.downcase self.login = self.login.downcase
check = true check = true
while check while check
@ -481,7 +483,6 @@ returns
end end
end end
end end
end
def avatar_check def avatar_check
@ -499,11 +500,11 @@ returns
) )
# update user link # update user link
if avatar return if !avatar
self.update_column( :image, avatar.store_hash ) self.update_column( :image, avatar.store_hash )
self.cache_delete self.cache_delete
end end
end
def avatar_destroy def avatar_destroy
Avatar.remove( 'User', self.id ) Avatar.remove( 'User', self.id )
@ -524,9 +525,9 @@ returns
end end
# crypt password if not already crypted # crypt password if not already crypted
if self.password && self.password !~ /^\{sha2\}/ return if !( self.password && self.password !~ /^\{sha2\}/ )
crypted = Digest::SHA2.hexdigest( self.password ) crypted = Digest::SHA2.hexdigest( self.password )
self.password = "{sha2}#{crypted}" self.password = "{sha2}#{crypted}"
end end
end
end end

View file

@ -5,7 +5,9 @@ class UpdateOverviewAndTicketState < ActiveRecord::Migration
overview_role = Role.where( name: 'Agent' ).first overview_role = Role.where( name: 'Agent' ).first
add_column :ticket_states, :next_state_id, :integer, null: true add_column :ticket_states, :next_state_id, :integer, null: true
UserInfo.current_user_id = 1 UserInfo.current_user_id = 1
if overview_role
return true if !overview_role
Overview.create_or_update( Overview.create_or_update(
name: 'My pending reached Tickets', name: 'My pending reached Tickets',
link: 'my_pending_reached', link: 'my_pending_reached',
@ -120,7 +122,6 @@ class UpdateOverviewAndTicketState < ActiveRecord::Migration
updated_by_id: 1, updated_by_id: 1,
) )
end end
end
def down def down
end end

View file

@ -2,7 +2,9 @@ class UpdateOverview2 < ActiveRecord::Migration
def up def up
overview_role = Role.where( name: 'Agent' ).first overview_role = Role.where( name: 'Agent' ).first
if overview_role
return true if !overview_role
UserInfo.current_user_id = 1 UserInfo.current_user_id = 1
Overview.create_or_update( Overview.create_or_update(
name: 'My assigned Tickets', name: 'My assigned Tickets',
@ -25,7 +27,6 @@ class UpdateOverview2 < ActiveRecord::Migration
}, },
) )
end end
end
def down def down
end end

View file

@ -61,9 +61,9 @@ def checkForHeader(fileName)
t_file.unlink t_file.unlink
# beautify ruby file # beautify ruby file
if !isCoffee return if isCoffee
t_file = RBeautify.beautify_file(fileName) t_file = RBeautify.beautify_file(fileName)
end
end end
#folder array #folder array