From 19feb32c7b6e5c23c7c356fec1ec9bf6109fb027 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:14:51 +0200 Subject: [PATCH 01/13] Corrected with rubocop cop 'Style/IndentationWidth'. --- Gemfile | 2 +- .../online_notifications_controller.rb | 12 +-- app/models/online_notification.rb | 24 ++--- lib/import/otrs.rb | 91 +++++++++---------- lib/import/otrs2.rb | 44 +++++---- lib/sessions/backend/activity_stream.rb | 2 +- lib/time_calculation.rb | 12 +-- 7 files changed, 90 insertions(+), 97 deletions(-) diff --git a/Gemfile b/Gemfile index 04d1a75fe..8034211c5 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,7 @@ gem 'em-websocket' # in production environments by default. group :development, :test do - gem 'test-unit' + gem 'test-unit' gem 'spring' gem 'sqlite3' diff --git a/app/controllers/online_notifications_controller.rb b/app/controllers/online_notifications_controller.rb index f3e4b273a..abe8c8c50 100644 --- a/app/controllers/online_notifications_controller.rb +++ b/app/controllers/online_notifications_controller.rb @@ -105,13 +105,13 @@ curl http://localhost/api/v1/online_notifications/mark_all_as_read -v -u #{login =end def mark_all_as_read - notifications = OnlineNotification.list(current_user, 100) - notifications.each do |notification| - if !notification['seen'] - OnlineNotification.seen( id: notification['id'] ) - end + notifications = OnlineNotification.list(current_user, 100) + notifications.each do |notification| + if !notification['seen'] + OnlineNotification.seen( id: notification['id'] ) end - render json: {}, status: :ok + end + render json: {}, status: :ok end end diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index a1c2bfa9d..954aa45ca 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -56,7 +56,7 @@ mark online notification as seen =end def self.seen(data) - notification = OnlineNotification.find(data[:id]) + notification = OnlineNotification.find(data[:id]) notification.seen = true notification.save end @@ -139,17 +139,17 @@ mark online notification as seen by object =end def self.seen_by_object(object_name, o_id) - object_id = ObjectLookup.by_name( object_name ) - notifications = OnlineNotification.where( - object_lookup_id: object_id, - o_id: o_id, - seen: false, - ) - notifications.each do |notification| - notification.seen = true - notification.save - end - true + object_id = ObjectLookup.by_name( object_name ) + notifications = OnlineNotification.where( + object_lookup_id: object_id, + o_id: o_id, + seen: false, + ) + notifications.each do |notification| + notification.seen = true + notification.save + end + true end =begin diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index b9e08326b..3711a96ab 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -117,7 +117,7 @@ module Import::OTRS # check if system is in import mode if !Setting.get('import_mode') - raise 'System is not in import mode!' + raise 'System is not in import mode!' end response = request('public.pl?Action=Export') @@ -181,7 +181,7 @@ module Import::OTRS # check if system is in import mode if !Setting.get('import_mode') - raise 'System is not in import mode!' + raise 'System is not in import mode!' end # create states @@ -702,48 +702,44 @@ module Import::OTRS UserEmail: :email, UserFirstname: :firstname, UserLastname: :lastname, -# :UserTitle => UserLogin: :login, UserPw: :password, }; result.each { |user| # puts 'USER: ' + user.inspect - _set_valid(user) + _set_valid(user) - role = Role.lookup( name: 'Agent' ) - # get new attributes - user_new = { - created_by_id: 1, - updated_by_id: 1, - source: 'OTRS Import', - role_ids: [ role.id ], - } - map.each { |key, value| - if user[key.to_s] - user_new[value] = user[key.to_s] - end - } + role = Role.lookup( name: 'Agent' ) + # get new attributes + user_new = { + created_by_id: 1, + updated_by_id: 1, + source: 'OTRS Import', + role_ids: [ role.id ], + } + map.each { |key, value| + if user[key.to_s] + user_new[value] = user[key.to_s] + end + } - # check if state already exists -# user_old = User.where( :login => user_new[:login] ).first - user_old = User.where( id: user_new[:id] ).first + # check if state already exists + user_old = User.where( id: user_new[:id] ).first # set state types - if user_old - puts "update User.find(#{user_new[:id]})" -# puts 'Update User' + user_new.inspect - user_new.delete( :role_ids ) - user_old.update_attributes(user_new) - else - puts "add User.find(#{user_new[:id]})" -# puts 'Add User' + user_new.inspect - user = User.new(user_new) - user.id = user_new[:id] - user.save - end - -# end + if user_old + puts "update User.find(#{user_new[:id]})" +# puts 'Update User' + user_new.inspect + user_new.delete( :role_ids ) + user_old.update_attributes(user_new) + else + puts "add User.find(#{user_new[:id]})" +# puts 'Add User' + user_new.inspect + user = User.new(user_new) + user.id = user_new[:id] + user.save + end } end def self.customer @@ -767,7 +763,6 @@ module Import::OTRS UserEmail: :email, UserFirstname: :firstname, UserLastname: :lastname, - # :UserTitle => UserLogin: :login, UserPassword: :password, UserPhone: :phone, @@ -800,7 +795,7 @@ module Import::OTRS } # check if state already exists - # user_old = User.where( :login => user_new[:login] ).first +# user_old = User.where( :login => user_new[:login] ).first user_old = User.where( login: user_new[:login] ).first # set state types @@ -819,17 +814,17 @@ module Import::OTRS end def self._set_valid(record) # map - if record['ValidID'] == '3' - record['ValidID'] = '2' - end - if record['ValidID'] == '2' - record['ValidID'] = false - end - if record['ValidID'] == '1' - record['ValidID'] = true - end - if record['ValidID'] == '0' - record['ValidID'] = false - end + if record['ValidID'] == '3' + record['ValidID'] = '2' + end + if record['ValidID'] == '2' + record['ValidID'] = false + end + if record['ValidID'] == '1' + record['ValidID'] = true + end + if record['ValidID'] == '0' + record['ValidID'] = false + end end end diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index d62a5d896..d6fb034b3 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -346,14 +346,14 @@ module Import::OTRS2 steps = 30 run = true while run - count += steps - records = load('CustomerUser', steps, count - steps) - if !records || !records[0] - log 'all customers imported.' - run = false - next - end - customer(records, organizations) + count += steps + records = load('CustomerUser', steps, count - steps) + if !records || !records[0] + log 'all customers imported.' + run = false + next + end + customer(records, organizations) end Thread.abort_on_exception = true @@ -944,7 +944,6 @@ module Import::OTRS2 UserEmail: :email, UserFirstname: :firstname, UserLastname: :lastname, -# :UserTitle => UserLogin: :login, UserPw: :password, }; @@ -1065,7 +1064,6 @@ module Import::OTRS2 UserEmail: :email, UserFirstname: :firstname, UserLastname: :lastname, -# :UserTitle => UserLogin: :login, UserPassword: :password, UserPhone: :phone, @@ -1236,20 +1234,20 @@ module Import::OTRS2 def self._set_valid(record) - # map - if record['ValidID'].to_s == '3' - record['ValidID'] = false - elsif record['ValidID'].to_s == '2' - record['ValidID'] = false - elsif record['ValidID'].to_s == '1' - record['ValidID'] = true - elsif record['ValidID'].to_s == '0' - record['ValidID'] = false + # map + if record['ValidID'].to_s == '3' + record['ValidID'] = false + elsif record['ValidID'].to_s == '2' + record['ValidID'] = false + elsif record['ValidID'].to_s == '1' + record['ValidID'] = true + elsif record['ValidID'].to_s == '0' + record['ValidID'] = false - # fallback - else - record['ValidID'] = true - end + # fallback + else + record['ValidID'] = true + end end # cleanup invalid values diff --git a/lib/sessions/backend/activity_stream.rb b/lib/sessions/backend/activity_stream.rb index 888d9d70e..ec4289f0a 100644 --- a/lib/sessions/backend/activity_stream.rb +++ b/lib/sessions/backend/activity_stream.rb @@ -22,7 +22,7 @@ class Sessions::Backend::ActivityStream # update last changed if activity_stream && activity_stream.first - @last_change = activity_stream.first['created_at'] + @last_change = activity_stream.first['created_at'] end @user.activity_stream( 25, true ) diff --git a/lib/time_calculation.rb b/lib/time_calculation.rb index d0b4bca2e..48e02ef86 100644 --- a/lib/time_calculation.rb +++ b/lib/time_calculation.rb @@ -22,11 +22,11 @@ put working hours matrix and timezone in function, returns UTC working hours mat time_diff = 0 if timezone begin - time_diff = Time.parse(start_time.to_s).in_time_zone(timezone).utc_offset - rescue Exception => e - puts "ERROR: Can't fine tomezone #{timezone}" - puts e.inspect - puts e.backtrace + time_diff = Time.parse(start_time.to_s).in_time_zone(timezone).utc_offset + rescue Exception => e + puts "ERROR: Can't fine tomezone #{timezone}" + puts e.inspect + puts e.backtrace end end beginning_of_workday = Time.parse("1977-10-27 #{config['beginning_of_workday']}") @@ -169,7 +169,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat diff = end_time - start_time if diff > 59 * 60 - diff = start_time - start_time.beginning_of_hour + diff = start_time - start_time.beginning_of_hour end start_time += diff From 69a16ee2c593d3d4bfacc1ba1db50c379c41bab8 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:20:27 +0200 Subject: [PATCH 02/13] Corrected with rubocop cop 'Style/RedundantReturn'. --- app/models/channel/email_parser.rb | 2 +- app/models/channel/twitter2.rb | 6 +++--- app/models/history.rb | 12 ++++++------ app/models/link.rb | 6 +++--- app/models/online_notification.rb | 2 +- app/models/recent_view.rb | 2 +- app/models/setting.rb | 4 ++-- app/models/store.rb | 6 +++--- app/models/tag.rb | 14 +++++++------- app/models/ticket/subject.rb | 2 +- app/models/token.rb | 2 +- app/models/translation.rb | 4 ++-- app/models/user.rb | 2 +- lib/auth.rb | 4 +--- lib/auth/developer.rb | 2 +- lib/auth/internal.rb | 2 +- lib/auth/ldap.rb | 2 +- lib/auth/otrs.rb | 2 +- lib/geo_location/gmaps.rb | 2 +- lib/import/otrs.rb | 12 +++++------- lib/import/otrs2.rb | 7 +++---- lib/rss.rb | 2 +- lib/session_helper.rb | 2 +- lib/sessions.rb | 2 +- lib/sso.rb | 2 -- lib/time_calculation.rb | 4 ++-- 26 files changed, 51 insertions(+), 58 deletions(-) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 526f97e37..1d3862649 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -491,7 +491,7 @@ class Channel::EmailParser } # return new objects - return ticket, article, user + [ticket, article, user] end def user_create(data) diff --git a/app/models/channel/twitter2.rb b/app/models/channel/twitter2.rb index 4720ca5fc..5724aa1c1 100644 --- a/app/models/channel/twitter2.rb +++ b/app/models/channel/twitter2.rb @@ -134,7 +134,7 @@ class Channel::TWITTER2 ticket = fetch_ticket_create(user, tweet, sender, channel, group) end article = fetch_article_create(user, ticket, tweet, sender) - return user, ticket, article + [user, ticket, article] end def fetch_user_create(tweet, sender) @@ -177,7 +177,7 @@ class Channel::TWITTER2 # set current user UserInfo.current_user_id = user.id - return user + user end def fetch_ticket_create(user, tweet, sender, channel, group) @@ -298,6 +298,6 @@ class Channel::TWITTER2 } ) # puts message.inspect - return message + message end end diff --git a/app/models/history.rb b/app/models/history.rb index 1b24f60f2..5c97b1a37 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -223,7 +223,7 @@ returns # lookup history_type = History::Type.lookup( id: id ) @@cache_type[ id ] = history_type - return history_type + history_type end def self.type_lookup( name ) @@ -243,7 +243,7 @@ returns name: name ) @@cache_type[ name ] = history_type - return history_type + history_type end def self.object_lookup_id( id ) @@ -254,7 +254,7 @@ returns # lookup history_object = History::Object.lookup( id: id ) @@cache_object[ id ] = history_object - return history_object + history_object end def self.object_lookup( name ) @@ -274,7 +274,7 @@ returns name: name ) @@cache_object[ name ] = history_object - return history_object + history_object end def self.attribute_lookup_id( id ) @@ -285,7 +285,7 @@ returns # lookup history_attribute = History::Attribute.lookup( id: id ) @@cache_attribute[ id ] = history_attribute - return history_attribute + history_attribute end def self.attribute_lookup( name ) @@ -305,7 +305,7 @@ returns name: name ) @@cache_attribute[ name ] = history_attribute - return history_attribute + history_attribute end private diff --git a/app/models/link.rb b/app/models/link.rb index 039b888e0..554707e30 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -49,7 +49,7 @@ class Link < ApplicationModel items.push link } - return items + items end =begin @@ -159,7 +159,7 @@ class Link < ApplicationModel name: data[:name] ) end - return linktype + linktype end def self.link_object_get(data) @@ -169,7 +169,7 @@ class Link < ApplicationModel name: data[:name] ) end - return linkobject + linkobject end end diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 954aa45ca..637b88769 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -171,7 +171,7 @@ returns: notifications = OnlineNotification.list(user, limit) assets = ApplicationModel.assets_of_object_list(notifications) - return { + { stream: notifications, assets: assets } diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index ea64c0f9e..d5e7e2239 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -67,7 +67,7 @@ class RecentView < ApplicationModel # get related object assets = ApplicationModel.assets_of_object_list(recent_viewed) - return { + { stream: recent_viewed, assets: assets, } diff --git a/app/models/setting.rb b/app/models/setting.rb index 9a2effc26..9439d3a77 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -32,7 +32,7 @@ class Setting < ApplicationModel # store for class requests @@current[:settings_config] = config - return config + config end def self.set(name, value) @@ -47,7 +47,7 @@ class Setting < ApplicationModel def self.get(name) self.load - return @@current[:settings_config][name] + @@current[:settings_config][name] end private diff --git a/app/models/store.rb b/app/models/store.rb index 4d8540bfb..58904adb6 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -82,7 +82,7 @@ returns store_object_id = Store::Object.lookup( name: data[:object] ) stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i ). order('created_at ASC, id ASC') - return stores + stores end =begin @@ -111,7 +111,7 @@ returns # check backend for references Store.remove_item( store.id ) end - return true + true end =begin @@ -136,7 +136,7 @@ returns end store.destroy - return true + true end def content diff --git a/app/models/tag.rb b/app/models/tag.rb index ba3002516..9f2b30cd7 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -24,7 +24,7 @@ class Tag < ApplicationModel o_id: data[:o_id], created_by_id: data[:created_by_id], ) - return true + true end def self.tag_remove(data) @@ -46,7 +46,7 @@ class Tag < ApplicationModel result.each { |item| item.destroy } - return true + true end def self.tag_list( data ) @@ -59,7 +59,7 @@ class Tag < ApplicationModel tag_search.each {|tag| tags.push self.tag_item_lookup_id( tag.tag_item_id ) } - return tags + tags end private @@ -72,7 +72,7 @@ class Tag < ApplicationModel # lookup tag_item = Tag::Item.find(id) @@cache_item[ id ] = tag_item.name - return tag_item.name + tag_item.name end def self.tag_item_lookup( name ) @@ -94,7 +94,7 @@ class Tag < ApplicationModel name: name ) @@cache_item[ name ] = tag_item.id - return tag_item.id + tag_item.id end def self.tag_object_lookup_id( id ) @@ -105,7 +105,7 @@ class Tag < ApplicationModel # lookup tag_object = Tag::Object.find(id) @@cache_object[ id ] = tag_object.name - return tag_object.name + tag_object.name end def self.tag_object_lookup( name ) @@ -125,7 +125,7 @@ class Tag < ApplicationModel name: name ) @@cache_object[ name ] = tag_object.id - return tag_object.id + tag_object.id end class Object < ActiveRecord::Base diff --git a/app/models/ticket/subject.rb b/app/models/ticket/subject.rb index 054abd4cb..7a7f61163 100644 --- a/app/models/ticket/subject.rb +++ b/app/models/ticket/subject.rb @@ -34,7 +34,7 @@ returns end # left position - return "[#{ticket_hook}#{ticket_hook_divider}#{self.number}] " + subject + "[#{ticket_hook}#{ticket_hook_divider}#{self.number}] " + subject end =begin diff --git a/app/models/token.rb b/app/models/token.rb index b48d34aa5..ff615d0aa 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -22,7 +22,7 @@ class Token < ActiveRecord::Base end # return token if valid - return token.user + token.user end private diff --git a/app/models/translation.rb b/app/models/translation.rb index 715df596b..d748bbc80 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -136,7 +136,7 @@ get list of translations end end - return { + { list: list, } end @@ -163,7 +163,7 @@ translate strings in ruby context, e. g. for notifications return record.target if record.source == string } - return string + string end private diff --git a/app/models/user.rb b/app/models/user.rb index 6256eae8f..18f0eae30 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -159,7 +159,7 @@ returns # get related objects assets = ApplicationModel.assets_of_object_list(activity_stream) - return { + { activity_stream: activity_stream, assets: assets, } diff --git a/lib/auth.rb b/lib/auth.rb index abb70af83..d77682a5d 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -54,7 +54,5 @@ returns return user_auth end } - return - - end + end end diff --git a/lib/auth/developer.rb b/lib/auth/developer.rb index ce006d19d..fc28219ee 100644 --- a/lib/auth/developer.rb +++ b/lib/auth/developer.rb @@ -8,6 +8,6 @@ module Auth::Developer return user if password == 'test' end - return false + false end end diff --git a/lib/auth/internal.rb b/lib/auth/internal.rb index 2ccbd30d5..0c367442d 100644 --- a/lib/auth/internal.rb +++ b/lib/auth/internal.rb @@ -15,6 +15,6 @@ module Auth::Internal # plain auth check return user if user.password == password - return false + false end end diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index b3db2c056..3e5ed005b 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -119,6 +119,6 @@ module Auth::Ldap # take session down # - not needed, done by Net::LDAP - - return user + user end end diff --git a/lib/auth/otrs.rb b/lib/auth/otrs.rb index 052d9acf6..3dab3b7b1 100644 --- a/lib/auth/otrs.rb +++ b/lib/auth/otrs.rb @@ -23,6 +23,6 @@ module Auth::Otrs # sync / check permissions Import::OTRS.permission_sync( user, result, config ) - return user + user end end diff --git a/lib/geo_location/gmaps.rb b/lib/geo_location/gmaps.rb index 7265ed49b..a96b32a8e 100644 --- a/lib/geo_location/gmaps.rb +++ b/lib/geo_location/gmaps.rb @@ -26,6 +26,6 @@ class GeoLocation::Gmaps result = JSON.parse( response.body ) address = result['results'].first['address_components'].first['long_name'] - return address + address end end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 3711a96ab..e0cf187dc 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -15,7 +15,7 @@ module Import::OTRS puts "ERROR: #{response.error}" return end - return response + response end def self.post(base, data) url = Setting.get('import_otrs_endpoint') + '/' + base @@ -34,7 +34,7 @@ module Import::OTRS puts "ERROR: #{response.error}" return end - return response + response end def self.json(response) @@ -48,7 +48,7 @@ module Import::OTRS return if !response.success? result = json(response) - return result + result end def self.session(session_id) @@ -57,7 +57,7 @@ module Import::OTRS return if !response.success? result = json(response) - return result + result end def self.permission_sync(user, result, config) @@ -167,8 +167,7 @@ module Import::OTRS threads[thread].join } - return - end + end def self.diff_worker return if !Setting.get('import_mode') @@ -198,7 +197,6 @@ module Import::OTRS self.ticket_diff() - return end def self.ticket_diff() diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index d6fb034b3..6731e255c 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -143,7 +143,7 @@ module Import::OTRS2 return if !response.success? result = json(response) - return result + result end =begin @@ -165,7 +165,7 @@ module Import::OTRS2 return if !response return if !response.success? result = json(response) - return result + result end =begin @@ -201,7 +201,7 @@ module Import::OTRS2 =end def self.connection_test - return self.request_json({}) + self.request_json({}) end =begin @@ -439,7 +439,6 @@ module Import::OTRS2 # get changed tickets self.ticket_diff - return end def self.ticket_diff diff --git a/lib/rss.rb b/lib/rss.rb index 5a2d0524c..aa13e8f2e 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -34,6 +34,6 @@ module Rss return end - return items + items end end diff --git a/lib/session_helper.rb b/lib/session_helper.rb index 4add9ed6b..ae97d7210 100644 --- a/lib/session_helper.rb +++ b/lib/session_helper.rb @@ -13,7 +13,7 @@ module SessionHelper (default_collection, assets ) = ExtraCollection.session( default_collection, assets, user ) end - return default_collection, assets + [default_collection, assets] end def self.models(user = nil) diff --git a/lib/sessions.rb b/lib/sessions.rb index 5cdd478a0..9d1bf2ab8 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -468,7 +468,7 @@ returns to_delete.each {|file| File.delete(file) } - return data + data end def self.jobs diff --git a/lib/sso.rb b/lib/sso.rb index f85add86f..a7ae93e2e 100644 --- a/lib/sso.rb +++ b/lib/sso.rb @@ -65,7 +65,5 @@ returns return user_auth end } - return - end end diff --git a/lib/time_calculation.rb b/lib/time_calculation.rb index 48e02ef86..46f031cd0 100644 --- a/lib/time_calculation.rb +++ b/lib/time_calculation.rb @@ -93,7 +93,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat } } end - return working_hours + working_hours end =begin @@ -350,7 +350,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat start_time = start_time.beginning_of_day + 86_400 end - return start_time + start_time end end From 88344da11c0b57dc317bbef95f1ee318068eab8d Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:22:28 +0200 Subject: [PATCH 03/13] Corrected with rubocop cop 'Style/EmptyElse'. --- app/models/ticket/escalation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 524c615ca..cb971087c 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -262,7 +262,7 @@ returns if counted # 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 - else + # else # puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}" end total_time = total_time + diff From 4b4f45ddd1b8ef1c8d46c7a70e023884f538d143 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:26:00 +0200 Subject: [PATCH 04/13] Corrected with rubocop cop 'Lint/DeprecatedClassMethods'. --- app/models/package.rb | 10 +++++----- config/boot.rb | 2 +- lib/sessions.rb | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/package.rb b/app/models/package.rb index f355adb63..0b01ee5c1 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -71,7 +71,7 @@ class Package < ApplicationModel File.delete( entry ) end backup_file = entry + '.link_backup' - if File.exists?( backup_file ) + if File.exist?( backup_file ) logger.info "Restore backup file of #{backup_file} -> #{entry}." File.rename( backup_file, entry ) end @@ -114,7 +114,7 @@ class Package < ApplicationModel end backup_file = dest.to_s + '.link_backup' - if File.exists?( backup_file ) + if File.exist?( backup_file ) logger.info "Restore backup file of #{backup_file} -> #{dest.to_s}." File.rename( backup_file, dest.to_s ) end @@ -145,7 +145,7 @@ class Package < ApplicationModel dest = @@root + '/' + file if File.directory?( entry.to_s ) - if !File.exists?( dest.to_s ) + if !File.exist?( dest.to_s ) logger.info "Create dir: #{dest.to_s}" FileUtils.mkdir_p( dest.to_s ) end @@ -153,7 +153,7 @@ class Package < ApplicationModel if File.file?( entry.to_s ) && ( File.file?( dest.to_s ) && !File.symlink?( dest.to_s ) ) backup_file = dest.to_s + '.link_backup' - if File.exists?( backup_file ) + if File.exist?( backup_file ) raise "Can't link #{entry.to_s} -> #{dest.to_s}, destination and .link_backup already exists!" else logger.info "Create backup file of #{dest.to_s} -> #{backup_file}." @@ -441,7 +441,7 @@ class Package < ApplicationModel def self.migrate( package, direction = 'normal' ) location = @@root + '/db/addon/' + package.underscore - return true if !File.exists?( location ) + return true if !File.exist?( location ) migrations_done = Package::Migration.where( name: package.underscore ) # get existing migrations diff --git a/config/boot.rb b/config/boot.rb index 4489e5868..f2830ae31 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,4 +3,4 @@ require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/lib/sessions.rb b/lib/sessions.rb index 9d1bf2ab8..05b0df90d 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -68,7 +68,7 @@ returns path = @path + '/' # just make sure that spool path exists - if !File::exists?( path ) + if !File::exist?( path ) FileUtils.mkpath path end @@ -270,7 +270,7 @@ returns check = true count = 0 while check - if File::exists?( path + filename ) + if File::exist?( path + filename ) count += 1 filename = filename + '-' + count else @@ -284,7 +284,7 @@ returns file.flock( File::LOCK_UN ) file.close } - return false if !File.exists?( path + 'a-' + filename ) + return false if !File.exist?( path + 'a-' + filename ) FileUtils.mv( path + 'a-' + filename, path + filename ) true end @@ -419,7 +419,7 @@ returns } files.sort.each {|entry| filename = path + '/' + entry - next if !File::exists?( filename ) + next if !File::exist?( filename ) File.open( filename, 'rb' ) { |file| all = file.read spool = JSON.parse( all ) @@ -474,7 +474,7 @@ returns def self.jobs # just make sure that spool path exists - if !File::exists?( @path ) + if !File::exist?( @path ) FileUtils.mkpath @path end From 44adaf000e1923ccc8b8ecbde82b766f561cf6d6 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:34:33 +0200 Subject: [PATCH 05/13] Corrected with rubocop cop 'Style/DeprecatedHashMethods'. --- app/models/application_model.rb | 10 +++++----- app/models/channel/imap.rb | 2 +- app/models/channel/pop3.rb | 2 +- app/models/link.rb | 14 +++++++------- app/models/setting.rb | 2 +- lib/import/otrs.rb | 4 ++-- lib/import/otrs2.rb | 12 ++++++------ script/websocket-server.rb | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 27eaf0419..e2e50d9c8 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -81,7 +81,7 @@ returns # only use object attributes data = {} self.new.attributes.each {|item| - if params.has_key?(item[0]) + if params.key?(item[0]) # puts 'use ' + item[0].to_s + '-' + params[item[0]].to_s data[item[0].to_sym] = params[item[0]] end @@ -109,7 +109,7 @@ returns # set relations self.class.reflect_on_all_associations.map { |assoc| real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' - if params.has_key?( real_key.to_sym ) + if params.key?( real_key.to_sym ) list_of_items = params[ real_key.to_sym ] if params[ real_key.to_sym ].class != Array list_of_items = [ params[ real_key.to_sym ] ] @@ -246,14 +246,14 @@ returns # delete old name / login caches if self.changed? - if self.changes.has_key?('name') + if self.changes.key?('name') name = self.changes['name'][0].to_s key = self.class.to_s + '::' + name Cache.delete( key.to_s ) key = self.class.to_s + ':f:' + name Cache.delete( key.to_s ) end - if self.changes.has_key?('login') + if self.changes.key?('login') name = self.changes['login'][0].to_s key = self.class.to_s + '::' + name Cache.delete( key.to_s ) @@ -844,7 +844,7 @@ log object update history with all updated attributes, if configured - will be e changes = self.changes if self.history_changes_last_done self.history_changes_last_done.each {|key, value| - if changes.has_key?(key) && changes[key] == value + if changes.key?(key) && changes[key] == value changes.delete(key) end } diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index 6bcb05b11..7a9508cf0 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -7,7 +7,7 @@ class Channel::IMAP < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') ssl = true port = 993 - if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + if channel[:options].key?(:ssl) && channel[:options][:ssl].to_s == 'false' ssl = false port = 143 end diff --git a/app/models/channel/pop3.rb b/app/models/channel/pop3.rb index af8abee6a..6ec354757 100644 --- a/app/models/channel/pop3.rb +++ b/app/models/channel/pop3.rb @@ -7,7 +7,7 @@ class Channel::POP3 < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') ssl = true port = 995 - if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + if channel[:options].key?(:ssl) && channel[:options][:ssl].to_s == 'false' ssl = false port = 110 end diff --git a/app/models/link.rb b/app/models/link.rb index 554707e30..b7b5e744b 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -74,19 +74,19 @@ class Link < ApplicationModel def self.add(data) - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: data[:link_type] ) data[:link_type_id] = linktype.id data.delete( :link_type ) end - if data.has_key?(:link_object_source) + if data.key?(:link_object_source) linkobject = self.link_object_get( name: data[:link_object_source] ) data[:link_object_source_id] = linkobject.id data.delete( :link_object_source ) end - if data.has_key?(:link_object_target) + if data.key?(:link_object_target) linkobject = self.link_object_get( name: data[:link_object_target] ) data[:link_object_target_id] = linkobject.id data.delete( :link_object_target ) @@ -108,18 +108,18 @@ class Link < ApplicationModel =end def self.remove(data) - if data.has_key?(:link_object_source) + if data.key?(:link_object_source) linkobject = self.link_object_get( name: data[:link_object_source] ) data[:link_object_source_id] = linkobject.id end - if data.has_key?(:link_object_target) + if data.key?(:link_object_target) linkobject = self.link_object_get( name: data[:link_object_target] ) data[:link_object_target_id] = linkobject.id end # from one site - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: data[:link_type] ) data[:link_type_id] = linktype.id end @@ -135,7 +135,7 @@ class Link < ApplicationModel } # from the other site - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: @map[ data[:link_type] ] ) data[:link_type_id] = linktype.id end diff --git a/app/models/setting.rb b/app/models/setting.rb index 9439d3a77..57dbb7efe 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -61,7 +61,7 @@ class Setting < ApplicationModel return if !(self.state || self.state == false) - return if !( !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) ) + return if !( !self.state.respond_to?('has_key?') || !self.state.key?(:value) ) self.state = { value: self.state } end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index e0cf187dc..ec2fb7456 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -69,7 +69,7 @@ module Import::OTRS } types.each {|config_key, result_key| if config[config_key] - return false if !result[result_key].has_value?( config[config_key] ) + return false if !result[result_key].value?( config[config_key] ) end } @@ -85,7 +85,7 @@ module Import::OTRS types.each {|config_key, result_key| next if !config[config_key] config[config_key].each {|otrs_group, role| - next if !result[result_key].has_value?( otrs_group ) + next if !result[result_key].value?( otrs_group ) role_ids = user.role_ids role = Role.where( name: role ).first next if !role diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 6731e255c..49996a7b2 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -820,7 +820,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if state.has_key?(key.to_s) + if state.key?(key.to_s) state_new[value] = state[key.to_s] end } @@ -869,7 +869,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if priority.has_key?(key.to_s) + if priority.key?(key.to_s) priority_new[value] = priority[key.to_s] end } @@ -910,7 +910,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if group.has_key?(key.to_s) + if group.key?(key.to_s) group_new[value] = group[key.to_s] end } @@ -965,7 +965,7 @@ module Import::OTRS2 group_ids: group_ids, } map.each { |key, value| - if user.has_key?(key.to_s) + if user.key?(key.to_s) user_new[value] = user[key.to_s] end } @@ -1089,7 +1089,7 @@ module Import::OTRS2 role_ids: [ role_customer.id ], } map.each { |key, value| - if user.has_key?(key.to_s) + if user.key?(key.to_s) user_new[value] = user[key.to_s] end } @@ -1153,7 +1153,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if organization.has_key?(key.to_s) + if organization.key?(key.to_s) organization_new[value] = organization[key.to_s] end } diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 75c18eba6..9501ee119 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -191,7 +191,7 @@ EventMachine.run { if data['recipient'].class != Hash log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'" else - if !data['recipient'].has_key?('user_id') + if !data['recipient'].key?('user_id') log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'" else if data['recipient']['user_id'].class != Array From 4ca036ecc9dc07006f13a6a3c5bc59879b86820a Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:46:06 +0200 Subject: [PATCH 06/13] Corrected with rubocop cop 'Style/TrailingWhitespace'. --- config/initializers/omniauth.rb | 2 +- db/migrate/20120101000070_create_channel.rb | 2 +- db/migrate/20130815000002_update_ticket_number.rb | 4 ++-- db/seeds.rb | 2 +- lib/auth/ldap.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index d4279d7b7..e14de3c8a 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,6 +1,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do - # twitter database connect + # twitter database connect provider :twitter_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse', client_options: { authorize_path: '/oauth/authorize', site: 'https://api.twitter.com' } diff --git a/db/migrate/20120101000070_create_channel.rb b/db/migrate/20120101000070_create_channel.rb index a5c080437..6ffb0bd94 100644 --- a/db/migrate/20120101000070_create_channel.rb +++ b/db/migrate/20120101000070_create_channel.rb @@ -1,6 +1,6 @@ class CreateChannel < ActiveRecord::Migration def up - + create_table :channels do |t| t.references :group, null: true t.column :adapter, :string, limit: 100, null: false diff --git a/db/migrate/20130815000002_update_ticket_number.rb b/db/migrate/20130815000002_update_ticket_number.rb index 43616ef4f..e2664adb8 100644 --- a/db/migrate/20130815000002_update_ticket_number.rb +++ b/db/migrate/20130815000002_update_ticket_number.rb @@ -8,14 +8,14 @@ class UpdateTicketNumber < ActiveRecord::Migration number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139). With "Date" the ticket numbers will be generated by the current date, the SystemID and the counter. The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139). - With param "Checksum => true" the counter will be appended as checksum to the string. The format + With param "Checksum => true" the counter will be appended as checksum to the string. The format looks like SystemID.Counter.CheckSum (e. g. 10101384, 10101392) or Year.Month.Day.SystemID.Counter.CheckSum (e.g. 2012070110101520, 2012070110101535).', options: { form: [ { display: '', null: true, - name: 'ticket_number', + name: 'ticket_number', tag: 'select', options: { 'Ticket::Number::Increment' => 'Increment (SystemID.Counter)', diff --git a/db/seeds.rb b/db/seeds.rb index 806e074ac..f2de5a4f2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -768,7 +768,7 @@ Setting.create_if_not_exists( number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139). With "Date" the ticket numbers will be generated by the current date, the SystemID and the counter. The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139). - With param "Checksum => true" the counter will be appended as checksum to the string. The format + With param "Checksum => true" the counter will be appended as checksum to the string. The format looks like SystemID.Counter.CheckSum (e. g. 10101384, 10101392) or Year.Month.Day.SystemID.Counter.CheckSum (e.g. 2012070110101520, 2012070110101535).', options: { form: [ diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index 3e5ed005b..2994f65c8 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -76,7 +76,7 @@ module Auth::Ldap else user.update_attributes( user_attributes ) puts "NOTICE: user updated '#{user.login}'" - end + end end # return if it was not possible to create user From 329efa85665a2a8f81d2f57d6b9f630d721bcb65 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:47:49 +0200 Subject: [PATCH 07/13] Corrected with rubocop cop 'Style/NonNilCheck'. --- app/models/history.rb | 2 +- app/models/user.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/history.rb b/app/models/history.rb index 5c97b1a37..42f051ee3 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -193,7 +193,7 @@ returns data.delete( 'value_to' ) data.delete( 'value_from' ) end - if data['related_history_object_id'] != nil + if !data['related_history_object_id'].nil? data['related_object'] = self.object_lookup_id( data['related_history_object_id'] ).name end data.delete( 'related_history_object_id' ) diff --git a/app/models/user.rb b/app/models/user.rb index 18f0eae30..743ec0a8c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -415,10 +415,10 @@ returns scan = self.firstname.scan(/, /) if scan[0] name = self.firstname.split(', ', 2) - if name[0] != nil + if !name[0].nil? self.lastname = name[0] end - if name[1] != nil + if !name[1].nil? self.firstname = name[1] end return @@ -426,10 +426,10 @@ returns # Firstname Lastname name = self.firstname.split(' ', 2) - if name[0] != nil + if !name[0].nil? self.firstname = name[0] end - if name[1] != nil + if !name[1].nil? self.lastname = name[1] end return @@ -438,10 +438,10 @@ returns elsif ( !self.firstname || self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) && ( self.email && !self.email.empty? ) scan = self.email.scan(/^(.+?)\.(.+?)\@.+?$/) if scan[0] - if scan[0][0] != nil + if !scan[0][0].nil? self.firstname = scan[0][0].capitalize end - if scan[0][1] != nil + if !scan[0][1].nil? self.lastname = scan[0][1].capitalize end end From b2fd3ba9f0928b99734e31ff30007e83613b2773 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:51:31 +0200 Subject: [PATCH 08/13] Corrected with rubocop cop 'Style/DotPosition'. --- app/models/activity_stream.rb | 12 ++++----- app/models/history.rb | 10 ++++---- app/models/job.rb | 6 ++--- app/models/online_notification.rb | 12 ++++----- app/models/recent_view.rb | 18 ++++++------- app/models/store.rb | 10 ++++---- app/models/ticket.rb | 8 +++--- app/models/ticket/overviews.rb | 42 +++++++++++++++---------------- lib/core_ext/class.rb | 10 ++++---- 9 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 9b2a551e0..d5806acc9 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -98,13 +98,13 @@ return all activity entries of an user return [] if role_ids.include?(customer_role.id) if group_ids.empty? - stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids ). - order( 'created_at DESC, id DESC' ). - limit( limit ) + stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) else - stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids ). - order( 'created_at DESC, id DESC' ). - limit( limit ) + stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) end list = [] stream.each do |item| diff --git a/app/models/history.rb b/app/models/history.rb index 42f051ee3..f3de58535 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -150,9 +150,9 @@ returns def self.list( requested_object, requested_object_id, related_history_object = nil, assets = nil ) if !related_history_object history_object = self.object_lookup( requested_object ) - history = History.where( history_object_id: history_object.id ). - where( o_id: requested_object_id ). - order('created_at ASC, id ASC') + history = History.where( history_object_id: history_object.id ) + .where( o_id: requested_object_id ) + .order('created_at ASC, id ASC') else history_object_requested = self.object_lookup( requested_object ) history_object_related = self.object_lookup( related_history_object ) @@ -162,8 +162,8 @@ returns requested_object_id, history_object_related.id, requested_object_id, - ). - order('created_at ASC, id ASC') + ) + .order('created_at ASC, id ASC') end asset_list = {} list = [] diff --git a/app/models/job.rb b/app/models/job.rb index c8ed289c5..4bf4b7d45 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -42,9 +42,9 @@ class Job < ApplicationModel next if !job.timeplan['minutes'].include?( match_minutes(time.min.to_s) ) # find tickets to change - tickets = Ticket.where( job.condition.permit! ). - order( '`tickets`.`created_at` DESC' ). - limit( 1_000 ) + tickets = Ticket.where( job.condition.permit! ) + .order( '`tickets`.`created_at` DESC' ) + .limit( 1_000 ) job.processed = tickets.count tickets.each do |ticket| #puts "CHANGE #{job.execute.inspect}" diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 637b88769..baa9e6f66 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -87,9 +87,9 @@ return all online notifications of an user def self.list(user, limit) - notifications = OnlineNotification.where(user_id: user.id). - order( 'created_at DESC, id DESC' ). - limit( limit ) + notifications = OnlineNotification.where(user_id: user.id) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) list = [] notifications.each do |item| data = item.attributes @@ -115,9 +115,9 @@ return all online notifications of an object notifications = OnlineNotification.where( object_lookup_id: object_id, o_id: o_id, - ). - order( 'created_at DESC, id DESC' ). - limit( 10_000 ) + ) + .order( 'created_at DESC, id DESC' ) + .limit( 10_000 ) list = [] notifications.each do |item| data = item.attributes diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index d5e7e2239..9c3c3915d 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -26,9 +26,9 @@ class RecentView < ApplicationModel def self.log_destroy( requested_object, requested_object_id ) return if requested_object == 'RecentView' - RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) ). - where( o_id: requested_object_id ). - destroy_all + RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) ) + .where( o_id: requested_object_id ) + .destroy_all end def self.user_log_destroy( user ) @@ -37,13 +37,13 @@ class RecentView < ApplicationModel def self.list( user, limit = 10, type = nil ) if !type - recent_views = RecentView.where( created_by_id: user.id ). - order('created_at DESC, id DESC'). - limit(limit) + recent_views = RecentView.where( created_by_id: user.id ) + .order('created_at DESC, id DESC') + .limit(limit) else - recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) ) . - order('created_at DESC, id DESC'). - limit(limit) + recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) ) + .order('created_at DESC, id DESC') + .limit(limit) end list = [] diff --git a/app/models/store.rb b/app/models/store.rb index 58904adb6..f907efebc 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -80,8 +80,8 @@ returns def self.list(data) # search store_object_id = Store::Object.lookup( name: data[:object] ) - stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i ). - order('created_at ASC, id ASC') + stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i ) + .order('created_at ASC, id ASC') stores end @@ -103,9 +103,9 @@ returns def self.remove(data) # search store_object_id = Store::Object.lookup( name: data[:object] ) - stores = Store.where( store_object_id: store_object_id ). - where( o_id: data[:o_id] ). - order('created_at ASC, id ASC') + stores = Store.where( store_object_id: store_object_id ) + .where( o_id: data[:o_id] ) + .order('created_at ASC, id ASC') stores.each do |store| # check backend for references diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 27a366612..9698eebd1 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -94,10 +94,10 @@ returns def self.access_condition(user) access_condition = [] if user.is_role(Z_ROLENAME_AGENT) - group_ids = Group.select( 'groups.id' ).joins(:users). - where( 'groups_users.user_id = ?', user.id ). - where( 'groups.active = ?', true ). - map( &:id ) + group_ids = Group.select( 'groups.id' ).joins(:users) + .where( 'groups_users.user_id = ?', user.id ) + .where( 'groups.active = ?', true ) + .map( &:id ) access_condition = [ 'group_id IN (?)', group_ids ] else if !user.organization || ( !user.organization.shared || user.organization.shared == false ) diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index 47c5b95d4..aeb52c6b1 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -108,14 +108,14 @@ returns # @tickets = Ticket.where(:group_id => groups, attributes[:myopenassigned] ).limit(params[:limit]) # get only tickets with permissions if data[:current_user].is_role('Customer') - group_ids = Group.select( 'groups.id' ). - where( 'groups.active = ?', true ). - map( &:id ) + group_ids = Group.select( 'groups.id' ) + .where( 'groups.active = ?', true ) + .map( &:id ) else - group_ids = Group.select( 'groups.id' ).joins(:users). - where( 'groups_users.user_id = ?', [ data[:current_user].id ] ). - where( 'groups.active = ?', true ). - map( &:id ) + group_ids = Group.select( 'groups.id' ).joins(:users) + .where( 'groups_users.user_id = ?', [ data[:current_user].id ] ) + .where( 'groups.active = ?', true ) + .map( &:id ) end # overview meta for navbar @@ -147,20 +147,20 @@ returns if overview_selected.group_by && !overview_selected.group_by.empty? order_by = overview_selected.group_by + '_id, ' + order_by end - tickets = Ticket.select( 'id' ). - where( group_id: group_ids ). - where( _condition( overview_selected.condition ) ). - order( order_by ). - limit( 500 ) + tickets = Ticket.select( 'id' ) + .where( group_id: group_ids ) + .where( _condition( overview_selected.condition ) ) + .order( order_by ) + .limit( 500 ) ticket_ids = [] tickets.each { |ticket| ticket_ids.push ticket.id } - tickets_count = Ticket.where( group_id: group_ids ). - where( _condition( overview_selected.condition ) ). - count() + tickets_count = Ticket.where( group_id: group_ids ) + .where( _condition( overview_selected.condition ) ) + .count() return { ticket_ids: ticket_ids, @@ -171,15 +171,15 @@ returns # get tickets for overview data[:start_page] ||= 1 - tickets = Ticket.where( group_id: group_ids ). - where( _condition( overview_selected.condition ) ). - order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#. + tickets = Ticket.where( group_id: group_ids ) + .where( _condition( overview_selected.condition ) ) + .order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#. # limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ). # offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) ) - tickets_count = Ticket.where( group_id: group_ids ). - where( _condition( overview_selected.condition ) ). - count() + tickets_count = Ticket.where( group_id: group_ids ) + .where( _condition( overview_selected.condition ) ) + .count() { tickets: tickets, diff --git a/lib/core_ext/class.rb b/lib/core_ext/class.rb index 896ad94a8..5cefe4e10 100644 --- a/lib/core_ext/class.rb +++ b/lib/core_ext/class.rb @@ -1,11 +1,11 @@ class Class def to_app_model_url camel_cased_word = self.to_s - camel_cased_word.gsub(/::/, '_'). - gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). - gsub(/([a-z\d])([A-Z])/, '\1_\2'). - tr('-', '_'). - downcase + camel_cased_word.gsub(/::/, '_') + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr('-', '_') + .downcase end def to_app_model camel_cased_word = self.to_s From 21a7a870985e37d204317913d774daa32d561479 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:54:08 +0200 Subject: [PATCH 09/13] Corrected with rubocop cop 'Style/Semicolon'. --- app/models/channel/email_build.rb | 2 +- app/models/observer/tag/ticket_history.rb | 4 ++-- lib/import/otrs.rb | 10 +++++----- lib/import/otrs2.rb | 12 ++++++------ script/websocket-server.rb | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 2b0c6cec6..e801b7547 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -20,7 +20,7 @@ module Channel::EmailBuild # set organization organization = Setting.get('organization') - if organization then; + if organization then mail['Organization'] = organization.to_s end diff --git a/app/models/observer/tag/ticket_history.rb b/app/models/observer/tag/ticket_history.rb index 7645c7551..9daeaf0f5 100644 --- a/app/models/observer/tag/ticket_history.rb +++ b/app/models/observer/tag/ticket_history.rb @@ -8,7 +8,7 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer def after_create(record) # just process ticket object tags - return true if record.tag_object.name != 'Ticket'; + return true if record.tag_object.name != 'Ticket' # add ticket history History.add( @@ -22,7 +22,7 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer def after_destroy(record) # just process ticket object tags - return true if record.tag_object.name != 'Ticket'; + return true if record.tag_object.name != 'Ticket' # add ticket history History.add( diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index ec2fb7456..a17dd3819 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -555,7 +555,7 @@ module Import::OTRS ID: :id, ValidID: :active, Comment: :note, - }; + } Ticket::State.all.each {|state| state.name = state.name + '_tmp' @@ -611,7 +611,7 @@ module Import::OTRS ID: :id, ValidID: :active, Comment: :note, - }; + } result.each { |priority| _set_valid(priority) @@ -655,7 +655,7 @@ module Import::OTRS QueueID: :id, ValidID: :active, Comment: :note, - }; + } result.each { |group| _set_valid(group) @@ -702,7 +702,7 @@ module Import::OTRS UserLastname: :lastname, UserLogin: :login, UserPw: :password, - }; + } result.each { |user| # puts 'USER: ' + user.inspect @@ -770,7 +770,7 @@ module Import::OTRS UserZip: :zip, UserCity: :city, UserCountry: :country, - }; + } done = true result.each { |user| diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 49996a7b2..7da76585f 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -803,7 +803,7 @@ module Import::OTRS2 ID: :id, ValidID: :active, Comment: :note, - }; + } # rename states to handle not uniq issues Ticket::State.all.each {|state| @@ -858,7 +858,7 @@ module Import::OTRS2 ID: :id, ValidID: :active, Comment: :note, - }; + } records.each { |priority| _set_valid(priority) @@ -899,7 +899,7 @@ module Import::OTRS2 QueueID: :id, ValidID: :active, Comment: :note, - }; + } records.each { |group| _set_valid(group) @@ -945,7 +945,7 @@ module Import::OTRS2 UserLastname: :lastname, UserLogin: :login, UserPw: :password, - }; + } records.each { |user| _set_valid(user) @@ -1072,7 +1072,7 @@ module Import::OTRS2 UserZip: :zip, UserCity: :city, UserCountry: :country, - }; + } role_agent = Role.lookup( name: 'Agent' ) role_customer = Role.lookup( name: 'Customer' ) @@ -1142,7 +1142,7 @@ module Import::OTRS2 CustomerCompanyName: :name, ValidID: :active, CustomerCompanyComment: :note, - }; + } records.each { |organization| _set_valid(organization) diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 9501ee119..29c712d37 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -55,7 +55,7 @@ end.parse! if ARGV[0] != 'start' && ARGV[0] != 'stop' puts "Usage: #{File.basename(__FILE__)} start|stop [options]" - exit; + exit end puts "Starting websocket server on #{ @options[:b] }:#{ @options[:p] } (secure:#{ @options[:s].to_s },pid:#{@options[:i].to_s})" From dd4b2b88d1b683d27c0e79296a781ff5d19fc583 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 20:02:52 +0200 Subject: [PATCH 10/13] Corrected with rubocop cop 'Style/TrivialAccessors'. --- lib/user_agent.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 6f3b54b90..3c16769eb 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -386,6 +386,13 @@ returns end class Result + + attr_reader :error + attr_reader :body + attr_reader :data + attr_reader :code + attr_reader :content_type + def initialize(options) @success = options[:success] @body = options[:body] @@ -394,23 +401,9 @@ returns @content_type = options[:content_type] @error = options[:error] end - def error - @error - end + def success? @success end - def body - @body - end - def data - @data - end - def code - @code - end - def content_type - @content_type - end end end From 62b23c963e90d9181db21335e623301f95c3e650 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 20:08:37 +0200 Subject: [PATCH 11/13] Corrected with rubocop cop 'Style/SpaceBeforeBlockBraces'. --- app/models/channel/email_parser.rb | 2 +- lib/sessions.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 1d3862649..57c5c0230 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -526,7 +526,7 @@ class Channel::EmailParser def set_attributes_by_x_headers( item_object, header_name, mail ) # loop all x-zammad-hedaer-* headers - item_object.attributes.each{|key, value| + item_object.attributes.each {|key, value| # ignore read only attributes next if key == 'updated_at' diff --git a/lib/sessions.rb b/lib/sessions.rb index 05b0df90d..7fec193e9 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -576,7 +576,7 @@ returns end def self.symbolize_keys(hash) - hash.inject({}){|result, (key, value)| + hash.inject({}) {|result, (key, value)| new_key = case key when String then key.to_sym else key From 34fdfc70720f745758b51ce012851d0052b059dd Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 20:13:25 +0200 Subject: [PATCH 12/13] Corrected with rubocop cop 'Style/SpaceAroundBlockParameters'. --- app/models/object_manager.rb | 2 +- app/models/ticket/overviews.rb | 2 +- app/models/user/assets.rb | 2 +- lib/auth/ldap.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/object_manager.rb b/app/models/object_manager.rb index 711666bb5..187343c15 100644 --- a/app/models/object_manager.rb +++ b/app/models/object_manager.rb @@ -187,7 +187,7 @@ returns: } if item.screens data[:screen] = {} - item.screens.each {|screen, roles_options | + item.screens.each {|screen, roles_options| data[:screen][screen] = {} roles_options.each {|role, options| if role == '-all-' diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index aeb52c6b1..7488102f6 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -72,7 +72,7 @@ returns end # 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 ) if parts[0] && parts[1] && parts[0] == 'current_user' diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index f9014b87d..962f88d2c 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -35,7 +35,7 @@ returns # get linked accounts attributes['accounts'] = {} authorizations = self.authorizations() - authorizations.each do | authorization | + authorizations.each do |authorization| attributes['accounts'][authorization.provider] = { uid: authorization[:uid], username: authorization[:username] diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index 2994f65c8..b9a13334e 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -64,7 +64,7 @@ module Auth::Ldap source: 'ldap', updated_by_id: 1, } - config[:sync_params].each {| local_data, ldap_data | + config[:sync_params].each {|local_data, ldap_data| if user_data[ ldap_data.downcase.to_sym ] user_attributes[ local_data.downcase.to_sym] = user_data[ ldap_data.downcase.to_sym ] end From 504f8b60197b3504b1cdf49f1f960c62170a92fc Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 20:16:25 +0200 Subject: [PATCH 13/13] Corrected with rubocop cop 'Style/MultilineIfThen'. --- app/models/channel/email_build.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index e801b7547..8633e952e 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -20,7 +20,7 @@ module Channel::EmailBuild # set organization organization = Setting.get('organization') - if organization then + if organization mail['Organization'] = organization.to_s end diff --git a/app/models/user.rb b/app/models/user.rb index 743ec0a8c..198287fcb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -245,7 +245,7 @@ returns def self.create_from_hash!(hash) url = '' - if hash['info']['urls'] then + if hash['info']['urls'] url = hash['info']['urls']['Website'] || hash['info']['urls']['Twitter'] || '' end roles = Role.where( name: 'Customer' )