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.
def cors_preflight_check
if request.method == 'OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
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-Max-Age'] = '1728000'
headers['Access-Control-Allow-Credentials'] = 'true'
render text: '', content_type: 'text/plain'
return false
end
return if request.method != 'OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
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-Max-Age'] = '1728000'
headers['Access-Control-Allow-Credentials'] = 'true'
render text: '', content_type: 'text/plain'
false
end
private
@ -90,9 +92,9 @@ class ApplicationController < ActionController::Base
end
# fill user agent
if !session[:user_agent]
session[:user_agent] = request.env['HTTP_USER_AGENT']
end
return if session[:user_agent]
session[:user_agent] = request.env['HTTP_USER_AGENT']
end
def authentication_check_only

View file

@ -159,15 +159,15 @@ class TicketArticlesController < ApplicationController
)
# find file
if list
file = Store.find(list.first)
send_data(
file.content,
filename: file.filename,
type: 'message/rfc822',
disposition: 'inline'
)
end
return if !list
file = Store.find(list.first)
send_data(
file.content,
filename: file.filename,
type: 'message/rfc822',
disposition: 'inline'
)
end
end

View file

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

View file

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

View file

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

View file

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

View file

@ -13,9 +13,10 @@ class Channel::TWITTER2
end
def disconnect
if @client
@client = nil
end
return if !@client
@client = nil
end
def fetch (channel)
@ -288,16 +289,15 @@ class Channel::TWITTER2
return dm
end
if attr[:type] == 'twitter status'
message = client.update(
attr[:body].to_s,
{
in_reply_to_status_id: attr[:in_reply_to]
}
)
# puts message.inspect
return message
end
return if attr[:type] != 'twitter status'
message = client.update(
attr[:body].to_s,
{
in_reply_to_status_id: attr[:in_reply_to]
}
)
# puts message.inspect
return message
end
end

View file

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

View file

@ -44,17 +44,18 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
recipient_list += record[key]
end
}
if recipient_list != ''
History.add(
o_id: record.id,
history_type: 'email',
history_object: 'Ticket::Article',
related_o_id: ticket.id,
related_history_object: 'Ticket',
value_from: record.subject,
value_to: recipient_list,
created_by_id: record.created_by_id,
)
end
return if recipient_list == ''
History.add(
o_id: record.id,
history_type: 'email',
history_object: 'Ticket::Article',
related_o_id: ticket.id,
related_history_object: 'Ticket',
value_from: record.subject,
value_to: recipient_list,
created_by_id: record.created_by_id,
)
end
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -152,10 +152,11 @@ returns
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
end
if self.changed?
self.callback_loop = true
self.save
end
return if !self.changed?
self.callback_loop = true
self.save
end
=begin

View file

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

View file

@ -449,9 +449,10 @@ returns
end
def check_email
if self.email
self.email = self.email.downcase
end
return if !self.email
self.email = self.email.downcase
end
def check_login
@ -469,16 +470,16 @@ returns
end
# check if login already exists
if self.login
self.login = self.login.downcase
check = true
while check
exists = User.where( login: self.login ).first
if exists && exists.id != self.id
self.login = self.login + rand(999).to_s
else
check = false
end
return if !self.login
self.login = self.login.downcase
check = true
while check
exists = User.where( login: self.login ).first
if exists && exists.id != self.id
self.login = self.login + rand(999).to_s
else
check = false
end
end
end
@ -499,10 +500,10 @@ returns
)
# update user link
if avatar
self.update_column( :image, avatar.store_hash )
self.cache_delete
end
return if !avatar
self.update_column( :image, avatar.store_hash )
self.cache_delete
end
def avatar_destroy
@ -524,9 +525,9 @@ returns
end
# crypt password if not already crypted
if self.password && self.password !~ /^\{sha2\}/
crypted = Digest::SHA2.hexdigest( self.password )
self.password = "{sha2}#{crypted}"
end
return if !( self.password && self.password !~ /^\{sha2\}/ )
crypted = Digest::SHA2.hexdigest( self.password )
self.password = "{sha2}#{crypted}"
end
end

View file

