diff --git a/Gemfile b/Gemfile index 8034211c5..7563fcfdb 100644 --- a/Gemfile +++ b/Gemfile @@ -63,24 +63,24 @@ gem 'em-websocket' group :development, :test do gem 'test-unit' - gem 'spring' - gem 'sqlite3' + gem 'spring' + gem 'sqlite3' - # code coverage - gem 'simplecov' - gem 'simplecov-rcov' + # code coverage + gem 'simplecov' + gem 'simplecov-rcov' - # UI tests w/ Selenium - gem 'selenium-webdriver' + # UI tests w/ Selenium + gem 'selenium-webdriver' - # livereload on template changes (html, js, css) - gem 'guard', '>= 2.2.2', require: false - gem 'guard-livereload', require: false - gem 'rack-livereload' - gem 'rb-fsevent', require: false + # livereload on template changes (html, js, css) + gem 'guard', '>= 2.2.2', require: false + gem 'guard-livereload', require: false + gem 'rack-livereload' + gem 'rb-fsevent', require: false - # code QA - gem 'rubocop' + # code QA + gem 'rubocop' end gem 'puma' diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index f19d7ccb4..f9cffaad5 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -76,7 +76,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # validate url messages = {} if !Setting.get('system_online_service') - if !params[:url] || params[:url] !~ /^(http|https):\/\/.+?$/ + if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} messages[:url] = 'A URL looks like http://zammad.example.com' end end @@ -107,7 +107,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # split url in http_type and fqdn settings = {} if !Setting.get('system_online_service') - if params[:url] =~ /^(http|https):\/\/(.+?)$/ + if params[:url] =~ %r{/^(http|https)://(.+?)$} Setting.set('http_type', $1) settings[:http_type] = $1 Setting.set('fqdn', $2) diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 0e0d49091..fdb3d99c5 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -6,7 +6,7 @@ class ImportOtrsController < ApplicationController return if setup_done_response # validate - if !params[:url] || params[:url] !~ /^(http|https):\/\/.+?$/ + if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} render json: { result: 'invalid', message: 'Invalid!', @@ -44,7 +44,7 @@ class ImportOtrsController < ApplicationController suffixes.each {|suffix| url = params[:url] + suffix + '?Action=ZammadMigrator' # strip multible / in url - url.gsub!(/([^:])(\/+\/)/, '\\1/') + url.gsub!(%r{([^:])(/+/)}, '\\1/') response = UserAgent.request( url ) #Setting.set('import_mode', true) @@ -65,7 +65,7 @@ class ImportOtrsController < ApplicationController # return result render json: { result: 'invalid', - message_human: message_human, + message_human: message_human, } end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e8c66fddb..df2b9aec4 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -55,14 +55,14 @@ class SessionsController < ApplicationController end # return new session data - render json: { - session: user, - models: models, - collections: collections, - assets: assets, - logon_session: logon_session_key, - }, - status: :created + render status: :created, + json: { + session: user, + models: models, + collections: collections, + assets: assets, + logon_session: logon_session_key, + } end def show diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index d5806acc9..582a79e77 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -99,12 +99,12 @@ 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 ) + .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 ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) end list = [] stream.each do |item| diff --git a/app/models/application_model.rb b/app/models/application_model.rb index e2e50d9c8..f7ea1325b 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -606,8 +606,8 @@ class OwnModel < ApplicationModel class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( - :event => class_name + ':touch', - :data => { :id => self.id, :updated_at => self.updated_at } + event: class_name + ':touch', + data: { id: self.id, updated_at: self.updated_at } ) end diff --git a/app/models/application_model/search_index_base.rb b/app/models/application_model/search_index_base.rb index 41a253f19..be0b22ac6 100644 --- a/app/models/application_model/search_index_base.rb +++ b/app/models/application_model/search_index_base.rb @@ -81,7 +81,7 @@ returns attributes end - private + private =begin diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 4e8d8cb96..963460a0f 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -110,7 +110,7 @@ add a avatar # twitter workaround to get bigger avatar images # see also https://dev.twitter.com/overview/general/user-profile-images-and-banners - if data[:url] =~ /\/\/pbs.twimg.com\//i + if data[:url] =~ %r{//pbs.twimg.com/}i data[:url].sub!(/normal\.png$/, 'bigger.png') end diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 57c5c0230..33a5f3e90 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -103,7 +103,7 @@ class Channel::EmailParser data[:from_local] = Mail::Address.new( from ).local data[:from_domain] = Mail::Address.new( from ).domain data[:from_display_name] = Mail::Address.new( from ).display_name || - ( Mail::Address.new( from ).comments && Mail::Address.new( from ).comments[0] ) + ( Mail::Address.new( from ).comments && Mail::Address.new( from ).comments[0] ) rescue data[:from_email] = from data[:from_local] = from diff --git a/app/models/history.rb b/app/models/history.rb index f3de58535..65bca3295 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -151,8 +151,8 @@ returns 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') + .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 ) diff --git a/app/models/job.rb b/app/models/job.rb index 4bf4b7d45..7a3386e7f 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -43,8 +43,8 @@ class Job < ApplicationModel # find tickets to change tickets = Ticket.where( job.condition.permit! ) - .order( '`tickets`.`created_at` DESC' ) - .limit( 1_000 ) + .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/link.rb b/app/models/link.rb index b7b5e744b..2c541da3d 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -152,6 +152,7 @@ class Link < ApplicationModel end private + def self.link_type_get(data) linktype = Link::Type.where( name: data[:name] ).first if !linktype diff --git a/app/models/observer/ticket/close_time.rb b/app/models/observer/ticket/close_time.rb index 30cdc5929..1ce45ee1b 100644 --- a/app/models/observer/ticket/close_time.rb +++ b/app/models/observer/ticket/close_time.rb @@ -12,6 +12,7 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer end private + def _check(record) # puts 'check close time' diff --git a/app/models/observer/ticket/last_contact.rb b/app/models/observer/ticket/last_contact.rb index 0bc8e7682..f7418b05e 100644 --- a/app/models/observer/ticket/last_contact.rb +++ b/app/models/observer/ticket/last_contact.rb @@ -18,8 +18,10 @@ class Observer::Ticket::LastContact < ActiveRecord::Observer # check if last communication is done by agent, else do not set last_contact_customer if record.ticket.last_contact_customer == nil || - record.ticket.last_contact_agent == nil || - record.ticket.last_contact_agent.to_i > record.ticket.last_contact_customer.to_i + record.ticket.last_contact_agent == nil || + record.ticket.last_contact_agent.to_i > record.ticket.last_contact_customer.to_i + + # set last_contact customer record.ticket.last_contact_customer = record.created_at # set last_contact diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index e1a97d63b..e320bfed1 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -70,7 +70,7 @@ class Observer::Ticket::Notification::BackgroundJob object: 'Ticket', o_id: ticket.id, seen: seen, - created_by_id: ticket.updated_by_id ||  1, + created_by_id: ticket.updated_by_id || 1, user_id: user.id, ) @@ -135,7 +135,7 @@ class Observer::Ticket::Notification::BackgroundJob history_type: 'notification', history_object: 'Ticket', value_to: recipient_list, - created_by_id: ticket.updated_by_id ||  1 + created_by_id: ticket.updated_by_id || 1 ) end diff --git a/app/models/observer/ticket/online_notification_seen.rb b/app/models/observer/ticket/online_notification_seen.rb index 4516a7ca7..2872bba29 100644 --- a/app/models/observer/ticket/online_notification_seen.rb +++ b/app/models/observer/ticket/online_notification_seen.rb @@ -12,6 +12,7 @@ class Observer::Ticket::OnlineNotificationSeen < ActiveRecord::Observer end private + def _check(record) # return if we run import mode diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index baa9e6f66..53ad3a120 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -57,8 +57,8 @@ mark online notification as seen def self.seen(data) notification = OnlineNotification.find(data[:id]) - notification.seen = true - notification.save + notification.seen = true + notification.save end =begin @@ -88,8 +88,8 @@ 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 ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) list = [] notifications.each do |item| data = item.attributes @@ -116,8 +116,9 @@ return all online notifications of an object 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/package.rb b/app/models/package.rb index 0b01ee5c1..a54ff89c3 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -47,7 +47,7 @@ class Package < ApplicationModel # install all packages located under auto_install/*.zpm def self.auto_install path = @@root + '/auto_install/' - return if ! File.exist?( path ) + return if !File.exist?( path ) data = [] Dir.foreach( path ) do |entry| if entry =~ /\.zpm/ && entry !~ /^\./ @@ -82,7 +82,7 @@ class Package < ApplicationModel def self._package_base_dir?(package_base_dir) package = false Dir.glob( package_base_dir + '/*.szpm') do |entry| - package = entry.sub( /^.*\/(.+?)\.szpm$/, '\1') + package = entry.sub( %r{^.*/(.+?)\.szpm$}, '\1') end if package == false raise "Can't link package, '#{package_base_dir}' is no package source directory!" @@ -133,7 +133,7 @@ class Package < ApplicationModel entry = entry.sub( '//', '/' ) file = entry file = file.sub( /#{package_base_dir.to_s}/, '' ) - file = file.sub( /^\//, '' ) + file = file.sub( %r{^/}, '' ) # ignore files if file =~ /^README/ diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 9c3c3915d..5db403034 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -38,12 +38,12 @@ 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) + .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) + .order('created_at DESC, id DESC') + .limit(limit) end list = [] diff --git a/app/models/setting.rb b/app/models/setting.rb index 57dbb7efe..7854ef336 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -51,6 +51,7 @@ class Setting < ApplicationModel end private + def delete_cache @@current[:settings_config] = nil end diff --git a/app/models/sla.rb b/app/models/sla.rb index 070beb4bc..e590fe8c6 100644 --- a/app/models/sla.rb +++ b/app/models/sla.rb @@ -10,6 +10,7 @@ class Sla < ApplicationModel after_destroy :escalation_calculation_rebuild private + def escalation_calculation_rebuild Cache.delete( 'SLA::List::Active' ) Ticket::Escalation.rebuild_all diff --git a/app/models/store.rb b/app/models/store.rb index f907efebc..d943ae969 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -81,7 +81,7 @@ returns # 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') + .order('created_at ASC, id ASC') stores end @@ -104,8 +104,8 @@ returns # 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') + .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/store/provider/file.rb b/app/models/store/provider/file.rb index 5cef6bc93..b127d784f 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -24,8 +24,8 @@ class Store::Provider::File # generate directory base = Rails.root.to_s + '/storage/fs/' parts = sha.scan(/.{1,4}/) - path = parts[ 1 .. 10 ].join('/') + '/' - file = parts[ 11 .. parts.count ].join('') + path = parts[ 1..10 ].join('/') + '/' + file = parts[ 11..parts.count ].join('') location = "#{base}/#{path}" # create directory if not exists diff --git a/app/models/taskbar.rb b/app/models/taskbar.rb index 3d707221d..1349fd074 100644 --- a/app/models/taskbar.rb +++ b/app/models/taskbar.rb @@ -7,6 +7,7 @@ class Taskbar < ApplicationModel before_update :update_last_contact, :set_user private + def update_last_contact self.last_contact = Time.now end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 9698eebd1..c21c1e47e 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -95,9 +95,9 @@ returns 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 ) + .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 7488102f6..36bd20290 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -109,13 +109,13 @@ returns # get only tickets with permissions if data[:current_user].is_role('Customer') group_ids = Group.select( 'groups.id' ) - .where( 'groups.active = ?', true ) - .map( &: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 ) + .where( 'groups_users.user_id = ?', [ data[:current_user].id ] ) + .where( 'groups.active = ?', true ) + .map( &:id ) end # overview meta for navbar @@ -148,10 +148,10 @@ returns 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 ) + .where( group_id: group_ids ) + .where( _condition( overview_selected.condition ) ) + .order( order_by ) + .limit( 500 ) ticket_ids = [] tickets.each { |ticket| @@ -159,8 +159,8 @@ returns } tickets_count = Ticket.where( group_id: group_ids ) - .where( _condition( overview_selected.condition ) ) - .count() + .where( _condition( overview_selected.condition ) ) + .count() return { ticket_ids: ticket_ids, @@ -172,14 +172,14 @@ 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 )#. - # 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 ) ) + .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() + .where( _condition( overview_selected.condition ) ) + .count() { tickets: tickets, diff --git a/app/models/token.rb b/app/models/token.rb index ff615d0aa..518dc66d3 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -13,7 +13,7 @@ class Token < ActiveRecord::Base # check if token is still valid if !token.persistent && - token.created_at < 1.day.ago + token.created_at < 1.day.ago # delete token token.delete @@ -26,6 +26,7 @@ class Token < ActiveRecord::Base end private + def generate_token begin self.name = SecureRandom.hex(20) diff --git a/app/models/translation.rb b/app/models/translation.rb index d748bbc80..acbe94bac 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -167,6 +167,7 @@ translate strings in ruby context, e. g. for notifications end private + def set_initial return if target_initial diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index 7dae03766..c4e73b2f4 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -83,10 +83,10 @@ class String string.gsub!( /^\s*/m, '' ) # pre/code handling 1/2 - string.gsub!( /
(.+?)<\/pre>/m ) { |placeholder|
+    string.gsub!( %r{
(.+?)
}m ) { |placeholder| placeholder = placeholder.gsub(/\n/, '###BR###') } - string.gsub!( /(.+?)<\/code>/m ) { |placeholder| + string.gsub!( %r{(.+?)/}m ) { |placeholder| placeholder = placeholder.gsub(/\n/, '###BR###') } @@ -103,12 +103,12 @@ class String string.gsub!(/]*)>/i, '> ') # add hr - string.gsub!(/]*)>/i, "___\n") + string.gsub!(%r{]*)>}i, "___\n") # add new lines - string.gsub!( /\<(br|table)(|\/| [^>]*)\>/i, "\n" ) - string.gsub!( /\<\/(div|p|pre|blockquote|table|tr)(|\s.+?)\>/i, "\n" ) - string.gsub!( /\<\/td\>/i, ' ' ) + string.gsub!( %r{\<(br|table)(|/| [^>]*)\>}i, "\n" ) + string.gsub!( %r{\}i, "\n" ) + string.gsub!( %r{/}i, ' ' ) # strip all other tags string.gsub!( /\<.+?\>/, '' ) diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index a17dd3819..f28fc0e3b 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -352,7 +352,7 @@ module Import::OTRS if !user begin display_name = Mail::Address.new( article_new[:from] ).display_name || - ( Mail::Address.new( article_new[:from] ).comments && Mail::Address.new( article_new[:from] ).comments[0] ) + ( Mail::Address.new( article_new[:from] ).comments && Mail::Address.new( article_new[:from] ).comments[0] ) rescue display_name = article_new[:from] end diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 175f7296c..b7ef5156a 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -1004,7 +1004,7 @@ module Import::OTRS2 if group_lookup['Name'] == 'admin' && permissions && permissions.include?('rw') roles.push 'Admin' end - if group_lookup['Name'] =~ /^(stats|report)/ && permissions && ( permissions.include?('ro') ||  permissions.include?('rw') ) + if group_lookup['Name'] =~ /^(stats|report)/ && permissions && ( permissions.include?('ro') || permissions.include?('rw') ) roles.push 'Report' end end @@ -1296,7 +1296,7 @@ module Import::OTRS2 # unlock user locks[:User][ email ] = false - + true end diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 3c16769eb..b29e9ab2e 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -241,6 +241,7 @@ returns end private + def self.get_http(uri, options) http = Net::HTTP.new(uri.host, uri.port)