From 19feb32c7b6e5c23c7c356fec1ec9bf6109fb027 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:14:51 +0200 Subject: [PATCH] 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