@ -5,121 +5,122 @@ class UpdateOverviewAndTicketState < ActiveRecord::Migration
overview_role = Role.where( name: 'Agent' ).first
add_column :ticket_states, :next_state_id, :integer, null: true
UserInfo.current_user_id = 1
if overview_role
Overview.create_or_update(
name: 'My pending reached Tickets',
link: 'my_pending_reached',
prio: 1010,
role_id: overview_role.id,
condition: {
'tickets.state_id' => [3],
'tickets.owner_id' => 'current_user.id',
'tickets.pending_time' => { 'direction' => 'before', 'count' => 1, 'area' => 'minute' },
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: [ 'title', 'customer', 'group', 'created_at' ],
s: [ 'title', 'customer', 'group', 'created_at' ],
m: [ 'number', 'title', 'customer', 'group', 'created_at' ],
view_mode_default: 's',
},
)
Ticket::State.create_or_update( id: 3, name: 'pending reminder', state_type_id: Ticket::StateType.where(name: 'pending reminder').first.id )
Ticket::State.create_or_update( id: 6, name: 'removed', state_type_id: Ticket::StateType.where(name: 'removed').first.id, active: false )
Ticket::State.create_or_update( id: 7, name: 'pending close', state_type_id: Ticket::StateType.where(name: 'pending action').first.id )
ObjectManager::Attribute.add(
object: 'Ticket',
name: 'state_id',
display: 'State',
data_type: 'select',
data_option: {
relation: 'TicketState',
nulloption: true,
multiple: false,
null: false,
default: 2,
translate: true,
filter: [1, 2, 3, 4, 7],
},
editable: false,
active: true,
screens: {
create_middle: {
Agent: {
null: false,
item_class: 'column',
},
Customer: {
item_class: 'column',
nulloption: false,
null: true,
filter: [1, 4],
default: 1,
},
},
edit: {
Agent: {
nulloption: false,
null: false,
filter: [2, 3, 4, 7],
},
Customer: {
nulloption: false,
null: true,
filter: [2, 4],
default: 2,
},
},
},
pending_migration: false,
position: 40,
created_by_id: 1,
updated_by_id: 1,
)
return true if !overview_role
ObjectManager::Attribute.add(
object: 'Ticket',
name: 'pending_time',
display: 'Pending till',
data_type: 'datetime',
data_option: {
future: true,
past: false,
diff: 24,
null: true,
translate: true,
required_if: {
state_id: [3, 7]
Overview.create_or_update(
name: 'My pending reached Tickets',
link: 'my_pending_reached',
prio: 1010,
role_id: overview_role.id,
condition: {
'tickets.state_id' => [3],
'tickets.owner_id' => 'current_user.id',
'tickets.pending_time' => { 'direction' => 'before', 'count' => 1, 'area' => 'minute' },
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: [ 'title', 'customer', 'group', 'created_at' ],
s: [ 'title', 'customer', 'group', 'created_at' ],
m: [ 'number', 'title', 'customer', 'group', 'created_at' ],
view_mode_default: 's',
},
)
Ticket::State.create_or_update( id: 3, name: 'pending reminder', state_type_id: Ticket::StateType.where(name: 'pending reminder').first.id )
Ticket::State.create_or_update( id: 6, name: 'removed', state_type_id: Ticket::StateType.where(name: 'removed').first.id, active: false )
Ticket::State.create_or_update( id: 7, name: 'pending close', state_type_id: Ticket::StateType.where(name: 'pending action').first.id )
ObjectManager::Attribute.add(
object: 'Ticket',
name: 'state_id',
display: 'State',
data_type: 'select',
data_option: {
relation: 'TicketState',
nulloption: true,
multiple: false,
null: false,
default: 2,
translate: true,
filter: [1, 2, 3, 4, 7],
},
editable: false,
active: true,
screens: {
create_middle: {
Agent: {
null: false,
item_class: 'column',
},
shown_if: {
state_id: [3, 7]
Customer: {
item_class: 'column',
nulloption: false,
null: true,
filter: [1, 4],
default: 1,
},
},
editable: false,
active: true,
screens: {
create_middle: {
'-all-' => {
null: false,
item_class: 'column',
},
edit: {
Agent: {
nulloption: false,
null: false,
filter: [2, 3, 4, 7],
},
edit: {
Agent: {
null: false,
},
Customer: {
nulloption: false,
null: true,
filter: [2, 4],
default: 2,
},
},
pending_migration: false,
position: 41,
created_by_id: 1,
updated_by_id: 1,
)
end
},
pending_migration: false,
position: 40,
created_by_id: 1,
updated_by_id: 1,
)
ObjectManager::Attribute.add(
object: 'Ticket',
name: 'pending_time',
display: 'Pending till',
data_type: 'datetime',
data_option: {
future: true,
past: false,
diff: 24,
null: true,
translate: true,
required_if: {
state_id: [3, 7]
},
shown_if: {
state_id: [3, 7]
},
},
editable: false,
active: true,
screens: {
create_middle: {
'-all-' => {
null: false,
item_class: 'column',
},
},
edit: {
Agent: {
null: false,
},
},
},
pending_migration: false,
position: 41,
created_by_id: 1,
updated_by_id: 1,
)
end
def down

View file

@ -2,29 +2,30 @@ class UpdateOverview2 < ActiveRecord::Migration
def up
overview_role = Role.where( name: 'Agent' ).first
if overview_role
UserInfo.current_user_id = 1
Overview.create_or_update(
name: 'My assigned Tickets',
link: 'my_assigned',
prio: 1000,
role_id: overview_role.id,
condition: {
'tickets.state_id' => [ 1, 2, 3, 7 ],
'tickets.owner_id' => 'current_user.id',
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: [ 'title', 'customer', 'group', 'created_at' ],
s: [ 'title', 'customer', 'group', 'created_at' ],
m: [ 'number', 'title', 'customer', 'group', 'created_at' ],
view_mode_default: 's',
},
)
end
return true if !overview_role
UserInfo.current_user_id = 1
Overview.create_or_update(
name: 'My assigned Tickets',
link: 'my_assigned',
prio: 1000,
role_id: overview_role.id,
condition: {
'tickets.state_id' => [ 1, 2, 3, 7 ],
'tickets.owner_id' => 'current_user.id',
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: [ 'title', 'customer', 'group', 'created_at' ],
s: [ 'title', 'customer', 'group', 'created_at' ],
m: [ 'number', 'title', 'customer', 'group', 'created_at' ],
view_mode_default: 's',
},
)
end
def down

View file

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