From 5f3c793f373e3f508395893801ba8064303da2ae Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 26 Apr 2018 10:55:53 +0200 Subject: [PATCH] Refactoring: Fixed autoloading issues and workarounds by doing dependency requirement the "Rails Way". - Removed unneeded `require`s - Replaced needed `require`s with `require_dependency` - Replaced `load` with Concers - Kept gem and core `require`s Read more about ``nrequire_dependency here: http://guides.rubyonrails.org/autoloading_and_reloading_constants.html#require-dependency Read more about Concerns here: http://api.rubyonrails.org/v5.1/classes/ActiveSupport/Concern.html --- app/controllers/application_controller.rb | 2 - .../calendar_subscriptions_controller.rb | 3 - app/controllers/getting_started_controller.rb | 3 - app/controllers/import_zendesk_controller.rb | 2 - .../integration/ldap_controller.rb | 6 +- .../integration/sipgate_controller.rb | 1 - app/controllers/reports_controller.rb | 3 - .../ticket_overviews_controller.rb | 3 - app/models/activity_stream.rb | 2 - app/models/activity_stream/assets.rb | 1 + app/models/channel.rb | 1 - app/models/channel/assets.rb | 1 + app/models/channel/driver/facebook.rb | 7 +- app/models/channel/driver/imap.rb | 3 +- app/models/channel/driver/pop3.rb | 2 +- app/models/channel/email_build.rb | 3 - app/models/channel/email_parser.rb | 3 - app/models/chat/session.rb | 4 +- app/models/chat/session/assets.rb | 1 + app/models/chat/session/search.rb | 70 +++---- app/models/chat/session/search_index.rb | 29 +-- app/models/concerns/can_csv_import.rb | 5 +- app/models/history.rb | 1 - app/models/history/assets.rb | 1 + app/models/job.rb | 1 - app/models/job/assets.rb | 1 + app/models/observer/session.rb | 3 - app/models/observer/tag/ticket_history.rb | 3 - .../ticket/article/communicate_facebook.rb | 3 - app/models/observer/ticket/stats_reopen.rb | 3 +- app/models/online_notification.rb | 1 - app/models/online_notification/assets.rb | 1 + app/models/organization.rb | 6 +- app/models/organization/assets.rb | 1 + app/models/organization/search.rb | 115 +++++------ app/models/organization/search_index.rb | 1 + app/models/overview.rb | 1 - app/models/overview/assets.rb | 1 + app/models/recent_view.rb | 1 - app/models/recent_view/assets.rb | 1 + app/models/role.rb | 1 - app/models/role/assets.rb | 1 + app/models/sla.rb | 1 - app/models/sla/assets.rb | 1 + app/models/store.rb | 6 +- app/models/store/file.rb | 2 +- app/models/store/object.rb | 2 +- app/models/ticket.rb | 4 +- app/models/ticket/article.rb | 3 +- app/models/ticket/article/assets.rb | 1 + app/models/ticket/assets.rb | 1 + app/models/ticket/search.rb | 187 +++++++++--------- app/models/ticket/search_index.rb | 1 + .../transaction/cti_caller_id_detection.rb | 2 - app/models/transaction/signature_detection.rb | 6 +- app/models/trigger.rb | 1 - app/models/trigger/assets.rb | 1 + app/models/user.rb | 30 +-- app/models/user/assets.rb | 1 + app/models/user/search.rb | 115 +++++------ app/models/user/search_index.rb | 2 +- lib/auth/ldap.rb | 4 +- lib/encode.rb | 1 - lib/facebook.rb | 2 - lib/import/exchange/folder.rb | 2 +- lib/import/ldap.rb | 4 +- lib/import/otrs.rb | 36 ++-- lib/import/otrs/dynamic_field/date.rb | 2 +- lib/import/otrs/dynamic_field/date_time.rb | 2 +- lib/import/otrs/ticket.rb | 2 +- .../zendesk/object_attribute/checkbox.rb | 2 +- lib/import/zendesk/object_attribute/date.rb | 2 +- .../zendesk/object_attribute/integer.rb | 2 +- lib/import/zendesk/object_attribute/regexp.rb | 2 +- lib/import/zendesk/object_attribute/select.rb | 2 +- lib/import/zendesk/object_attribute/text.rb | 2 +- .../zendesk/object_attribute/textarea.rb | 2 +- lib/ldap.rb | 4 +- lib/ldap/group.rb | 8 +- lib/ldap/user.rb | 8 +- .../ldap_samaccountname_to_uid.rb | 4 +- lib/sequencer.rb | 4 +- lib/sequencer/sequence.rb | 2 +- lib/sequencer/state.rb | 4 +- lib/sequencer/unit.rb | 2 +- lib/sequencer/unit/base.rb | 2 +- .../common/model/associations/assign.rb | 2 +- .../unit/import/common/model/save.rb | 2 +- .../import/common/model/skip/blank/base.rb | 2 +- .../model/skip/missing_mandatory/base.rb | 2 +- .../model/statistics/diff/custom_key.rb | 3 +- .../common/model/statistics/diff/model_key.rb | 2 +- .../common/model/statistics/diff/top_level.rb | 2 +- .../model/statistics/mixin/action_diff.rb | 2 +- .../model/statistics/mixin/empty_diff.rb | 2 +- .../unit/import/ldap/user/model/save.rb | 2 +- .../unit/import/ldap/user/statistics/diff.rb | 2 +- .../import/ldap/users/lost/statistics_diff.rb | 2 +- .../unit/import/ldap/users/sub_sequence.rb | 2 +- lib/sequencer/unit/import/ldap/users/total.rb | 2 +- .../unit/import/ldap/users/user_roles.rb | 4 +- lib/sequencer/unit/ldap/config.rb | 2 +- lib/sequencer/unit/ldap/connection.rb | 2 +- lib/sequencer/units.rb | 4 +- lib/service/geo_calendar/zammad.rb | 8 +- lib/service/geo_ip/zammad.rb | 8 +- lib/sessions.rb | 3 - lib/stats.rb | 3 - lib/tweet_base.rb | 3 +- lib/twitter/streaming/client_custom.rb | 2 +- lib/user_agent.rb | 1 - 111 files changed, 394 insertions(+), 451 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a2a6a6343..947a8e865 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'exceptions' - class ApplicationController < ActionController::Base include ApplicationController::HandlesErrors include ApplicationController::HandlesDevices diff --git a/app/controllers/calendar_subscriptions_controller.rb b/app/controllers/calendar_subscriptions_controller.rb index 82e81fe7d..d922d7949 100644 --- a/app/controllers/calendar_subscriptions_controller.rb +++ b/app/controllers/calendar_subscriptions_controller.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/ - -require 'icalendar' - class CalendarSubscriptionsController < ApplicationController prepend_before_action { authentication_check( { basic_auth_promt: true, permission: 'user_preferences.calendar' } ) } diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index 989f172f3..2d1cf73ba 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'resolv' - class GettingStartedController < ApplicationController =begin diff --git a/app/controllers/import_zendesk_controller.rb b/app/controllers/import_zendesk_controller.rb index c3ee3587c..11d24cf2e 100644 --- a/app/controllers/import_zendesk_controller.rb +++ b/app/controllers/import_zendesk_controller.rb @@ -1,6 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'zendesk_api' - class ImportZendeskController < ApplicationController def url_check diff --git a/app/controllers/integration/ldap_controller.rb b/app/controllers/integration/ldap_controller.rb index 80ddb62c0..5f916f6df 100644 --- a/app/controllers/integration/ldap_controller.rb +++ b/app/controllers/integration/ldap_controller.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'ldap' -require 'ldap/user' -require 'ldap/group' +require_dependency 'ldap' +require_dependency 'ldap/user' +require_dependency 'ldap/group' class Integration::LdapController < ApplicationController include Integration::ImportJobBase diff --git a/app/controllers/integration/sipgate_controller.rb b/app/controllers/integration/sipgate_controller.rb index 8f4a3323c..5aef8f4d8 100644 --- a/app/controllers/integration/sipgate_controller.rb +++ b/app/controllers/integration/sipgate_controller.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - require 'builder' class Integration::SipgateController < ApplicationController diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 70220f0ec..2e8ede57f 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'tempfile' - class ReportsController < ApplicationController prepend_before_action { authentication_check(permission: 'report') } diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index 58e3a774d..eede33cd2 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'ticket/overviews' - class TicketOverviewsController < ApplicationController prepend_before_action :authentication_check diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 31d75d665..ddbb536bf 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - class ActivityStream < ApplicationModel - load 'activity_stream/assets.rb' include ActivityStream::Assets self.table_name = 'activity_streams' diff --git a/app/models/activity_stream/assets.rb b/app/models/activity_stream/assets.rb index a08f9043b..a8a8aab3b 100644 --- a/app/models/activity_stream/assets.rb +++ b/app/models/activity_stream/assets.rb @@ -2,6 +2,7 @@ class ActivityStream module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/channel.rb b/app/models/channel.rb index 4e0d62477..0ecd2953e 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class Channel < ApplicationModel - load 'channel/assets.rb' include Channel::Assets belongs_to :group diff --git a/app/models/channel/assets.rb b/app/models/channel/assets.rb index f6f7af0b3..c181cbb2c 100644 --- a/app/models/channel/assets.rb +++ b/app/models/channel/assets.rb @@ -2,6 +2,7 @@ class Channel module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/channel/driver/facebook.rb b/app/models/channel/driver/facebook.rb index af4f2e8ca..b56b39a66 100644 --- a/app/models/channel/driver/facebook.rb +++ b/app/models/channel/driver/facebook.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/ - -require 'facebook' - class Channel::Driver::Facebook =begin @@ -38,7 +35,7 @@ class Channel::Driver::Facebook if !access_token raise "No access_token found for fb_object_id: #{fb_object_id}" end - client = Facebook.new(access_token) + client = ::Facebook.new(access_token) client.from_article(article) end @@ -96,7 +93,7 @@ returns page = get_page(page_to_sync_id) next if !page next if page_to_sync_params['group_id'].blank? - page_client = Facebook.new(page['access_token']) + page_client = ::Facebook.new(page['access_token']) posts = page_client.client.get_connection('me', 'feed', fields: 'id,from,to,message,created_time,permalink_url,comments{id,from,to,message,created_time}') posts.each do |post| diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index ba24dfff7..68b42da9f 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - require 'net/imap' class Channel::Driver::Imap < Channel::EmailParser @@ -101,7 +100,7 @@ example end Timeout.timeout(timeout) do - @imap = Net::IMAP.new(options[:host], port, ssl, nil, false) + @imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false) if starttls @imap.starttls() end diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index 4b5542709..549a678d9 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -62,7 +62,7 @@ returns Rails.logger.info "fetching pop3 (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl})" - @pop = Net::POP3.new(options[:host], port) + @pop = ::Net::POP3.new(options[:host], port) #@pop.set_debug_output $stderr # on check, reduce open_timeout to have faster probing diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 86df788f1..7e6a4aad5 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'mail' - module Channel::EmailBuild =begin diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 86ad4c7d3..f66f51138 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -2,9 +2,6 @@ # encoding: utf-8 -require 'mail' -require 'encode' - class Channel::EmailParser =begin diff --git a/app/models/chat/session.rb b/app/models/chat/session.rb index 93c42223f..789665634 100644 --- a/app/models/chat/session.rb +++ b/app/models/chat/session.rb @@ -2,10 +2,8 @@ class Chat::Session < ApplicationModel include HasSearchIndexBackend include HasTags - extend Chat::Session::Search - load 'chat/session/search_index.rb' + include Chat::Session::Search include Chat::Session::SearchIndex - load 'chat/session/assets.rb' include Chat::Session::Assets # rubocop:disable Rails/InverseOf diff --git a/app/models/chat/session/assets.rb b/app/models/chat/session/assets.rb index 6410e2692..492bb355c 100644 --- a/app/models/chat/session/assets.rb +++ b/app/models/chat/session/assets.rb @@ -1,5 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Chat::Session::Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/chat/session/search.rb b/app/models/chat/session/search.rb index 240793a10..ef77f7050 100644 --- a/app/models/chat/session/search.rb +++ b/app/models/chat/session/search.rb @@ -1,7 +1,10 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - class Chat::Session module Search + extend ActiveSupport::Concern + + # methods defined here are going to extend the class, not the instance of it + class_methods do =begin @@ -22,13 +25,13 @@ returns if user has no permissions to search =end - def search_preferences(current_user) - return false if Setting.get('chat') != true || !current_user.permissions?('chat.agent') - { - prio: 900, - direct_search_index: true, - } - end + def search_preferences(current_user) + return false if Setting.get('chat') != true || !current_user.permissions?('chat.agent') + { + prio: 900, + direct_search_index: true, + } + end =begin @@ -47,36 +50,37 @@ returns =end - def search(params) + def search(params) - # get params - query = params[:query] - limit = params[:limit] || 10 - offset = params[:offset] || 0 - current_user = params[:current_user] + # get params + query = params[:query] + limit = params[:limit] || 10 + offset = params[:offset] || 0 + current_user = params[:current_user] - # enable search only for agents and admins - return [] if !search_preferences(current_user) + # enable search only for agents and admins + return [] if !search_preferences(current_user) - # try search index backend - if SearchIndexBackend.enabled? - items = SearchIndexBackend.search(query, limit, 'Chat::Session', {}, offset) - chat_sessions = [] - items.each do |item| - chat_session = Chat::Session.lookup(id: item[:id]) - next if !chat_session - chat_sessions.push chat_session + # try search index backend + if SearchIndexBackend.enabled? + items = SearchIndexBackend.search(query, limit, 'Chat::Session', {}, offset) + chat_sessions = [] + items.each do |item| + chat_session = Chat::Session.lookup(id: item[:id]) + next if !chat_session + chat_sessions.push chat_session + end + return chat_sessions end - return chat_sessions - end - # fallback do sql query - # - stip out * we already search for *query* - - query.delete! '*' - chat_sessions = Chat::Session.where( - 'name LIKE ?', "%#{query}%" - ).order('name').offset(offset).limit(limit).to_a - chat_sessions + # fallback do sql query + # - stip out * we already search for *query* - + query.delete! '*' + chat_sessions = Chat::Session.where( + 'name LIKE ?', "%#{query}%" + ).order('name').offset(offset).limit(limit).to_a + chat_sessions + end end end end diff --git a/app/models/chat/session/search_index.rb b/app/models/chat/session/search_index.rb index b81196722..7ed607b39 100644 --- a/app/models/chat/session/search_index.rb +++ b/app/models/chat/session/search_index.rb @@ -1,5 +1,9 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Chat::Session::SearchIndex + extend ActiveSupport::Concern + + # methods defined here are going to extend the class, not the instance of it + class_methods do =begin @@ -14,23 +18,24 @@ returns =end - def search_index_attribute_lookup - attributes = super - return if !attributes + def search_index_attribute_lookup + attributes = super + return if !attributes - attributes[:tag] = tag_list + attributes[:tag] = tag_list - messages = Chat::Message.where(chat_session_id: id) - attributes['messages'] = [] - messages.each do |message| + messages = Chat::Message.where(chat_session_id: id) + attributes['messages'] = [] + messages.each do |message| - # lookup attributes of ref. objects (normally name and note) - message_attributes = message.search_index_attribute_lookup + # lookup attributes of ref. objects (normally name and note) + message_attributes = message.search_index_attribute_lookup - attributes['messages'].push message_attributes + attributes['messages'].push message_attributes + end + + attributes end - - attributes end end diff --git a/app/models/concerns/can_csv_import.rb b/app/models/concerns/can_csv_import.rb index 273f013a3..debf03bf2 100644 --- a/app/models/concerns/can_csv_import.rb +++ b/app/models/concerns/can_csv_import.rb @@ -1,4 +1,5 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ + require 'csv' module CanCsvImport @@ -58,7 +59,7 @@ returns raise Exceptions::UnprocessableEntity, 'Unable to parse empty file/string!' end - rows = CSV.parse(data[:string], data[:parse_params]) + rows = ::CSV.parse(data[:string], data[:parse_params]) header = rows.shift if header.blank? raise Exceptions::UnprocessableEntity, 'Unable to parse file/string without header!' @@ -301,7 +302,7 @@ returns end rows_to_add = [] end - CSV.generate(params) do |csv| + ::CSV.generate(params) do |csv| csv << header rows.each do |row| csv << row diff --git a/app/models/history.rb b/app/models/history.rb index f2ff24c19..15fae7bc8 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class History < ApplicationModel - load 'history/assets.rb' include History::Assets self.table_name = 'histories' diff --git a/app/models/history/assets.rb b/app/models/history/assets.rb index 488f1f412..8ab711212 100644 --- a/app/models/history/assets.rb +++ b/app/models/history/assets.rb @@ -2,6 +2,7 @@ class History module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/job.rb b/app/models/job.rb index 46ce7a6b4..45556f116 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -4,7 +4,6 @@ class Job < ApplicationModel include ChecksClientNotification include ChecksConditionValidation - load 'job/assets.rb' include Job::Assets store :timeplan diff --git a/app/models/job/assets.rb b/app/models/job/assets.rb index 3e0c0a656..7593594f2 100644 --- a/app/models/job/assets.rb +++ b/app/models/job/assets.rb @@ -2,6 +2,7 @@ class Job module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/observer/session.rb b/app/models/observer/session.rb index 9a8e24dd7..05afc249e 100644 --- a/app/models/observer/session.rb +++ b/app/models/observer/session.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'history' - class Observer::Session < ActiveRecord::Observer observe 'active_record::_session_store::_session' diff --git a/app/models/observer/tag/ticket_history.rb b/app/models/observer/tag/ticket_history.rb index 3cdaf8e17..0336a5d3f 100644 --- a/app/models/observer/tag/ticket_history.rb +++ b/app/models/observer/tag/ticket_history.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'history' - class Observer::Tag::TicketHistory < ActiveRecord::Observer observe 'tag' diff --git a/app/models/observer/ticket/article/communicate_facebook.rb b/app/models/observer/ticket/article/communicate_facebook.rb index 0285f7de9..0eb4d60d4 100644 --- a/app/models/observer/ticket/article/communicate_facebook.rb +++ b/app/models/observer/ticket/article/communicate_facebook.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'channel/driver/facebook' - class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer observe 'ticket::_article' diff --git a/app/models/observer/ticket/stats_reopen.rb b/app/models/observer/ticket/stats_reopen.rb index 408e3cd48..cead581d3 100644 --- a/app/models/observer/ticket/stats_reopen.rb +++ b/app/models/observer/ticket/stats_reopen.rb @@ -1,7 +1,8 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ +require_dependency 'stats/ticket_reopen' + class Observer::Ticket::StatsReopen < ActiveRecord::Observer - load 'stats/ticket_reopen.rb' observe 'ticket' diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index ae05ed875..56c5eeaf7 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class OnlineNotification < ApplicationModel - load 'online_notification/assets.rb' include OnlineNotification::Assets belongs_to :user diff --git a/app/models/online_notification/assets.rb b/app/models/online_notification/assets.rb index 68e50a234..b803ca668 100644 --- a/app/models/online_notification/assets.rb +++ b/app/models/online_notification/assets.rb @@ -2,6 +2,7 @@ class OnlineNotification module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/organization.rb b/app/models/organization.rb index d75f7b4b4..3c2f8c45a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -7,12 +7,10 @@ class Organization < ApplicationModel include HasHistory include HasSearchIndexBackend include CanCsvImport - include Organization::ChecksAccess - load 'organization/assets.rb' + include Organization::ChecksAccess include Organization::Assets - extend Organization::Search - load 'organization/search_index.rb' + include Organization::Search include Organization::SearchIndex # rubocop:disable Rails/InverseOf diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb index 4709ef454..81636cabc 100644 --- a/app/models/organization/assets.rb +++ b/app/models/organization/assets.rb @@ -2,6 +2,7 @@ class Organization module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/organization/search.rb b/app/models/organization/search.rb index e6107536e..27fc92b50 100644 --- a/app/models/organization/search.rb +++ b/app/models/organization/search.rb @@ -2,6 +2,10 @@ class Organization module Search + extend ActiveSupport::Concern + + # methods defined here are going to extend the class, not the instance of it + class_methods do =begin @@ -22,13 +26,13 @@ returns if user has no permissions to search =end - def search_preferences(current_user) - return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.organization') - { - prio: 1000, - direct_search_index: true, - } - end + def search_preferences(current_user) + return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.organization') + { + prio: 1000, + direct_search_index: true, + } + end =begin @@ -47,60 +51,61 @@ returns =end - def search(params) + def search(params) - # get params - query = params[:query] - limit = params[:limit] || 10 - offset = params[:offset] || 0 - current_user = params[:current_user] + # get params + query = params[:query] + limit = params[:limit] || 10 + offset = params[:offset] || 0 + current_user = params[:current_user] - # enable search only for agents and admins - return [] if !search_preferences(current_user) + # enable search only for agents and admins + return [] if !search_preferences(current_user) - # try search index backend - if SearchIndexBackend.enabled? - items = SearchIndexBackend.search(query, limit, 'Organization', {}, offset) - organizations = [] - items.each do |item| - organization = Organization.lookup(id: item[:id]) - next if !organization - organizations.push organization - end - return organizations - end - - # fallback do sql query - # - stip out * we already search for *query* - - query.delete! '*' - organizations = Organization.where( - 'name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%" - ).order('name').offset(offset).limit(limit).to_a - - # use result independent of size if an explicit offset is given - # this is the case for e.g. paginated searches - return organizations if params[:offset].present? - return organizations if organizations.length > 3 - - # if only a few organizations are found, search for names of users - organizations_by_user = Organization.select('DISTINCT(organizations.id), organizations.name').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').where( - 'users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%" - ).order('organizations.name').limit(limit) - - organizations_by_user.each do |organization_by_user| - - organization_exists = false - organizations.each do |organization| - next if organization.id != organization_by_user.id - organization_exists = true - break + # try search index backend + if SearchIndexBackend.enabled? + items = SearchIndexBackend.search(query, limit, 'Organization', {}, offset) + organizations = [] + items.each do |item| + organization = Organization.lookup(id: item[:id]) + next if !organization + organizations.push organization + end + return organizations end - # get model with full data - next if organization_exists - organizations.push Organization.find(organization_by_user.id) + # fallback do sql query + # - stip out * we already search for *query* - + query.delete! '*' + organizations = Organization.where( + 'name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%" + ).order('name').offset(offset).limit(limit).to_a + + # use result independent of size if an explicit offset is given + # this is the case for e.g. paginated searches + return organizations if params[:offset].present? + return organizations if organizations.length > 3 + + # if only a few organizations are found, search for names of users + organizations_by_user = Organization.select('DISTINCT(organizations.id), organizations.name').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').where( + 'users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%" + ).order('organizations.name').limit(limit) + + organizations_by_user.each do |organization_by_user| + + organization_exists = false + organizations.each do |organization| + next if organization.id != organization_by_user.id + organization_exists = true + break + end + + # get model with full data + next if organization_exists + organizations.push Organization.find(organization_by_user.id) + end + organizations end - organizations end end end diff --git a/app/models/organization/search_index.rb b/app/models/organization/search_index.rb index d52df059f..139b1b43b 100644 --- a/app/models/organization/search_index.rb +++ b/app/models/organization/search_index.rb @@ -2,6 +2,7 @@ class Organization module SearchIndex + extend ActiveSupport::Concern =begin diff --git a/app/models/overview.rb b/app/models/overview.rb index d45140736..7f731f059 100644 --- a/app/models/overview.rb +++ b/app/models/overview.rb @@ -6,7 +6,6 @@ class Overview < ApplicationModel include ChecksConditionValidation include CanSeed - load 'overview/assets.rb' include Overview::Assets has_and_belongs_to_many :roles, after_add: :cache_update, after_remove: :cache_update, class_name: 'Role' diff --git a/app/models/overview/assets.rb b/app/models/overview/assets.rb index bccb2440e..f18830140 100644 --- a/app/models/overview/assets.rb +++ b/app/models/overview/assets.rb @@ -2,6 +2,7 @@ class Overview module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 9d6363cf9..e02e3af82 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class RecentView < ApplicationModel - load 'recent_view/assets.rb' include RecentView::Assets # rubocop:disable Rails/InverseOf diff --git a/app/models/recent_view/assets.rb b/app/models/recent_view/assets.rb index 63817f377..7e1cca223 100644 --- a/app/models/recent_view/assets.rb +++ b/app/models/recent_view/assets.rb @@ -2,6 +2,7 @@ class RecentView module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/role.rb b/app/models/role.rb index 743a3fc06..97027b0ce 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -6,7 +6,6 @@ class Role < ApplicationModel include ChecksLatestChangeObserved include HasGroups - load 'role/assets.rb' include Role::Assets has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update diff --git a/app/models/role/assets.rb b/app/models/role/assets.rb index ab8d03bd2..c7634ca06 100644 --- a/app/models/role/assets.rb +++ b/app/models/role/assets.rb @@ -2,6 +2,7 @@ class Role module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/sla.rb b/app/models/sla.rb index 11aed5e6f..81a0ba6c0 100644 --- a/app/models/sla.rb +++ b/app/models/sla.rb @@ -4,7 +4,6 @@ class Sla < ApplicationModel include ChecksClientNotification include ChecksConditionValidation - load 'sla/assets.rb' include Sla::Assets store :condition diff --git a/app/models/sla/assets.rb b/app/models/sla/assets.rb index b24d0f88d..c0185bf19 100644 --- a/app/models/sla/assets.rb +++ b/app/models/sla/assets.rb @@ -2,6 +2,7 @@ class Sla module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/store.rb b/app/models/store.rb index 03354f47a..0a3d78ead 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -1,9 +1,9 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -class Store < ApplicationModel - load 'store/object.rb' - load 'store/file.rb' +require_dependency 'store/object' +require_dependency 'store/file' +class Store < ApplicationModel # rubocop:disable Rails/InverseOf belongs_to :store_object, class_name: 'Store::Object' belongs_to :store_file, class_name: 'Store::File' diff --git a/app/models/store/file.rb b/app/models/store/file.rb index c056a4be8..a9f0eb234 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -class Store +class Store < ApplicationModel class File < ApplicationModel include ApplicationLib after_destroy :destroy_provider diff --git a/app/models/store/object.rb b/app/models/store/object.rb index f12a4a575..59a8295de 100644 --- a/app/models/store/object.rb +++ b/app/models/store/object.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -class Store +class Store < ApplicationModel class Object < ApplicationModel validates :name, presence: true end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index c226fd07f..f71bc5300 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -15,11 +15,9 @@ class Ticket < ApplicationModel include Ticket::Escalation include Ticket::Subject - load 'ticket/assets.rb' include Ticket::Assets - load 'ticket/search_index.rb' include Ticket::SearchIndex - extend Ticket::Search + include Ticket::Search store :preferences before_create :check_generate, :check_defaults, :check_title, :set_default_state, :set_default_priority diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index e3cec702e..a6442bc1d 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -5,9 +5,8 @@ class Ticket::Article < ApplicationModel include HasHistory include ChecksHtmlSanitized include CanCsvImport - include Ticket::Article::ChecksAccess - load 'ticket/article/assets.rb' + include Ticket::Article::ChecksAccess include Ticket::Article::Assets belongs_to :ticket diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb index e2efaf92d..d88f85b9d 100644 --- a/app/models/ticket/article/assets.rb +++ b/app/models/ticket/article/assets.rb @@ -1,6 +1,7 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Ticket::Article::Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb index c247949c6..c202e5d4b 100644 --- a/app/models/ticket/assets.rb +++ b/app/models/ticket/assets.rb @@ -1,5 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Ticket::Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/ticket/search.rb b/app/models/ticket/search.rb index 998ab3653..7aa373a72 100644 --- a/app/models/ticket/search.rb +++ b/app/models/ticket/search.rb @@ -1,5 +1,9 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Ticket::Search + extend ActiveSupport::Concern + + # methods defined here are going to extend the class, not the instance of it + class_methods do =begin @@ -20,12 +24,12 @@ returns if user has no permissions to search =end - def search_preferences(_current_user) - { - prio: 3000, - direct_search_index: false, - } - end + def search_preferences(_current_user) + { + prio: 3000, + direct_search_index: false, + } + end =begin @@ -89,103 +93,104 @@ returns =end - def search(params) + def search(params) - # get params - query = params[:query] - condition = params[:condition] - limit = params[:limit] || 12 - offset = params[:offset] || 0 - current_user = params[:current_user] - full = false - if params[:full] == true || params[:full] == 'true' || !params.key?(:full) - full = true - end - - # try search index backend - if condition.blank? && SearchIndexBackend.enabled? - query_extention = {} - query_extention['bool'] = {} - query_extention['bool']['must'] = [] - - if current_user.permissions?('ticket.agent') - group_ids = current_user.group_ids_access('read') - access_condition = { - 'query_string' => { 'default_field' => 'group_id', 'query' => "\"#{group_ids.join('" OR "')}\"" } - } - else - access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) - { - 'query_string' => { 'default_field' => 'customer_id', 'query' => current_user.id } - } - # customer_id: XXX - # conditions = [ 'customer_id = ?', current_user.id ] - else - { - 'query_string' => { 'query' => "customer_id:#{current_user.id} OR organization_id:#{current_user.organization.id}" } - } - # customer_id: XXX OR organization_id: XXX - # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] - end + # get params + query = params[:query] + condition = params[:condition] + limit = params[:limit] || 12 + offset = params[:offset] || 0 + current_user = params[:current_user] + full = false + if params[:full] == true || params[:full] == 'true' || !params.key?(:full) + full = true end - query_extention['bool']['must'].push access_condition + # try search index backend + if condition.blank? && SearchIndexBackend.enabled? + query_extention = {} + query_extention['bool'] = {} + query_extention['bool']['must'] = [] - items = SearchIndexBackend.search(query, limit, 'Ticket', query_extention, offset) + if current_user.permissions?('ticket.agent') + group_ids = current_user.group_ids_access('read') + access_condition = { + 'query_string' => { 'default_field' => 'group_id', 'query' => "\"#{group_ids.join('" OR "')}\"" } + } + else + access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) + { + 'query_string' => { 'default_field' => 'customer_id', 'query' => current_user.id } + } + # customer_id: XXX + # conditions = [ 'customer_id = ?', current_user.id ] + else + { + 'query_string' => { 'query' => "customer_id:#{current_user.id} OR organization_id:#{current_user.organization.id}" } + } + # customer_id: XXX OR organization_id: XXX + # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] + end + end + + query_extention['bool']['must'].push access_condition + + items = SearchIndexBackend.search(query, limit, 'Ticket', query_extention, offset) + if !full + ids = [] + items.each do |item| + ids.push item[:id] + end + return ids + end + tickets = [] + items.each do |item| + ticket = Ticket.lookup(id: item[:id]) + next if !ticket + tickets.push ticket + end + return tickets + end + + # fallback do sql query + access_condition = Ticket.access_condition(current_user, 'read') + + # do query + # - stip out * we already search for *query* - + if query + query.delete! '*' + tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at') + .where(access_condition) + .where('(tickets.title LIKE ? OR tickets.number LIKE ? OR ticket_articles.body LIKE ? OR ticket_articles.from LIKE ? OR ticket_articles.to LIKE ? OR ticket_articles.subject LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ) + .joins(:articles) + .order('tickets.created_at DESC') + .offset(offset) + .limit(limit) + else + query_condition, bind_condition, tables = selector2sql(condition) + tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at') + .joins(tables) + .where(access_condition) + .where(query_condition, *bind_condition) + .order('tickets.created_at DESC') + .offset(offset) + .limit(limit) + end + + # build result list if !full ids = [] - items.each do |item| - ids.push item[:id] + tickets_all.each do |ticket| + ids.push ticket.id end return ids end + tickets = [] - items.each do |item| - ticket = Ticket.lookup(id: item[:id]) - next if !ticket - tickets.push ticket - end - return tickets - end - - # fallback do sql query - access_condition = Ticket.access_condition(current_user, 'read') - - # do query - # - stip out * we already search for *query* - - if query - query.delete! '*' - tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at') - .where(access_condition) - .where('(tickets.title LIKE ? OR tickets.number LIKE ? OR ticket_articles.body LIKE ? OR ticket_articles.from LIKE ? OR ticket_articles.to LIKE ? OR ticket_articles.subject LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ) - .joins(:articles) - .order('tickets.created_at DESC') - .offset(offset) - .limit(limit) - else - query_condition, bind_condition, tables = selector2sql(condition) - tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at') - .joins(tables) - .where(access_condition) - .where(query_condition, *bind_condition) - .order('tickets.created_at DESC') - .offset(offset) - .limit(limit) - end - - # build result list - if !full - ids = [] tickets_all.each do |ticket| - ids.push ticket.id + tickets.push Ticket.lookup(id: ticket.id) end - return ids + tickets end - - tickets = [] - tickets_all.each do |ticket| - tickets.push Ticket.lookup(id: ticket.id) - end - tickets end end diff --git a/app/models/ticket/search_index.rb b/app/models/ticket/search_index.rb index 3a2e6bcaf..a86822c27 100644 --- a/app/models/ticket/search_index.rb +++ b/app/models/ticket/search_index.rb @@ -1,5 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ module Ticket::SearchIndex + extend ActiveSupport::Concern =begin diff --git a/app/models/transaction/cti_caller_id_detection.rb b/app/models/transaction/cti_caller_id_detection.rb index 959ba4a26..8a1ee55db 100644 --- a/app/models/transaction/cti_caller_id_detection.rb +++ b/app/models/transaction/cti_caller_id_detection.rb @@ -1,6 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'signature_detection' - class Transaction::CtiCallerIdDetection =begin diff --git a/app/models/transaction/signature_detection.rb b/app/models/transaction/signature_detection.rb index 607627f08..d3443a2fe 100644 --- a/app/models/transaction/signature_detection.rb +++ b/app/models/transaction/signature_detection.rb @@ -1,6 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'signature_detection' - class Transaction::SignatureDetection =begin @@ -46,14 +44,14 @@ class Transaction::SignatureDetection return if type['name'] != 'email' # update current signature of user id - SignatureDetection.rebuild_user(article.created_by_id) + ::SignatureDetection.rebuild_user(article.created_by_id) # user user = User.lookup(id: article.created_by_id) return if !user return if !user.preferences return if !user.preferences[:signature_detection] - line = SignatureDetection.find_signature_line_by_article( + line = ::SignatureDetection.find_signature_line_by_article( user, article ) diff --git a/app/models/trigger.rb b/app/models/trigger.rb index 93f859c99..d76144db7 100644 --- a/app/models/trigger.rb +++ b/app/models/trigger.rb @@ -4,7 +4,6 @@ class Trigger < ApplicationModel include ChecksConditionValidation include CanSeed - load 'trigger/assets.rb' include Trigger::Assets store :condition diff --git a/app/models/trigger/assets.rb b/app/models/trigger/assets.rb index 5fd7c40aa..fd37d3145 100644 --- a/app/models/trigger/assets.rb +++ b/app/models/trigger/assets.rb @@ -2,6 +2,7 @@ class Trigger module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/user.rb b/app/models/user.rb index 3bcc634f7..4c2ec6ff7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,28 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'digest/md5' - -# @model User -# -# @property id(required) [Integer] The identifier for the User. -# @property login(required) [String] The login of the User used for authentication. -# @property firstname [String] The firstname of the User. -# @property lastname [String] The lastname of the User. -# @property email [String] The email of the User. -# @property image [String] The Image used as the User avatar (TODO: Image model?). -# @property web [String] The website/URL of the User. -# @property password [String] The password of the User. -# @property phone [String] The phone number of the User. -# @property fax [String] The fax number of the User. -# @property mobile [String] The mobile number of the User. -# @property department [String] The department the User is working at. -# @property street [String] The street the User lives in. -# @property zip [Integer] The zip postal code of the User city. -# @property city [String] The city the User lives in. -# @property country [String] The country the User lives in. -# @property verified [Boolean] The flag that shows the verified state of the User. -# @property active [Boolean] The flag that shows the active state of the User. -# @property note [String] The note or comment stored to the User. class User < ApplicationModel include HasActivityStreamLog include ChecksClientNotification @@ -31,12 +7,10 @@ class User < ApplicationModel include CanCsvImport include HasGroups include HasRoles - include User::ChecksAccess - load 'user/assets.rb' + include User::ChecksAccess include User::Assets - extend User::Search - load 'user/search_index.rb' + include User::Search include User::SearchIndex has_and_belongs_to_many :roles, after_add: %i[cache_update check_notifications], after_remove: :cache_update, before_add: %i[validate_agent_limit_by_role validate_roles], before_remove: :last_admin_check_by_role, class_name: 'Role' diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index 2be614b5f..7b5e63d94 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -2,6 +2,7 @@ class User module Assets + extend ActiveSupport::Concern =begin diff --git a/app/models/user/search.rb b/app/models/user/search.rb index 9738b7cb1..5474bd8f6 100644 --- a/app/models/user/search.rb +++ b/app/models/user/search.rb @@ -2,6 +2,10 @@ class User module Search + extend ActiveSupport::Concern + + # methods defined here are going to extend the class, not the instance of it + class_methods do =begin @@ -22,13 +26,13 @@ returns if user has no permissions to search =end - def search_preferences(current_user) - return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.user') - { - prio: 2000, - direct_search_index: true, - } - end + def search_preferences(current_user) + return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.user') + { + prio: 2000, + direct_search_index: true, + } + end =begin @@ -58,61 +62,62 @@ returns =end - def search(params) + def search(params) - # get params - query = params[:query] - limit = params[:limit] || 10 - offset = params[:offset] || 0 - current_user = params[:current_user] + # get params + query = params[:query] + limit = params[:limit] || 10 + offset = params[:offset] || 0 + current_user = params[:current_user] - # enable search only for agents and admins - return [] if !search_preferences(current_user) + # enable search only for agents and admins + return [] if !search_preferences(current_user) - # lookup for roles of permission - if params[:permissions].present? - params[:role_ids] ||= [] - role_ids = Role.with_permissions(params[:permissions]).pluck(:id) - params[:role_ids].concat(role_ids) - end + # lookup for roles of permission + if params[:permissions].present? + params[:role_ids] ||= [] + role_ids = Role.with_permissions(params[:permissions]).pluck(:id) + params[:role_ids].concat(role_ids) + end - # try search index backend - if SearchIndexBackend.enabled? - query_extention = {} - if params[:role_ids].present? - query_extention['bool'] = {} - query_extention['bool']['must'] = [] - if !params[:role_ids].is_a?(Array) - params[:role_ids] = [params[:role_ids]] + # try search index backend + if SearchIndexBackend.enabled? + query_extention = {} + if params[:role_ids].present? + query_extention['bool'] = {} + query_extention['bool']['must'] = [] + if !params[:role_ids].is_a?(Array) + params[:role_ids] = [params[:role_ids]] + end + access_condition = { + 'query_string' => { 'default_field' => 'role_ids', 'query' => "\"#{params[:role_ids].join('" OR "')}\"" } + } + query_extention['bool']['must'].push access_condition end - access_condition = { - 'query_string' => { 'default_field' => 'role_ids', 'query' => "\"#{params[:role_ids].join('" OR "')}\"" } - } - query_extention['bool']['must'].push access_condition + items = SearchIndexBackend.search(query, limit, 'User', query_extention, offset) + users = [] + items.each do |item| + user = User.lookup(id: item[:id]) + next if !user + users.push user + end + return users end - items = SearchIndexBackend.search(query, limit, 'User', query_extention, offset) - users = [] - items.each do |item| - user = User.lookup(id: item[:id]) - next if !user - users.push user - end - return users - end - # fallback do sql query - # - stip out * we already search for *query* - - query.delete! '*' - users = if params[:role_ids] - User.joins(:roles).where('roles.id' => params[:role_ids]).where( - '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" - ).order('updated_at DESC').offset(offset).limit(limit) - else - User.where( - '(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" - ).order('updated_at DESC').offset(offset).limit(limit) - end - users + # fallback do sql query + # - stip out * we already search for *query* - + query.delete! '*' + users = if params[:role_ids] + User.joins(:roles).where('roles.id' => params[:role_ids]).where( + '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" + ).order('updated_at DESC').offset(offset).limit(limit) + else + User.where( + '(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" + ).order('updated_at DESC').offset(offset).limit(limit) + end + users + end end end end diff --git a/app/models/user/search_index.rb b/app/models/user/search_index.rb index 80376e7f4..cab464500 100644 --- a/app/models/user/search_index.rb +++ b/app/models/user/search_index.rb @@ -2,6 +2,7 @@ class User module SearchIndex + extend ActiveSupport::Concern =begin @@ -67,6 +68,5 @@ returns attributes end - end end diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index dad7ea67a..f72ab6fe0 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'ldap' -require 'ldap/user' +require_dependency 'ldap' +require_dependency 'ldap/user' class Auth class Ldap < Auth::Base diff --git a/lib/encode.rb b/lib/encode.rb index c0ccc5ac6..b844197ea 100644 --- a/lib/encode.rb +++ b/lib/encode.rb @@ -1,4 +1,3 @@ -#require 'iconv' module Encode def self.conv (charset, string) diff --git a/lib/facebook.rb b/lib/facebook.rb index 16bcca4e2..4d90f405b 100644 --- a/lib/facebook.rb +++ b/lib/facebook.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/ -require 'koala' - class Facebook attr_accessor :client, :account diff --git a/lib/import/exchange/folder.rb b/lib/import/exchange/folder.rb index 3e702bc9c..0cd5e2b75 100644 --- a/lib/import/exchange/folder.rb +++ b/lib/import/exchange/folder.rb @@ -1,4 +1,4 @@ -require 'mixin/rails_logger' +require_dependency 'mixin/rails_logger' module Import class Exchange diff --git a/lib/import/ldap.rb b/lib/import/ldap.rb index 6bcac2ea9..69f50706c 100644 --- a/lib/import/ldap.rb +++ b/lib/import/ldap.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'ldap' -require 'ldap/group' +require_dependency 'ldap' +require_dependency 'ldap/group' module Import class Ldap < Import::IntegrationBase diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 55e9489f9..147a2d5f3 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -2,24 +2,24 @@ # in the importer folder require AND simultaniuos requiring # of the same file in different threads so we need to # require them ourself -require 'import/otrs/ticket' -require 'import/otrs/ticket_factory' -require 'import/otrs/article_customer' -require 'import/otrs/article_customer_factory' -require 'import/otrs/article' -require 'import/otrs/article_factory' -require 'import/otrs/article/attachment_factory' -require 'import/otrs/history' -require 'import/otrs/history_factory' -require 'import/otrs/history/article' -require 'import/otrs/history/move' -require 'import/otrs/history/new_ticket' -require 'import/otrs/history/priority_update' -require 'import/otrs/history/state_update' -require 'store' -require 'store/object' -require 'store/provider/db' -require 'store/provider/file' +require_dependency 'import/otrs/ticket' +require_dependency 'import/otrs/ticket_factory' +require_dependency 'import/otrs/article_customer' +require_dependency 'import/otrs/article_customer_factory' +require_dependency 'import/otrs/article' +require_dependency 'import/otrs/article_factory' +require_dependency 'import/otrs/article/attachment_factory' +require_dependency 'import/otrs/history' +require_dependency 'import/otrs/history_factory' +require_dependency 'import/otrs/history/article' +require_dependency 'import/otrs/history/move' +require_dependency 'import/otrs/history/new_ticket' +require_dependency 'import/otrs/history/priority_update' +require_dependency 'import/otrs/history/state_update' +require_dependency 'store' +require_dependency 'store/object' +require_dependency 'store/provider/db' +require_dependency 'store/provider/file' module Import module OTRS diff --git a/lib/import/otrs/dynamic_field/date.rb b/lib/import/otrs/dynamic_field/date.rb index 7d8d71133..84c62dbed 100644 --- a/lib/import/otrs/dynamic_field/date.rb +++ b/lib/import/otrs/dynamic_field/date.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/otrs/dynamic_field' +require_dependency 'import/otrs/dynamic_field' module Import module OTRS diff --git a/lib/import/otrs/dynamic_field/date_time.rb b/lib/import/otrs/dynamic_field/date_time.rb index d9a7761b1..1232f150b 100644 --- a/lib/import/otrs/dynamic_field/date_time.rb +++ b/lib/import/otrs/dynamic_field/date_time.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/otrs/dynamic_field' +require_dependency 'import/otrs/dynamic_field' module Import module OTRS diff --git a/lib/import/otrs/ticket.rb b/lib/import/otrs/ticket.rb index 8af2ef7d8..38cc934f5 100644 --- a/lib/import/otrs/ticket.rb +++ b/lib/import/otrs/ticket.rb @@ -1,4 +1,4 @@ -require 'ticket' +require_dependency 'ticket' module Import module OTRS diff --git a/lib/import/zendesk/object_attribute/checkbox.rb b/lib/import/zendesk/object_attribute/checkbox.rb index 310712126..6ef344be8 100644 --- a/lib/import/zendesk/object_attribute/checkbox.rb +++ b/lib/import/zendesk/object_attribute/checkbox.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/date.rb b/lib/import/zendesk/object_attribute/date.rb index 7e7c57df7..fbd920926 100644 --- a/lib/import/zendesk/object_attribute/date.rb +++ b/lib/import/zendesk/object_attribute/date.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/integer.rb b/lib/import/zendesk/object_attribute/integer.rb index eb8a2ab22..e19e41322 100644 --- a/lib/import/zendesk/object_attribute/integer.rb +++ b/lib/import/zendesk/object_attribute/integer.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/regexp.rb b/lib/import/zendesk/object_attribute/regexp.rb index b56093acc..895d0523b 100644 --- a/lib/import/zendesk/object_attribute/regexp.rb +++ b/lib/import/zendesk/object_attribute/regexp.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/select.rb b/lib/import/zendesk/object_attribute/select.rb index 43ca8633e..5c79808c1 100644 --- a/lib/import/zendesk/object_attribute/select.rb +++ b/lib/import/zendesk/object_attribute/select.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/text.rb b/lib/import/zendesk/object_attribute/text.rb index 6676173e4..0d815b666 100644 --- a/lib/import/zendesk/object_attribute/text.rb +++ b/lib/import/zendesk/object_attribute/text.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/import/zendesk/object_attribute/textarea.rb b/lib/import/zendesk/object_attribute/textarea.rb index 9562d3d0a..e22ac0f12 100644 --- a/lib/import/zendesk/object_attribute/textarea.rb +++ b/lib/import/zendesk/object_attribute/textarea.rb @@ -1,7 +1,7 @@ # this require is required (hehe) because of Rails autoloading # which causes strange behavior not inheriting correctly # from Import::OTRS::DynamicField -require 'import/zendesk/object_attribute/base' +require_dependency 'import/zendesk/object_attribute/base' module Import class Zendesk diff --git a/lib/ldap.rb b/lib/ldap.rb index fbb090fdc..2e732b8ac 100644 --- a/lib/ldap.rb +++ b/lib/ldap.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'net/ldap' -require 'net/ldap/entry' +require_dependency 'net/ldap' +require_dependency 'net/ldap/entry' # Class for establishing LDAP connections. A wrapper around Net::LDAP needed for Auth and Sync. # ATTENTION: Loads custom 'net/ldap/entry' from 'lib/core_ext' which extends the Net::LDAP::Entry class. diff --git a/lib/ldap/group.rb b/lib/ldap/group.rb index 253a7417c..b3320a85c 100644 --- a/lib/ldap/group.rb +++ b/lib/ldap/group.rb @@ -6,8 +6,8 @@ class Ldap # an ::Ldap instance. # # @example - # require 'ldap' - # require 'ldap/group' + # require_dependency 'ldap' + # require_dependency 'ldap/group' class Group include Ldap::FilterLookup @@ -29,8 +29,8 @@ class Ldap # @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration. # # @example - # require 'ldap' - # require 'ldap/group' + # require_dependency 'ldap' + # require_dependency 'ldap/group' # ldap_group = Ldap::Group.new # # @return [nil] diff --git a/lib/ldap/user.rb b/lib/ldap/user.rb index 9b6455003..3dd2143f6 100644 --- a/lib/ldap/user.rb +++ b/lib/ldap/user.rb @@ -6,8 +6,8 @@ class Ldap # an ::Ldap instance. # # @example - # require 'ldap' - # require 'ldap/user' + # require_dependency 'ldap' + # require_dependency 'ldap/user' class User include Ldap::FilterLookup @@ -76,8 +76,8 @@ class Ldap # @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration. # # @example - # require 'ldap' - # require 'ldap/user' + # require_dependency 'ldap' + # require_dependency 'ldap/user' # ldap_user = Ldap::User.new # # @return [nil] diff --git a/lib/migration_job/ldap_samaccountname_to_uid.rb b/lib/migration_job/ldap_samaccountname_to_uid.rb index 810be1f10..b3f3dfcc6 100644 --- a/lib/migration_job/ldap_samaccountname_to_uid.rb +++ b/lib/migration_job/ldap_samaccountname_to_uid.rb @@ -1,5 +1,5 @@ -require 'ldap' -require 'ldap/user' +require_dependency 'ldap' +require_dependency 'ldap/user' module MigrationJob class LdapSamaccountnameToUid diff --git a/lib/sequencer.rb b/lib/sequencer.rb index 3a8aab6c1..a0a662877 100644 --- a/lib/sequencer.rb +++ b/lib/sequencer.rb @@ -1,5 +1,5 @@ -require 'mixin/rails_logger' -require 'mixin/start_finish_logger' +require_dependency 'mixin/rails_logger' +require_dependency 'mixin/start_finish_logger' class Sequencer include ::Mixin::RailsLogger diff --git a/lib/sequencer/sequence.rb b/lib/sequencer/sequence.rb index 7e4e32fdc..64642836e 100644 --- a/lib/sequencer/sequence.rb +++ b/lib/sequencer/sequence.rb @@ -1,4 +1,4 @@ -require 'sequencer/mixin/prefixed_constantize' +require_dependency 'sequencer/mixin/prefixed_constantize' class Sequencer class Sequence diff --git a/lib/sequencer/state.rb b/lib/sequencer/state.rb index 460648e6c..62736dfc9 100644 --- a/lib/sequencer/state.rb +++ b/lib/sequencer/state.rb @@ -1,5 +1,5 @@ -require 'mixin/rails_logger' -require 'mixin/start_finish_logger' +require_dependency 'mixin/rails_logger' +require_dependency 'mixin/start_finish_logger' class Sequencer class State diff --git a/lib/sequencer/unit.rb b/lib/sequencer/unit.rb index 723ef4a2e..17254c9b0 100644 --- a/lib/sequencer/unit.rb +++ b/lib/sequencer/unit.rb @@ -1,4 +1,4 @@ -require 'sequencer/mixin/prefixed_constantize' +require_dependency 'sequencer/mixin/prefixed_constantize' class Sequencer class Unit diff --git a/lib/sequencer/unit/base.rb b/lib/sequencer/unit/base.rb index cd97afe82..1876c4099 100644 --- a/lib/sequencer/unit/base.rb +++ b/lib/sequencer/unit/base.rb @@ -1,4 +1,4 @@ -require 'mixin/rails_logger' +require_dependency 'mixin/rails_logger' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/associations/assign.rb b/lib/sequencer/unit/import/common/model/associations/assign.rb index 65c334517..e548282bf 100644 --- a/lib/sequencer/unit/import/common/model/associations/assign.rb +++ b/lib/sequencer/unit/import/common/model/associations/assign.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/mixin/handle_failure' +require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/save.rb b/lib/sequencer/unit/import/common/model/save.rb index 588009808..de0595bf1 100644 --- a/lib/sequencer/unit/import/common/model/save.rb +++ b/lib/sequencer/unit/import/common/model/save.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/mixin/handle_failure' +require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/skip/blank/base.rb b/lib/sequencer/unit/import/common/model/skip/blank/base.rb index 18f23e891..7399b117e 100644 --- a/lib/sequencer/unit/import/common/model/skip/blank/base.rb +++ b/lib/sequencer/unit/import/common/model/skip/blank/base.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/common/mixin/dynamic_attribute' +require_dependency 'sequencer/unit/common/mixin/dynamic_attribute' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/skip/missing_mandatory/base.rb b/lib/sequencer/unit/import/common/model/skip/missing_mandatory/base.rb index f4d9c3560..6aee4846b 100644 --- a/lib/sequencer/unit/import/common/model/skip/missing_mandatory/base.rb +++ b/lib/sequencer/unit/import/common/model/skip/missing_mandatory/base.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/common/mixin/dynamic_attribute' +require_dependency 'sequencer/unit/common/mixin/dynamic_attribute' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/statistics/diff/custom_key.rb b/lib/sequencer/unit/import/common/model/statistics/diff/custom_key.rb index 0ad3c3be7..813744de9 100644 --- a/lib/sequencer/unit/import/common/model/statistics/diff/custom_key.rb +++ b/lib/sequencer/unit/import/common/model/statistics/diff/custom_key.rb @@ -1,5 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/action_diff' - +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff' class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/common/model/statistics/diff/model_key.rb b/lib/sequencer/unit/import/common/model/statistics/diff/model_key.rb index 1474e8e80..93868fe70 100644 --- a/lib/sequencer/unit/import/common/model/statistics/diff/model_key.rb +++ b/lib/sequencer/unit/import/common/model/statistics/diff/model_key.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/action_diff' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/statistics/diff/top_level.rb b/lib/sequencer/unit/import/common/model/statistics/diff/top_level.rb index e37f116dd..700614fa3 100644 --- a/lib/sequencer/unit/import/common/model/statistics/diff/top_level.rb +++ b/lib/sequencer/unit/import/common/model/statistics/diff/top_level.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/action_diff' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/statistics/mixin/action_diff.rb b/lib/sequencer/unit/import/common/model/statistics/mixin/action_diff.rb index 35aee5a17..59df5dcbb 100644 --- a/lib/sequencer/unit/import/common/model/statistics/mixin/action_diff.rb +++ b/lib/sequencer/unit/import/common/model/statistics/mixin/action_diff.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/common' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/common/model/statistics/mixin/empty_diff.rb b/lib/sequencer/unit/import/common/model/statistics/mixin/empty_diff.rb index 3e610bc67..f44e78982 100644 --- a/lib/sequencer/unit/import/common/model/statistics/mixin/empty_diff.rb +++ b/lib/sequencer/unit/import/common/model/statistics/mixin/empty_diff.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/common' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/user/model/save.rb b/lib/sequencer/unit/import/ldap/user/model/save.rb index 960c14d40..d46a26611 100644 --- a/lib/sequencer/unit/import/ldap/user/model/save.rb +++ b/lib/sequencer/unit/import/ldap/user/model/save.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/mixin/without_callback' +require_dependency 'sequencer/unit/import/common/model/mixin/without_callback' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/user/statistics/diff.rb b/lib/sequencer/unit/import/ldap/user/statistics/diff.rb index 3113acad4..de4b343e6 100644 --- a/lib/sequencer/unit/import/ldap/user/statistics/diff.rb +++ b/lib/sequencer/unit/import/ldap/user/statistics/diff.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/action_diff' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb b/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb index 000d4fdfa..78da6c310 100644 --- a/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb +++ b/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/users/sub_sequence.rb b/lib/sequencer/unit/import/ldap/users/sub_sequence.rb index b890ad508..a8a9c8537 100644 --- a/lib/sequencer/unit/import/ldap/users/sub_sequence.rb +++ b/lib/sequencer/unit/import/ldap/users/sub_sequence.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/sub_sequence/mixin/import_job' +require_dependency 'sequencer/unit/import/common/sub_sequence/mixin/import_job' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/users/total.rb b/lib/sequencer/unit/import/ldap/users/total.rb index deb95cdcc..96601d0ce 100644 --- a/lib/sequencer/unit/import/ldap/users/total.rb +++ b/lib/sequencer/unit/import/ldap/users/total.rb @@ -1,4 +1,4 @@ -require 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' +require_dependency 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' class Sequencer class Unit diff --git a/lib/sequencer/unit/import/ldap/users/user_roles.rb b/lib/sequencer/unit/import/ldap/users/user_roles.rb index 8ae344487..7bc879eff 100644 --- a/lib/sequencer/unit/import/ldap/users/user_roles.rb +++ b/lib/sequencer/unit/import/ldap/users/user_roles.rb @@ -1,5 +1,5 @@ -require 'ldap' -require 'ldap/group' +require_dependency 'ldap' +require_dependency 'ldap/group' class Sequencer class Unit diff --git a/lib/sequencer/unit/ldap/config.rb b/lib/sequencer/unit/ldap/config.rb index 3425c4f5c..0258b6b11 100644 --- a/lib/sequencer/unit/ldap/config.rb +++ b/lib/sequencer/unit/ldap/config.rb @@ -1,4 +1,4 @@ -require 'import/ldap' +require_dependency 'import/ldap' class Sequencer class Unit diff --git a/lib/sequencer/unit/ldap/connection.rb b/lib/sequencer/unit/ldap/connection.rb index 4276d95dd..1f485cc29 100644 --- a/lib/sequencer/unit/ldap/connection.rb +++ b/lib/sequencer/unit/ldap/connection.rb @@ -1,4 +1,4 @@ -require 'ldap' +require_dependency 'ldap' class Sequencer class Unit diff --git a/lib/sequencer/units.rb b/lib/sequencer/units.rb index f1adb1bf3..b63ca129b 100644 --- a/lib/sequencer/units.rb +++ b/lib/sequencer/units.rb @@ -1,5 +1,5 @@ -require 'sequencer/units/attribute' -require 'sequencer/units/attributes' +require_dependency 'sequencer/units/attribute' +require_dependency 'sequencer/units/attributes' class Sequencer class Units < SimpleDelegator diff --git a/lib/service/geo_calendar/zammad.rb b/lib/service/geo_calendar/zammad.rb index 688b46c86..ea19e3400 100644 --- a/lib/service/geo_calendar/zammad.rb +++ b/lib/service/geo_calendar/zammad.rb @@ -1,13 +1,11 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'cache' - class Service::GeoCalendar::Zammad def self.location(address) # check cache cache_key = "zammadgeocalendar::#{address}" - cache = Cache.get(cache_key) + cache = ::Cache.get(cache_key) return cache if cache # do lookup @@ -35,10 +33,10 @@ class Service::GeoCalendar::Zammad data = response.data - Cache.write(cache_key, data, { expires_in: 30.minutes }) + ::Cache.write(cache_key, data, { expires_in: 30.minutes }) rescue => e Rails.logger.error "#{host}#{url}: #{e.inspect}" - Cache.write(cache_key, data, { expires_in: 1.minute }) + ::Cache.write(cache_key, data, { expires_in: 1.minute }) end data end diff --git a/lib/service/geo_ip/zammad.rb b/lib/service/geo_ip/zammad.rb index 0be67ca54..109ecf993 100644 --- a/lib/service/geo_ip/zammad.rb +++ b/lib/service/geo_ip/zammad.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ -require 'cache' - class Service::GeoIp::Zammad def self.location(address) return {} if address == '127.0.0.1' @@ -9,7 +7,7 @@ class Service::GeoIp::Zammad # check cache cache_key = "zammadgeoip::#{address}" - cache = Cache.get(cache_key) + cache = ::Cache.get(cache_key) return cache if cache # do lookup @@ -38,10 +36,10 @@ class Service::GeoIp::Zammad data['country_code'] = data['country_code2'] end - Cache.write(cache_key, data, { expires_in: 90.days }) + ::Cache.write(cache_key, data, { expires_in: 90.days }) rescue => e Rails.logger.error "#{host}#{url}: #{e.inspect}" - Cache.write(cache_key, data, { expires_in: 60.minutes }) + ::Cache.write(cache_key, data, { expires_in: 60.minutes }) end data end diff --git a/lib/sessions.rb b/lib/sessions.rb index ad1317d62..8e2e0169a 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -1,6 +1,3 @@ -require 'json' -require 'session_helper' - module Sessions # get application root directory diff --git a/lib/stats.rb b/lib/stats.rb index 615d49720..a25d40aad 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -1,7 +1,4 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -require 'stats_store' - class Stats =begin diff --git a/lib/tweet_base.rb b/lib/tweet_base.rb index e01a6ac67..49d3436a1 100644 --- a/lib/tweet_base.rb +++ b/lib/tweet_base.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/ -require 'twitter' -load 'lib/http/uri.rb' +require 'http/uri' class TweetBase diff --git a/lib/twitter/streaming/client_custom.rb b/lib/twitter/streaming/client_custom.rb index 57a13a920..bc77e6bfc 100644 --- a/lib/twitter/streaming/client_custom.rb +++ b/lib/twitter/streaming/client_custom.rb @@ -1,6 +1,6 @@ # file is based on Twitter::Streaming::Client, needed to get custom_connection_handle # to close connection after config has changed -require 'twitter/streaming/connection_custom' +require_dependency 'twitter/streaming/connection_custom' class Twitter::Streaming::ClientCustom < Twitter::Streaming::Client diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 1cc4bc155..73a4885bf 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -3,7 +3,6 @@ require 'net/http' require 'net/https' require 'net/ftp' -require 'tempfile' class UserAgent