diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d4c793244..d183a7b4f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,7 +45,7 @@ variables: # as a key for the cache to avoid cache growth and incompatibilities between # the gems. Search hook: 2.6.6 (change it when updating the Ruby version too) cache: - key: "centos7ruby266" + key: "centos7ruby266rails6" paths: - vendor/ruby # ATTENTION: This should be a dedicated cache only used in the job "TODO". diff --git a/.gitlab/ci/pre.yml b/.gitlab/ci/pre.yml index edc945a84..211cd4531 100644 --- a/.gitlab/ci/pre.yml +++ b/.gitlab/ci/pre.yml @@ -21,6 +21,17 @@ shellcheck: script: - shellcheck -S warning $(find . -name "*.sh" -o -name "functions" | grep -v "/vendor/") +zeitwerk_check: + <<: *template_pre + extends: + - .tags_docker + - .services_postgresql + script: + - bundle install -j $(nproc) --path vendor + - bundle exec ruby script/build/database_config.rb + - bundle exec rake zammad:db:init + - bundle exec rails zeitwerk:check + coffeelint: <<: *template_pre script: diff --git a/.rubocop/default.yml b/.rubocop/default.yml index a7481ed17..091707fef 100644 --- a/.rubocop/default.yml +++ b/.rubocop/default.yml @@ -15,9 +15,7 @@ AllCops: NewCops: enable DisplayCopNames: true Exclude: - - 'bin/rails' - - 'bin/rake' - - 'bin/spring' + - 'bin/*' - 'db/schema.rb' - 'vendor/**/*' - 'node_modules/**/*' diff --git a/.rubocop/todo.yml b/.rubocop/todo.yml index e0d3fa39b..2d30d7496 100644 --- a/.rubocop/todo.yml +++ b/.rubocop/todo.yml @@ -61,8 +61,6 @@ Metrics/AbcSize: - 'app/controllers/recent_view_controller.rb' - 'app/controllers/reports_controller.rb' - 'app/controllers/search_controller.rb' - - 'app/controllers/sessions/collection_base.rb' - - 'app/controllers/sessions/collection_ticket.rb' - 'app/controllers/sessions_controller.rb' - 'app/controllers/settings_controller.rb' - 'app/controllers/text_modules_controller.rb' @@ -321,6 +319,8 @@ Metrics/AbcSize: - 'lib/service/geo_calendar/zammad.rb' - 'lib/service/geo_ip/zammad.rb' - 'lib/service/geo_location/gmaps.rb' + - 'lib/session_helper/collection_base.rb' + - 'lib/session_helper/collection_ticket.rb' - 'lib/sessions.rb' - 'lib/sessions/backend/activity_stream.rb' - 'lib/sessions/backend/base.rb' @@ -478,8 +478,6 @@ Metrics/CyclomaticComplexity: - 'app/controllers/organizations_controller.rb' - 'app/controllers/reports_controller.rb' - 'app/controllers/search_controller.rb' - - 'app/controllers/sessions/collection_base.rb' - - 'app/controllers/sessions/collection_ticket.rb' - 'app/controllers/sessions_controller.rb' - 'app/controllers/ticket_articles_controller.rb' - 'app/controllers/tickets_controller.rb' @@ -638,6 +636,8 @@ Metrics/CyclomaticComplexity: - 'lib/secure_mailing/smime/incoming.rb' - 'lib/sequencer/unit/import/zendesk/sub_sequence/base.rb' - 'lib/service/geo_ip/zammad.rb' + - 'lib/session_helper/collection_base.rb' + - 'lib/session_helper/collection_ticket.rb' - 'lib/sessions.rb' - 'lib/sessions/backend/activity_stream.rb' - 'lib/sessions/backend/ticket_overview_list.rb' @@ -715,8 +715,6 @@ Metrics/PerceivedComplexity: - 'app/controllers/organizations_controller.rb' - 'app/controllers/reports_controller.rb' - 'app/controllers/search_controller.rb' - - 'app/controllers/sessions/collection_base.rb' - - 'app/controllers/sessions/collection_ticket.rb' - 'app/controllers/sessions_controller.rb' - 'app/controllers/ticket_articles_controller.rb' - 'app/controllers/tickets_controller.rb' @@ -865,6 +863,8 @@ Metrics/PerceivedComplexity: - 'lib/search_index_backend.rb' - 'lib/secure_mailing/smime/incoming.rb' - 'lib/service/geo_ip/zammad.rb' + - 'lib/session_helper/collection_base.rb' + - 'lib/session_helper/collection_ticket.rb' - 'lib/sessions.rb' - 'lib/sessions/backend/activity_stream.rb' - 'lib/sessions/backend/ticket_overview_list.rb' diff --git a/Gemfile b/Gemfile index a92e51436..26af002ce 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' # core - base ruby '2.6.6' -gem 'rails', '5.2.4.6' +gem 'rails', '6.0.4' # core - rails additions gem 'activerecord-import' diff --git a/Gemfile.lock b/Gemfile.lock index 422c22795..167ea955b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,41 +49,53 @@ GEM specs: aasm (5.0.0) concurrent-ruby (~> 1.0) - actioncable (5.2.4.6) - actionpack (= 5.2.4.6) + actioncable (6.0.4) + actionpack (= 6.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.6) - actionpack (= 5.2.4.6) - actionview (= 5.2.4.6) - activejob (= 5.2.4.6) + actionmailbox (6.0.4) + actionpack (= 6.0.4) + activejob (= 6.0.4) + activerecord (= 6.0.4) + activestorage (= 6.0.4) + activesupport (= 6.0.4) + mail (>= 2.7.1) + actionmailer (6.0.4) + actionpack (= 6.0.4) + actionview (= 6.0.4) + activejob (= 6.0.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.6) - actionview (= 5.2.4.6) - activesupport (= 5.2.4.6) + actionpack (6.0.4) + actionview (= 6.0.4) + activesupport (= 6.0.4) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.6) - activesupport (= 5.2.4.6) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.4) + actionpack (= 6.0.4) + activerecord (= 6.0.4) + activestorage (= 6.0.4) + activesupport (= 6.0.4) + nokogiri (>= 1.8.5) + actionview (6.0.4) + activesupport (= 6.0.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.6) - activesupport (= 5.2.4.6) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.4) + activesupport (= 6.0.4) globalid (>= 0.3.6) - activemodel (5.2.4.6) - activesupport (= 5.2.4.6) - activerecord (5.2.4.6) - activemodel (= 5.2.4.6) - activesupport (= 5.2.4.6) - arel (>= 9.0) - activerecord-import (1.0.2) + activemodel (6.0.4) + activesupport (= 6.0.4) + activerecord (6.0.4) + activemodel (= 6.0.4) + activesupport (= 6.0.4) + activerecord-import (1.0.5) activerecord (>= 3.2) - activerecord-nulldb-adapter (0.3.9) + activerecord-nulldb-adapter (0.4.0) activerecord (>= 2.0.0) activerecord-session_store (2.0.0) actionpack (>= 5.2.4.1) @@ -91,20 +103,21 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 2.0.8, < 3) railties (>= 5.2.4.1) - activestorage (5.2.4.6) - actionpack (= 5.2.4.6) - activerecord (= 5.2.4.6) - marcel (~> 0.3.1) - activesupport (5.2.4.6) + activestorage (6.0.4) + actionpack (= 6.0.4) + activejob (= 6.0.4) + activerecord (= 6.0.4) + marcel (~> 1.0.0) + activesupport (6.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts_as_list (0.9.19) - activerecord (>= 3.0) + zeitwerk (~> 2.2, >= 2.2.2) + acts_as_list (1.0.1) + activerecord (>= 4.2) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) - arel (9.0.0) argon2 (2.0.2) ffi (~> 1.9) ffi-compiler (>= 0.1) @@ -137,9 +150,9 @@ GEM clearbit (0.2.8) nestful (~> 1.1.0) coderay (1.1.2) - coffee-rails (4.2.2) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs @@ -148,9 +161,9 @@ GEM coffee-script execjs json - composite_primary_keys (11.2.0) - activerecord (~> 5.2.1) - concurrent-ruby (1.1.8) + composite_primary_keys (12.0.2) + activerecord (~> 6.0.0) + concurrent-ruby (1.1.9) coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) @@ -163,10 +176,10 @@ GEM daemons (1.3.1) dalli (2.7.10) debug_inspector (0.0.3) - delayed_job (4.1.7) - activesupport (>= 3.0, < 5.3) - delayed_job_active_record (4.1.3) - activerecord (>= 3.0, < 5.3) + delayed_job (4.1.8) + activesupport (>= 3.0, < 6.1) + delayed_job_active_record (4.1.4) + activerecord (>= 3.0, < 6.1) delayed_job (>= 3.0, < 5) deprecation_toolkit (1.4.0) activesupport (>= 4.2) @@ -275,23 +288,19 @@ GEM logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) - loofah (2.9.1) + loofah (2.10.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.13) - marcel (0.3.3) - mimemagic (~> 0.3.2) + marcel (1.0.1) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2019.0331) - mimemagic (0.3.10) - nokogiri (~> 1) - rake mini_mime (1.1.0) - mini_portile2 (2.5.1) + mini_portile2 (2.5.3) mini_racer (0.2.9) libv8 (>= 6.9.411) minitest (5.14.4) @@ -306,7 +315,7 @@ GEM net-ldap (0.16.1) netrc (0.11.0) nio4r (2.5.7) - nokogiri (1.11.5) + nokogiri (1.11.7) mini_portile2 (~> 2.5.0) racc (~> 1.4) nori (2.6.0) @@ -396,18 +405,20 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.4.6) - actioncable (= 5.2.4.6) - actionmailer (= 5.2.4.6) - actionpack (= 5.2.4.6) - actionview (= 5.2.4.6) - activejob (= 5.2.4.6) - activemodel (= 5.2.4.6) - activerecord (= 5.2.4.6) - activestorage (= 5.2.4.6) - activesupport (= 5.2.4.6) + rails (6.0.4) + actioncable (= 6.0.4) + actionmailbox (= 6.0.4) + actionmailer (= 6.0.4) + actionpack (= 6.0.4) + actiontext (= 6.0.4) + actionview (= 6.0.4) + activejob (= 6.0.4) + activemodel (= 6.0.4) + activerecord (= 6.0.4) + activestorage (= 6.0.4) + activesupport (= 6.0.4) bundler (>= 1.3.0) - railties (= 5.2.4.6) + railties (= 6.0.4) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.4) actionpack (>= 5.0.1.x) @@ -418,12 +429,12 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (5.2.4.6) - actionpack (= 5.2.4.6) - activesupport (= 5.2.4.6) + railties (6.0.4) + actionpack (= 6.0.4) + activesupport (= 6.0.4) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.0.0) raindrops (0.19.0) rake (12.3.3) @@ -562,12 +573,13 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) writeexcel (1.0.5) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.4.2) zendesk_api (1.19.0) faraday (~> 0.9) hashie (>= 3.5.2, < 4.0.0) @@ -650,7 +662,7 @@ DEPENDENCIES pundit pundit-matchers rack-livereload - rails (= 5.2.4.6) + rails (= 6.0.4) rails-controller-testing rb-fsevent rchardet (>= 1.8.0) diff --git a/app/controllers/channels_sms_controller.rb b/app/controllers/channels_sms_controller.rb index b345d662f..b82c8fdd9 100644 --- a/app/controllers/channels_sms_controller.rb +++ b/app/controllers/channels_sms_controller.rb @@ -98,7 +98,6 @@ class ChannelsSmsController < ApplicationController list = [] Dir.glob(Rails.root.join('app/models/channel/driver/sms/*.rb')).each do |path| filename = File.basename(path) - require_dependency "channel/driver/sms/#{filename.sub('.rb', '')}" list.push Channel.driver_class("sms/#{filename}").definition end list diff --git a/app/controllers/channels_twitter_controller.rb b/app/controllers/channels_twitter_controller.rb index 10d1cfe90..20fe71930 100644 --- a/app/controllers/channels_twitter_controller.rb +++ b/app/controllers/channels_twitter_controller.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'channel/driver/twitter' - class ChannelsTwitterController < ApplicationController prepend_before_action -> { authentication_check && authorize! }, except: %i[webhook_incoming webhook_verify] skip_before_action :verify_csrf_token, only: %i[webhook_incoming webhook_verify] diff --git a/app/controllers/integration/ldap_controller.rb b/app/controllers/integration/ldap_controller.rb index d68d9de81..c6aec71c3 100644 --- a/app/controllers/integration/ldap_controller.rb +++ b/app/controllers/integration/ldap_controller.rb @@ -1,9 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' -require_dependency 'ldap/user' -require_dependency 'ldap/group' - class Integration::LdapController < ApplicationController include Integration::ImportJobBase diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 695f513e4..4465c98f5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -65,7 +65,6 @@ class SearchController < ApplicationController if objects_with_direct_search_index.present? items = SearchIndexBackend.search(query, objects_with_direct_search_index, limit: limit) items.each do |item| - require_dependency item[:type].to_filename local_class = item[:type].constantize record = local_class.lookup(id: item[:id]) next if !record diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 84fba5b34..625c902b0 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -5,6 +5,8 @@ class ApplicationJob < ActiveJob::Base include ApplicationJob::HasQueuingPriority include ApplicationJob::HasCustomLogging + ActiveJob::Logging::LogSubscriber.detach_from :active_job + # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/jobs/migrate_ldap_samaccountname_to_uid_job.rb b/app/jobs/migrate_ldap_samaccountname_to_uid_job.rb index 4919bf382..1952f486c 100644 --- a/app/jobs/migrate_ldap_samaccountname_to_uid_job.rb +++ b/app/jobs/migrate_ldap_samaccountname_to_uid_job.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' -require_dependency 'ldap/user' - class MigrateLdapSamaccountnameToUidJob < ApplicationJob def perform diff --git a/app/models/application_model/can_assets.rb b/app/models/application_model/can_assets.rb index 3e1411d87..70fc28b87 100644 --- a/app/models/application_model/can_assets.rb +++ b/app/models/application_model/can_assets.rb @@ -158,7 +158,6 @@ get assets of object list def assets_of_object_list(list, assets = {}) list.each do |item| - require_dependency item['object'].to_filename record = item['object'].constantize.lookup(id: item['o_id']) next if record.blank? diff --git a/app/models/application_model/can_latest_change.rb b/app/models/application_model/can_latest_change.rb index 3c38c5d5f..4e55e67cd 100644 --- a/app/models/application_model/can_latest_change.rb +++ b/app/models/application_model/can_latest_change.rb @@ -25,7 +25,7 @@ returns return updated_at if updated_at # if we do not have it cached, do lookup - updated_at = order(updated_at: :desc).limit(1).pluck(:updated_at).first + updated_at = order(updated_at: :desc).limit(1).pick(:updated_at) return if !updated_at diff --git a/app/models/authorization.rb b/app/models/authorization.rb index 95654467c..924ad3f07 100644 --- a/app/models/authorization.rb +++ b/app/models/authorization.rb @@ -6,7 +6,7 @@ class Authorization < ApplicationModel after_update :delete_user_cache after_destroy :delete_user_cache validates :user_id, presence: true - validates :uid, presence: true, uniqueness: { scope: :provider } + validates :uid, presence: true, uniqueness: { case_sensitive: true, scope: :provider } validates :provider, presence: true def self.find_from_hash(hash) diff --git a/app/models/channel.rb b/app/models/channel.rb index edc9b0a29..c937db081 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -315,12 +315,6 @@ load channel driver and return class =end def self.driver_class(adapter) - # we need to require each channel backend individually otherwise we get a - # 'warning: toplevel constant Twitter referenced by Channel::Driver::Twitter' error e.g. - # so we have to convert the channel name to the filename via Rails String.underscore - # http://stem.ps/rails/2015/01/25/ruby-gotcha-toplevel-constant-referenced-by.html - require_dependency "channel/driver/#{adapter.to_filename}" - "::Channel::Driver::#{adapter.to_classname}".constantize end diff --git a/app/models/channel/driver/sms/twilio.rb b/app/models/channel/driver/sms/twilio.rb index be0e7cfad..722e7c4aa 100644 --- a/app/models/channel/driver/sms/twilio.rb +++ b/app/models/channel/driver/sms/twilio.rb @@ -21,7 +21,7 @@ class Channel::Driver::Sms::Twilio body: attr[:message], ) - raise result.error_message if result.error_code.positive? + raise result.error_message if result&.error_code&.positive? end true diff --git a/app/models/channel/driver/twitter.rb b/app/models/channel/driver/twitter.rb index bd807c223..a0aa97875 100644 --- a/app/models/channel/driver/twitter.rb +++ b/app/models/channel/driver/twitter.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'external_credential/twitter' - class Channel::Driver::Twitter =begin diff --git a/app/models/concerns/has_groups.rb b/app/models/concerns/has_groups.rb index e6abd732d..11c1d7437 100644 --- a/app/models/concerns/has_groups.rb +++ b/app/models/concerns/has_groups.rb @@ -159,7 +159,7 @@ module HasGroups # @return [HashString,Array>] The given map def group_names_access_map=(name_access_map) groups_access_map_store(name_access_map) do |group_name| - Group.where(name: group_name).pluck(:id).first + Group.where(name: group_name).pick(:id) end end diff --git a/app/models/concerns/has_ticket_create_screen_impact.rb b/app/models/concerns/has_ticket_create_screen_impact.rb index 7402b6ac8..f86742bfb 100644 --- a/app/models/concerns/has_ticket_create_screen_impact.rb +++ b/app/models/concerns/has_ticket_create_screen_impact.rb @@ -10,7 +10,7 @@ module HasTicketCreateScreenImpact def push_ticket_create_screen? return true if destroyed? - %w[id name active].any? do |attribute| + %w[id name active updated_at].any? do |attribute| saved_change_to_attribute?(attribute) end end diff --git a/app/models/data_privacy_task/validation.rb b/app/models/data_privacy_task/validation.rb index 8fbe325a4..5f38b1a01 100644 --- a/app/models/data_privacy_task/validation.rb +++ b/app/models/data_privacy_task/validation.rb @@ -72,6 +72,7 @@ class DataPrivacyTask::Validation < ActiveModel::Validator deletable: deletable ).where.not( id: record.id, + ).where.not( state: 'failed' ).exists? end diff --git a/app/models/external_credential.rb b/app/models/external_credential.rb index 4e96063c6..dc66378c5 100644 --- a/app/models/external_credential.rb +++ b/app/models/external_credential.rb @@ -35,9 +35,7 @@ class ExternalCredential < ApplicationModel end def self.load_backend(provider) - adapter = "ExternalCredential::#{provider.camelcase}" - require_dependency adapter.to_filename.to_s - adapter.constantize + "ExternalCredential::#{provider.camelcase}".constantize end end diff --git a/app/models/knowledge_base/answer/translation.rb b/app/models/knowledge_base/answer/translation.rb index 2ebed4f36..4957588a3 100644 --- a/app/models/knowledge_base/answer/translation.rb +++ b/app/models/knowledge_base/answer/translation.rb @@ -20,7 +20,7 @@ class KnowledgeBase::Answer::Translation < ApplicationModel validates :title, presence: true, length: { maximum: 250 } validates :content, presence: true - validates :kb_locale_id, uniqueness: { scope: :answer_id } + validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :answer_id } scope :neighbours_of, ->(translation) { joins(:answer).where(knowledge_base_answers: { category_id: translation.answer&.category_id }) } diff --git a/app/models/knowledge_base/category/translation.rb b/app/models/knowledge_base/category/translation.rb index e04959df3..f3016d075 100644 --- a/app/models/knowledge_base/category/translation.rb +++ b/app/models/knowledge_base/category/translation.rb @@ -15,7 +15,7 @@ class KnowledgeBase::Category::Translation < ApplicationModel validates :category, presence: true validates :title, presence: true - validates :kb_locale_id, uniqueness: { scope: :category_id } + validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :category_id } scope :neighbours_of, ->(translation) { joins(:category).where(knowledge_base_categories: { parent_id: translation.category&.parent_id }) } diff --git a/app/models/knowledge_base/locale.rb b/app/models/knowledge_base/locale.rb index fbc6ea0dc..2873bfd9d 100644 --- a/app/models/knowledge_base/locale.rb +++ b/app/models/knowledge_base/locale.rb @@ -4,8 +4,8 @@ class KnowledgeBase::Locale < ApplicationModel belongs_to :knowledge_base, inverse_of: :kb_locales, touch: true belongs_to :system_locale, inverse_of: :knowledge_base_locales, class_name: '::Locale' - validates :primary, uniqueness: { scope: %i[system_locale_id knowledge_base_id] }, if: :primary? - validates :system_locale_id, uniqueness: { scope: :knowledge_base_id } + validates :primary, uniqueness: { case_sensitive: true, scope: %i[system_locale_id knowledge_base_id] }, if: :primary? + validates :system_locale_id, uniqueness: { case_sensitive: true, scope: :knowledge_base_id } has_many :knowledge_base_translations, class_name: 'KnowledgeBase::Translation', inverse_of: :kb_locale, diff --git a/app/models/knowledge_base/translation.rb b/app/models/knowledge_base/translation.rb index df8f0a7ca..73ff345ec 100644 --- a/app/models/knowledge_base/translation.rb +++ b/app/models/knowledge_base/translation.rb @@ -11,7 +11,7 @@ class KnowledgeBase::Translation < ApplicationModel belongs_to :kb_locale, inverse_of: :knowledge_base_translations, class_name: 'KnowledgeBase::Locale' validates :title, presence: true, length: { maximum: 250 } - validates :kb_locale_id, uniqueness: { scope: :knowledge_base_id } + validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :knowledge_base_id } def assets(data) return data if assets_added_to?(data) diff --git a/app/models/object_manager/attribute/validation.rb b/app/models/object_manager/attribute/validation.rb index 4bca31fe2..e774f9f61 100644 --- a/app/models/object_manager/attribute/validation.rb +++ b/app/models/object_manager/attribute/validation.rb @@ -51,7 +51,8 @@ class ObjectManager::Attribute::Validation < ActiveModel::Validator def sanitize_memory_cache @model_attributes = nil - latest_cache_key = active_attributes_in_db.cache_key + active_attributes = active_attributes_in_db + latest_cache_key = active_attributes.cache_key + active_attributes.cache_version return if @previous_cache_key == latest_cache_key @previous_cache_key = latest_cache_key diff --git a/app/models/role.rb b/app/models/role.rb index 846fb4890..e54a189fd 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -116,7 +116,7 @@ returns def self.with_permissions(keys) permission_ids = Role.permission_ids_by_name(keys) - Role.joins(:roles_permissions).joins(:permissions).where( + Role.joins(:permissions_roles).joins(:permissions).where( 'permissions_roles.permission_id IN (?) AND roles.active = ? AND permissions.active = ?', permission_ids, true, true ).distinct() end @@ -140,7 +140,7 @@ returns def with_permission?(keys) permission_ids = Role.permission_ids_by_name(keys) - return true if Role.joins(:roles_permissions).joins(:permissions).where( + return true if Role.joins(:permissions_roles).joins(:permissions).where( 'roles.id = ? AND permissions_roles.permission_id IN (?) AND permissions.active = ?', id, permission_ids, true ).distinct().count.nonzero? diff --git a/app/models/smime_certificate.rb b/app/models/smime_certificate.rb index c554c8ea5..932e79632 100644 --- a/app/models/smime_certificate.rb +++ b/app/models/smime_certificate.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ class SMIMECertificate < ApplicationModel - validates :fingerprint, uniqueness: true + validates :fingerprint, uniqueness: { case_sensitive: true } def self.parse(raw) OpenSSL::X509::Certificate.new(raw.gsub(%r{(?:TRUSTED\s)?(CERTIFICATE---)}, '\1')) diff --git a/app/models/store.rb b/app/models/store.rb index 64fd7a2c5..f87885177 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'store/object' -require_dependency 'store/file' - class Store < ApplicationModel PREFERENCES_SIZE_MAX = 2400 diff --git a/app/models/ticket/calls_stats_ticket_reopen_log.rb b/app/models/ticket/calls_stats_ticket_reopen_log.rb index 7689e6c96..c73c18796 100644 --- a/app/models/ticket/calls_stats_ticket_reopen_log.rb +++ b/app/models/ticket/calls_stats_ticket_reopen_log.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'stats/ticket_reopen' - # Adds new and updated tickets to the reopen log processing. module Ticket::CallsStatsTicketReopenLog extend ActiveSupport::Concern diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 8191006ab..9e070e159 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'escalation' - module Ticket::Escalation extend ActiveSupport::Concern diff --git a/app/models/translation.rb b/app/models/translation.rb index 6825c7bab..62f0c206c 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -244,7 +244,7 @@ or return timestamp.to_s end - record = Translation.where(locale: locale, source: 'timestamp', format: 'time').pluck(:target).first + record = Translation.where(locale: locale, source: 'timestamp', format: 'time').pick(:target) return timestamp.to_s if !record record.sub!('dd', format('%02d', day: timestamp.day)) @@ -286,7 +286,7 @@ or return date.to_s if date.class != Date - record = Translation.where(locale: locale, source: 'date', format: 'time').pluck(:target).first + record = Translation.where(locale: locale, source: 'date', format: 'time').pick(:target) return date.to_s if !record record.sub!('dd', format('%02d', day: date.day)) diff --git a/app/models/user.rb b/app/models/user.rb index 7cd485e53..641a5fe8c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'karma/user' - class User < ApplicationModel include CanBeAuthorized include CanBeImported @@ -14,7 +12,7 @@ class User < ApplicationModel include HasGroups include HasRoles include HasObjectManagerAttributesValidation - include HasTicketCreateScreenImpact + include ::HasTicketCreateScreenImpact include HasTaskbars include User::HasTicketCreateScreenImpact include User::Assets @@ -461,7 +459,7 @@ returns end next if permission_ids.blank? - Role.joins(:roles_permissions).joins(:permissions).where('permissions_roles.permission_id IN (?) AND roles.active = ? AND permissions.active = ?', permission_ids, true, true).distinct().pluck(:id).each do |role_id| + Role.joins(:permissions_roles).joins(:permissions).where('permissions_roles.permission_id IN (?) AND roles.active = ? AND permissions.active = ?', permission_ids, true, true).distinct().pluck(:id).each do |role_id| role_ids.push role_id end total_role_ids.push role_ids @@ -475,7 +473,7 @@ returns end condition += 'roles_users.role_id IN (?)' end - User.joins(:users_roles).where("(#{condition}) AND users.active = ?", *total_role_ids, true).distinct.order(:id) + User.joins(:roles_users).where("(#{condition}) AND users.active = ?", *total_role_ids, true).distinct.order(:id) end =begin @@ -686,11 +684,11 @@ returns def self.of_role(role, group_ids = nil) roles_ids = Role.where(active: true, name: role).map(&:id) if !group_ids - return User.where(active: true).joins(:users_roles).where('roles_users.role_id' => roles_ids).order('users.updated_at DESC') + return User.where(active: true).joins(:roles_users).where('roles_users.role_id' => roles_ids).order('users.updated_at DESC') end User.where(active: true) - .joins(:users_roles) + .joins(:roles_users) .joins(:users_groups) .where('roles_users.role_id IN (?) AND users_groups.group_ids IN (?)', roles_ids, group_ids).order('users.updated_at DESC') end diff --git a/app/models/user/has_ticket_create_screen_impact.rb b/app/models/user/has_ticket_create_screen_impact.rb index a4aa4c168..07526ee0f 100644 --- a/app/models/user/has_ticket_create_screen_impact.rb +++ b/app/models/user/has_ticket_create_screen_impact.rb @@ -1,16 +1,14 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -class User - module HasTicketCreateScreenImpact - extend ActiveSupport::Concern +module User::HasTicketCreateScreenImpact + extend ActiveSupport::Concern - def push_ticket_create_screen? - return true if destroyed? - return false if %w[id login firstname lastname preferences active].none? do |attribute| - saved_change_to_attribute?(attribute) - end - - permissions?('ticket.agent') + def push_ticket_create_screen? + return true if destroyed? + return false if %w[id login firstname lastname preferences active].none? do |attribute| + saved_change_to_attribute?(attribute) end + + permissions?('ticket.agent') end end diff --git a/bin/setup b/bin/setup index cad61e934..84a8aa8c1 100755 --- a/bin/setup +++ b/bin/setup @@ -2,7 +2,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ require 'fileutils' -include FileUtils # rubocop:disable Style/MixinUsage # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -11,24 +10,25 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') - # Install JavaScript dependencies if using Yarn + # Install JavaScript dependencies # system('bin/yarn') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/bin/yarn b/bin/yarn index 5e602628c..c22543d0b 100755 --- a/bin/yarn +++ b/bin/yarn @@ -3,9 +3,11 @@ APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do - exec 'yarnpkg', *ARGV -rescue Errno::ENOENT - warn 'Yarn executable was not detected in the system.' - warn 'Download Yarn at https://yarnpkg.com/en/docs/install' - exit 1 + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end end diff --git a/config/application.rb b/config/application.rb index 235a7b5b1..d8045d69c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,14 +15,27 @@ Bundler.require(*Rails.groups) module Zammad class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.2 + config.load_defaults 6.0 + + Rails.autoloaders.each do |autoloader| + autoloader.do_not_eager_load "#{config.root}/lib/core_ext" + autoloader.collapse "#{config.root}/lib/omniauth" + autoloader.inflector.inflect( + 'github_database' => 'GithubDatabase', + 'otrs' => 'OTRS', + 'db' => 'DB', + ) + end # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + + # the framework and any gems in your application. # Custom directories with classes and modules you want to be autoloadable. - config.autoload_paths += %W[#{config.root}/lib] + config.add_autoload_paths_to_load_path = false + config.autoload_paths += %W[#{config.root}/lib] config.eager_load_paths += %W[#{config.root}/lib] config.active_job.queue_adapter = :delayed_job @@ -36,6 +49,9 @@ module Zammad # define cache store config.cache_store = :zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days } + # Rails 6.1 returns false when the enqueuing is aborted. + config.active_job.return_false_on_aborted_enqueue = true + # default preferences by permission config.preferences_default_by_permission = { 'ticket.agent' => { diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..51373e49a --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: zammad_production diff --git a/config/environments/development.rb b/config/environments/development.rb index f3424d6d9..0ede10343 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -18,6 +18,7 @@ Rails.application.configure do # Run rails dev:cache to toggle caching. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true + # config.action_controller.enable_fragment_cache_logging = true config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" @@ -26,7 +27,7 @@ Rails.application.configure do config.action_controller.perform_caching = false end - # Store uploaded files on the local file system (see config/storage.yml for options) + # Store uploaded files on the local file system (see config/storage.yml for options). # config.active_storage.service = :local # Don't care if the mailer can't send. @@ -51,7 +52,7 @@ Rails.application.configure do # Suppress logger output for asset requests. config.assets.quiet = true - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, @@ -69,4 +70,8 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # TODO: New in Rails 6 + # See https://www.fngtps.com/2019/rails6-blocked-host/ + config.hosts.clear end diff --git a/config/environments/production.rb b/config/environments/production.rb index 3cb7ea613..dd4566bab 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -40,10 +40,10 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - # Store uploaded files on the local file system (see config/storage.yml for options) + # Store uploaded files on the local file system (see config/storage.yml for options). # config.active_storage.service = :local - # Mount Action Cable outside main process or domain + # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] @@ -61,7 +61,7 @@ Rails.application.configure do # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per environment) + # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "zammad_#{Rails.env}" diff --git a/config/environments/test.rb b/config/environments/test.rb index 0bdb30bbd..651945098 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -30,7 +30,7 @@ Rails.application.configure do # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory + # Store uploaded files on the local file system in a temporary directory. # config.active_storage.service = :test config.action_mailer.perform_caching = false @@ -46,7 +46,7 @@ Rails.application.configure do # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Enable autoload diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d6c3ecb24..7d504fd97 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -13,6 +13,8 @@ # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https +# # If you are using webpack-dev-server then specify webpack-dev-server host +# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" @@ -43,6 +45,9 @@ end # If you are using UJS then enable automatic nonce generation Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) } +# Set the nonce only to specific directives +Rails.application.config.content_security_policy_nonce_directives = %w[script-src] + # Report CSP violations to a specified URI # For further information see the following documentation: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only diff --git a/config/initializers/db_preflight_check.rb b/config/initializers/db_preflight_check.rb index b7c013364..c28a31e78 100644 --- a/config/initializers/db_preflight_check.rb +++ b/config/initializers/db_preflight_check.rb @@ -3,4 +3,4 @@ # Rails' constant auto-loading resolves to 'rails/initializable' instead require_dependency 'zammad/application/initializer/db_preflight_check' -Zammad::Application::Initializer::DBPreflightCheck.perform +Zammad::Application::Initializer::DbPreflightCheck.perform diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb new file mode 100644 index 000000000..50ae6f77b --- /dev/null +++ b/config/initializers/new_framework_defaults_6_0.rb @@ -0,0 +1,47 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Don't force requests from old versions of IE to be UTF-8 encoded. +# Rails.application.config.action_view.default_enforce_utf8 = false + +# Embed purpose and expiry metadata inside signed and encrypted +# cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.0. +# Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. +# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false + +# Return false instead of self when enqueuing is aborted from a callback. +# Rails.application.config.active_job.return_false_on_aborted_enqueue = true + +# Send Active Storage analysis and purge jobs to dedicated queues. +# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis +# Rails.application.config.active_storage.queues.purge = :active_storage_purge + +# When assigning to a collection of attachments declared via `has_many_attached`, replace existing +# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. +# Rails.application.config.active_storage.replace_on_assign_to_many = true + +# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. +# +# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), +# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. +# If you send mail in the background, job workers need to have a copy of +# MailDeliveryJob to ensure all delivery jobs are processed properly. +# Make sure your entire app is migrated and stable on 6.0 before using this setting. +# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" + +# Enable the same cache key to be reused when the object being cached of type +# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) +# of the relation's cache key into the cache version to support recycling cache key. +# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/config/initializers/workaround_active_job_logging.rb b/config/initializers/workaround_active_job_logging.rb deleted file mode 100644 index a84c029da..000000000 --- a/config/initializers/workaround_active_job_logging.rb +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ - -# This is a workaround because `ActiveSupport::Subscriber` supports only `attach_to` but not `detach_from` in Rails 5.2. -# `detach_from` was added with Rails 6.0: https://github.com/rails/rails/commit/ca19b7f5d86aa590077766cbe8006f952b6d4296 -# Once Rails 6.0 is used `ActiveJob::Logging::LogSubscriber.detach_from :active_job` needs to be added to `app/jobs/application_job.rb` instead. -ActiveSupport.on_load(:active_job) do - - # gather all `ActiveJob::Logging::LogSubscriber` event subscribers - subscribers = ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers).select do |subscriber| - subscriber.instance_variable_get(:@delegate).instance_of?(ActiveJob::Logging::LogSubscriber) - end - - # remove gathered event subscribers in a dedicated step to not work on iterating array - subscribers.each do |subscriber| - ActiveSupport::Notifications.notifier.unsubscribe(subscriber) - end - - # remove whole `ActiveJob::Logging::LogSubscriber` subscriber reference - ActiveSupport::Subscriber.subscribers.delete_if { |subscriber| subscriber.instance_of?(ActiveJob::Logging::LogSubscriber) } -end diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a857..cf9b342d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -27,7 +27,7 @@ # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. +# available at https://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb index 94635d9d2..2b0ccf8c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,13 +2,15 @@ Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + # app init match '/init', to: 'init#index', via: :get match '/app', to: 'init#index', via: :get # just remember to delete public/index.html. root to: 'init#index', via: :get - root to: 'errors#routing', via: %i[post put delete options] + root to: 'errors#routing', via: %i[post put delete options], as: nil # load routes from external files dir = File.expand_path(__dir__) diff --git a/config/spring.rb b/config/spring.rb index a673e2417..32cbe683a 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,11 +1,11 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -%w[ - .ruby-version - .rbenv-vars - tmp/restart.txt - tmp/caching-dev.txt -].each { |path| Spring.watch(path) } +Spring.watch( + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt', +) module Spring module Commands diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 000000000..d32f76e8f --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/migrate/20191017122807_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb b/db/migrate/20191017122807_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb new file mode 100644 index 000000000..a20930ab0 --- /dev/null +++ b/db/migrate/20191017122807_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb @@ -0,0 +1,12 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +# This migration comes from active_storage (originally 20180723000244) +class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0] + def up + return if foreign_key_exists?(:active_storage_attachments, column: :blob_id) + + return if !table_exists?(:active_storage_blobs) + + add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id + end +end diff --git a/lib/assets/.gitkeep b/lib/assets/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/assets_set.rb b/lib/assets_set.rb index c047b79a6..696bc905b 100644 --- a/lib/assets_set.rb +++ b/lib/assets_set.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'assets_set/proxy' - # The name AssetsSet combines the Assets term in Zammad with the Set class from the Ruby StdLib. # Zammad Assets serve the purpose to limit requests to the REST API. For a requested object all # related and relevant objects are collected recursively and then send to the client in one go. diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index b4aa537b9..ba5f931c6 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' -require_dependency 'ldap/user' - class Auth class Ldap < Auth::Base diff --git a/lib/core_ext/active_record/calculations/pluck_as_hash.rb b/lib/core_ext/active_record/calculations/pluck_as_hash.rb index 692466595..cef12995d 100644 --- a/lib/core_ext/active_record/calculations/pluck_as_hash.rb +++ b/lib/core_ext/active_record/calculations/pluck_as_hash.rb @@ -18,7 +18,7 @@ module ActiveRecord def pluck_as_hash(*column_names) column_names.flatten! # flatten args in case array was given - klass.enforce_raw_sql_whitelist(column_names) # keep up deprection as in #pluck to ensure smooth Rails 6 transition + klass.disallow_raw_sql!(column_names) # validate parameters as in #pluck pluck(*arel_columns(column_names)) .map { |elem| pluck_as_hash_map(column_names, elem) } diff --git a/lib/core_ext/open-uri.rb b/lib/core_ext/kernel.rb similarity index 90% rename from lib/core_ext/open-uri.rb rename to lib/core_ext/kernel.rb index ffdf5af24..5d6e62f50 100644 --- a/lib/core_ext/open-uri.rb +++ b/lib/core_ext/kernel.rb @@ -1,4 +1,3 @@ -# rubocop:disable Naming/FileName # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ if Kernel.respond_to?(:open_uri_original_open) @@ -20,4 +19,3 @@ if Kernel.respond_to?(:open_uri_original_open) end end end -# rubocop:enable Naming/FileName diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 8ba77dc85..70d2223dc 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -227,8 +227,6 @@ returns on fail # connection test result_inbound = {} begin - require_dependency "channel/driver/#{adapter.to_filename}" - driver_class = "Channel::Driver::#{adapter.to_classname}".constantize driver_instance = driver_class.new result_inbound = driver_instance.fetch(params[:options], nil, 'check') @@ -330,8 +328,6 @@ returns on fail # test connection begin - require_dependency "channel/driver/#{adapter.to_filename}" - driver_class = "Channel::Driver::#{adapter.to_classname}".constantize driver_instance = driver_class.new driver_instance.send( diff --git a/lib/email_helper/verify.rb b/lib/email_helper/verify.rb index 4662661dd..191f489cf 100644 --- a/lib/email_helper/verify.rb +++ b/lib/email_helper/verify.rb @@ -82,8 +82,6 @@ or fetch_result = nil begin - require_dependency "channel/driver/#{adapter.to_filename}" - driver_class = "Channel::Driver::#{adapter.to_classname}".constantize driver_instance = driver_class.new fetch_result = driver_instance.fetch(params[:inbound][:options], self, 'verify', subject) diff --git a/lib/excel_sheet/ticket.rb b/lib/excel_sheet/ticket.rb index 1564825b2..624ca1a2a 100644 --- a/lib/excel_sheet/ticket.rb +++ b/lib/excel_sheet/ticket.rb @@ -57,7 +57,9 @@ class ExcelSheet::Ticket < ExcelSheet object_lookup: ObjectLookup.lookup(name: 'Ticket') ) .where.not( - name: header.pluck(:name), + name: header.pluck(:name) + ) + .where.not( display: header.pluck(:display) ) .pluck_as_hash(:name, :display, :data_type, :data_option) diff --git a/lib/fill_db.rb b/lib/fill_db.rb index 1bd583f89..2abd55a98 100644 --- a/lib/fill_db.rb +++ b/lib/fill_db.rb @@ -1,13 +1,13 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ # rubocop:disable Rails/Output -module FillDB +module FillDb =begin fill your database with demo records - FillDB.load( + FillDb.load( agents: 50, customers: 1000, groups: 20, @@ -18,10 +18,10 @@ fill your database with demo records or if you only want to create 100 tickets - FillDB.load(tickets: 100) - FillDB.load(agents: 20) - FillDB.load(overviews: 20) - FillDB.load(tickets: 10000) + FillDb.load(tickets: 100) + FillDb.load(agents: 20) + FillDb.load(overviews: 20) + FillDb.load(tickets: 10000) =end diff --git a/lib/import/exchange/folder.rb b/lib/import/exchange/folder.rb index 0f30577e0..be9d7b943 100644 --- a/lib/import/exchange/folder.rb +++ b/lib/import/exchange/folder.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'mixin/rails_logger' - module Import class Exchange class Folder diff --git a/lib/import/ldap.rb b/lib/import/ldap.rb index 2bfbf5386..4ec2de982 100644 --- a/lib/import/ldap.rb +++ b/lib/import/ldap.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' -require_dependency 'ldap/group' - module Import class Ldap < Import::IntegrationBase include Import::Mixin::Sequence diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index dc3971ece..a999aed19 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -1,28 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# Rails autoload has some issues with same namend sub-classes -# in the importer folder require AND simultaniuos requiring -# of the same file in different threads so we need to -# require them ourself -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 extend Import::Helper diff --git a/lib/import/otrs/dynamic_field/date.rb b/lib/import/otrs/dynamic_field/date.rb index bf6afa5a7..15efbd20d 100644 --- a/lib/import/otrs/dynamic_field/date.rb +++ b/lib/import/otrs/dynamic_field/date.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/otrs/dynamic_field' - module Import module OTRS class DynamicField diff --git a/lib/import/otrs/dynamic_field/date_time.rb b/lib/import/otrs/dynamic_field/date_time.rb index 77fd96a55..ab28cbb8b 100644 --- a/lib/import/otrs/dynamic_field/date_time.rb +++ b/lib/import/otrs/dynamic_field/date_time.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/otrs/dynamic_field' - module Import module OTRS class DynamicField diff --git a/lib/import/otrs/ticket.rb b/lib/import/otrs/ticket.rb index 7f1319701..dc9175a22 100644 --- a/lib/import/otrs/ticket.rb +++ b/lib/import/otrs/ticket.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ticket' - module Import module OTRS class Ticket diff --git a/lib/import/zendesk/object_attribute/checkbox.rb b/lib/import/zendesk/object_attribute/checkbox.rb index 249011dce..a7171af10 100644 --- a/lib/import/zendesk/object_attribute/checkbox.rb +++ b/lib/import/zendesk/object_attribute/checkbox.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/date.rb b/lib/import/zendesk/object_attribute/date.rb index 6e610e702..cc3c21f16 100644 --- a/lib/import/zendesk/object_attribute/date.rb +++ b/lib/import/zendesk/object_attribute/date.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/integer.rb b/lib/import/zendesk/object_attribute/integer.rb index 1f30b0ff0..8e74a2ff4 100644 --- a/lib/import/zendesk/object_attribute/integer.rb +++ b/lib/import/zendesk/object_attribute/integer.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/regexp.rb b/lib/import/zendesk/object_attribute/regexp.rb index e743b824e..6724f1f68 100644 --- a/lib/import/zendesk/object_attribute/regexp.rb +++ b/lib/import/zendesk/object_attribute/regexp.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/select.rb b/lib/import/zendesk/object_attribute/select.rb index b054ace5e..f7b4b4810 100644 --- a/lib/import/zendesk/object_attribute/select.rb +++ b/lib/import/zendesk/object_attribute/select.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/text.rb b/lib/import/zendesk/object_attribute/text.rb index 27fdb15c9..3a0a34c16 100644 --- a/lib/import/zendesk/object_attribute/text.rb +++ b/lib/import/zendesk/object_attribute/text.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/import/zendesk/object_attribute/textarea.rb b/lib/import/zendesk/object_attribute/textarea.rb index 3ca87b348..3d6ffa780 100644 --- a/lib/import/zendesk/object_attribute/textarea.rb +++ b/lib/import/zendesk/object_attribute/textarea.rb @@ -1,10 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -# this require is required (hehe) because of Rails autoloading -# which causes strange behavior not inheriting correctly -# from Import::OTRS::DynamicField -require_dependency 'import/zendesk/object_attribute/base' - module Import class Zendesk module ObjectAttribute diff --git a/lib/ldap.rb b/lib/ldap.rb index 4ca227323..60e3dced7 100644 --- a/lib/ldap.rb +++ b/lib/ldap.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -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 e54ee592b..2b0ecd424 100644 --- a/lib/ldap/group.rb +++ b/lib/ldap/group.rb @@ -3,13 +3,6 @@ class Ldap # Class for handling LDAP Groups. - # ATTENTION: Make sure to add the following lines to your code if accessing this class. - # Otherwise Rails will autoload the Group model or might throw parameter errors if crearing - # an ::Ldap instance. - # - # @example - # require_dependency 'ldap' - # require_dependency 'ldap/group' class Group include Ldap::FilterLookup @@ -31,8 +24,6 @@ class Ldap # @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration. # # @example - # 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 c6314924c..ecf5220f8 100644 --- a/lib/ldap/user.rb +++ b/lib/ldap/user.rb @@ -3,13 +3,6 @@ class Ldap # Class for handling LDAP Groups. - # ATTENTION: Make sure to add the following lines to your code if accessing this class. - # Otherwise Rails will autoload the Group model or might throw parameter errors if crearing - # an ::Ldap instance. - # - # @example - # require_dependency 'ldap' - # require_dependency 'ldap/user' class User include Ldap::FilterLookup @@ -79,8 +72,6 @@ class Ldap # @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration. # # @example - # require_dependency 'ldap' - # require_dependency 'ldap/user' # ldap_user = Ldap::User.new # # @return [nil] diff --git a/lib/mixin/required_sub_paths.rb b/lib/mixin/required_sub_paths.rb index 2baa99e12..3a6848130 100644 --- a/lib/mixin/required_sub_paths.rb +++ b/lib/mixin/required_sub_paths.rb @@ -9,18 +9,10 @@ module Mixin eager_load_recursive(sub_path) end - # Loads a directory recursively. - # The specialty of this method is that it will first load all - # files in a directory and then start with the sub directories. - # This is needed since otherwise some parent namespaces might not - # be initialized yet. - # - # The cause of this is that Rails autoload doesn't work properly - # for same named classes or modules in different namespaces. - # Here is a good description how autoload works: - # http://urbanautomaton.com/blog/2013/08/27/rails-autoloading-hell/ - # - # This avoids a) Rails autoloading issues and b) require '...' workarounds + # Loads a directory recursively. This can be needed when accessing + # modules not directly via .constantize on a known string, but dynamically + # via the inheritance tree, e.g. via .descendants (which assumes they have + # previously been loaded). def self.eager_load_recursive(path) excluded = ['.', '..'] diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 42319cc5c..585e40cc6 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -298,7 +298,7 @@ remove whole data from index query_data = build_query(condition, options) if (fields = options.dig(:highlight_fields_by_indexes, index.to_sym)) - fields_for_highlight = fields.each_with_object({}) { |elem, memo| memo[elem] = {} } + fields_for_highlight = fields.index_with { |_elem| {} } query_data[:highlight] = { fields: fields_for_highlight } end diff --git a/lib/sequencer.rb b/lib/sequencer.rb index 8440e25ed..c384e7854 100644 --- a/lib/sequencer.rb +++ b/lib/sequencer.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'mixin/rails_logger' -require_dependency 'mixin/start_finish_logger' - class Sequencer include ::Mixin::RailsLogger include ::Mixin::StartFinishLogger diff --git a/lib/sequencer/sequence.rb b/lib/sequencer/sequence.rb index 9ad180cb8..2f81f81e1 100644 --- a/lib/sequencer/sequence.rb +++ b/lib/sequencer/sequence.rb @@ -1,10 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/mixin/prefixed_constantize' - class Sequencer class Sequence - include ::Mixin::RequiredSubPaths extend ::Sequencer::Mixin::PrefixedConstantize PREFIX = 'Sequencer::Sequence::'.freeze diff --git a/lib/sequencer/sequence/import/zendesk/ticket.rb b/lib/sequencer/sequence/import/zendesk/ticket.rb index c657bc95a..0ef62a7ec 100644 --- a/lib/sequencer/sequence/import/zendesk/ticket.rb +++ b/lib/sequencer/sequence/import/zendesk/ticket.rb @@ -9,14 +9,14 @@ class Sequencer def self.sequence [ 'Import::Zendesk::Ticket::Skip::Deleted', - 'Import::Zendesk::Ticket::UserID', - 'Import::Zendesk::Ticket::OwnerID', - 'Import::Zendesk::Ticket::GroupID', - 'Import::Zendesk::Ticket::OrganizationID', - 'Import::Zendesk::Ticket::PriorityID', - 'Import::Zendesk::Ticket::StateID', - 'Import::Zendesk::Common::ArticleSenderID', - 'Import::Zendesk::Common::ArticleTypeID', + 'Import::Zendesk::Ticket::UserId', + 'Import::Zendesk::Ticket::OwnerId', + 'Import::Zendesk::Ticket::GroupId', + 'Import::Zendesk::Ticket::OrganizationId', + 'Import::Zendesk::Ticket::PriorityId', + 'Import::Zendesk::Ticket::StateId', + 'Import::Zendesk::Common::ArticleSenderId', + 'Import::Zendesk::Common::ArticleTypeId', 'Import::Zendesk::Ticket::Subject', 'Import::Zendesk::Ticket::CustomFields', 'Import::Zendesk::Ticket::Mapping', diff --git a/lib/sequencer/sequence/import/zendesk/ticket/comment.rb b/lib/sequencer/sequence/import/zendesk/ticket/comment.rb index 242370d0a..f8a393037 100644 --- a/lib/sequencer/sequence/import/zendesk/ticket/comment.rb +++ b/lib/sequencer/sequence/import/zendesk/ticket/comment.rb @@ -9,9 +9,9 @@ class Sequencer def self.sequence [ - 'Import::Zendesk::Ticket::Comment::UserID', - 'Import::Zendesk::Common::ArticleSenderID', - 'Import::Zendesk::Common::ArticleTypeID', + 'Import::Zendesk::Ticket::Comment::UserId', + 'Import::Zendesk::Common::ArticleSenderId', + 'Import::Zendesk::Common::ArticleTypeId', 'Import::Zendesk::Ticket::Comment::From', 'Import::Zendesk::Ticket::Comment::To', 'Import::Zendesk::Ticket::Comment::Mapping', diff --git a/lib/sequencer/sequence/import/zendesk/user.rb b/lib/sequencer/sequence/import/zendesk/user.rb index ed4ff901e..8ef542aa8 100644 --- a/lib/sequencer/sequence/import/zendesk/user.rb +++ b/lib/sequencer/sequence/import/zendesk/user.rb @@ -14,7 +14,7 @@ class Sequencer 'Import::Zendesk::User::Login', 'Import::Zendesk::User::Password', 'Import::Zendesk::User::ImageSource', - 'Import::Zendesk::User::OrganizationID', + 'Import::Zendesk::User::OrganizationId', 'Common::ModelClass::User', 'Import::Zendesk::User::Mapping', 'Import::Zendesk::User::CustomFields', diff --git a/lib/sequencer/state.rb b/lib/sequencer/state.rb index ae7f66ce6..9f770eab3 100644 --- a/lib/sequencer/state.rb +++ b/lib/sequencer/state.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'mixin/rails_logger' -require_dependency 'mixin/start_finish_logger' - class Sequencer class State include ::Mixin::RailsLogger @@ -166,7 +163,7 @@ class Sequencer # # @return [Hash{Symbol => Object}] def to_h - available.map { |identifier| [identifier, @values[identifier]] }.to_h + available.index_with { |identifier| @values[identifier] } end private diff --git a/lib/sequencer/unit.rb b/lib/sequencer/unit.rb index c8d5a5fbf..8abc525ac 100644 --- a/lib/sequencer/unit.rb +++ b/lib/sequencer/unit.rb @@ -1,10 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/mixin/prefixed_constantize' - class Sequencer class Unit - include ::Mixin::RequiredSubPaths extend ::Sequencer::Mixin::PrefixedConstantize PREFIX = 'Sequencer::Unit::'.freeze diff --git a/lib/sequencer/unit/base.rb b/lib/sequencer/unit/base.rb index 3f3b91dd3..500e35a2a 100644 --- a/lib/sequencer/unit/base.rb +++ b/lib/sequencer/unit/base.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'mixin/rails_logger' - class Sequencer class Unit class Base diff --git a/lib/sequencer/unit/import/common/model/associations/assign.rb b/lib/sequencer/unit/import/common/model/associations/assign.rb index 6020a3896..d46c9a8a6 100644 --- a/lib/sequencer/unit/import/common/model/associations/assign.rb +++ b/lib/sequencer/unit/import/common/model/associations/assign.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/common/model/save.rb b/lib/sequencer/unit/import/common/model/save.rb index c85af9ee2..aa31a9901 100644 --- a/lib/sequencer/unit/import/common/model/save.rb +++ b/lib/sequencer/unit/import/common/model/save.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure' - class Sequencer class Unit module Import 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 054437224..612bf73de 100644 --- a/lib/sequencer/unit/import/common/model/skip/blank/base.rb +++ b/lib/sequencer/unit/import/common/model/skip/blank/base.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/common/mixin/dynamic_attribute' -require_dependency 'sequencer/unit/import/common/model/mixin/log/context_identification_string' - # This unit checks if an Sequencer state attribute (e.g. `mapped`) is blank. # Don't confuse it with e.g. 'Import::Common::Model::Skip::MissingMandatory::Base' which checks if an attribute key (e.g. mapped[:some_key]) is blank/missing. class Sequencer 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 be38da2d1..79e855245 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,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/common/mixin/dynamic_attribute' -require_dependency 'sequencer/unit/import/common/model/mixin/log/context_identification_string' - class Sequencer class Unit module Import 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 c1ef9311b..dad1aa3e8 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,6 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -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 ddf577758..b719dcf20 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,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -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/top_level.rb b/lib/sequencer/unit/import/common/model/statistics/diff/top_level.rb index 1697394a1..57dcc8abf 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,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' - class Sequencer class Unit module Import 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 89b3cfeaa..09c4647c3 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,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/common/model/statistics/mixin/common.rb b/lib/sequencer/unit/import/common/model/statistics/mixin/common.rb index b1f4e0875..134d72b45 100644 --- a/lib/sequencer/unit/import/common/model/statistics/mixin/common.rb +++ b/lib/sequencer/unit/import/common/model/statistics/mixin/common.rb @@ -19,7 +19,7 @@ class Sequencer end def empty_diff - possible_actions.collect { |key| [key, 0] }.to_h + possible_actions.index_with { |_key| 0 } end def possible_actions 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 39dcfcfe5..128d8596c 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,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/freshdesk/agents/groups_permissions.rb b/lib/sequencer/unit/import/freshdesk/agents/groups_permissions.rb index ee50b4eb7..46543c46f 100644 --- a/lib/sequencer/unit/import/freshdesk/agents/groups_permissions.rb +++ b/lib/sequencer/unit/import/freshdesk/agents/groups_permissions.rb @@ -18,8 +18,8 @@ class Sequencer def group_ids_access_map @group_ids_access_map ||= begin - ::Group.all.pluck(:id).each_with_object({}) do |group_id, result| - result[group_id] = 'full'.freeze + ::Group.all.pluck(:id).index_with do + 'full'.freeze end end end diff --git a/lib/sequencer/unit/import/ldap/user/statistics/diff.rb b/lib/sequencer/unit/import/ldap/user/statistics/diff.rb index 6e4db1285..98533c0a1 100644 --- a/lib/sequencer/unit/import/ldap/user/statistics/diff.rb +++ b/lib/sequencer/unit/import/ldap/user/statistics/diff.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/ldap/users/dry_run/payload.rb b/lib/sequencer/unit/import/ldap/users/dry_run/payload.rb index e2f30153b..e5321602b 100644 --- a/lib/sequencer/unit/import/ldap/users/dry_run/payload.rb +++ b/lib/sequencer/unit/import/ldap/users/dry_run/payload.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Ldap module Users - class DryRun + module DryRun class Payload < Sequencer::Unit::Import::Common::ImportJob::Payload::ToAttribute provides :ldap_config end 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 edb7bf5f4..dbc6e04f5 100644 --- a/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb +++ b/lib/sequencer/unit/import/ldap/users/lost/statistics_diff.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/ldap/users/sub_sequence.rb b/lib/sequencer/unit/import/ldap/users/sub_sequence.rb index f783f261f..a39b0e86c 100644 --- a/lib/sequencer/unit/import/ldap/users/sub_sequence.rb +++ b/lib/sequencer/unit/import/ldap/users/sub_sequence.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/sub_sequence/mixin/import_job' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/ldap/users/total.rb b/lib/sequencer/unit/import/ldap/users/total.rb index 3aadbfa83..7825edfec 100644 --- a/lib/sequencer/unit/import/ldap/users/total.rb +++ b/lib/sequencer/unit/import/ldap/users/total.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/unit/import/common/model/statistics/mixin/empty_diff' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/ldap/users/user_roles.rb b/lib/sequencer/unit/import/ldap/users/user_roles.rb index d0d6ba065..6c590d619 100644 --- a/lib/sequencer/unit/import/ldap/users/user_roles.rb +++ b/lib/sequencer/unit/import/ldap/users/user_roles.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' -require_dependency 'ldap/group' - class Sequencer class Unit module Import diff --git a/lib/sequencer/unit/import/zendesk/common/article_sender_id.rb b/lib/sequencer/unit/import/zendesk/common/article_sender_id.rb index 4d09a4014..a00e6b669 100644 --- a/lib/sequencer/unit/import/zendesk/common/article_sender_id.rb +++ b/lib/sequencer/unit/import/zendesk/common/article_sender_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Common - class ArticleSenderID < Sequencer::Unit::Common::Provider::Named + class ArticleSenderId < Sequencer::Unit::Common::Provider::Named uses :user_id diff --git a/lib/sequencer/unit/import/zendesk/common/article_type_id.rb b/lib/sequencer/unit/import/zendesk/common/article_type_id.rb index bad4d61be..e29184a0b 100644 --- a/lib/sequencer/unit/import/zendesk/common/article_type_id.rb +++ b/lib/sequencer/unit/import/zendesk/common/article_type_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Common - class ArticleTypeID < Sequencer::Unit::Common::Provider::Named + class ArticleTypeId < Sequencer::Unit::Common::Provider::Named uses :resource diff --git a/lib/sequencer/unit/import/zendesk/objects_total_count.rb b/lib/sequencer/unit/import/zendesk/objects_total_count.rb index 37a9dd855..3451e8af6 100644 --- a/lib/sequencer/unit/import/zendesk/objects_total_count.rb +++ b/lib/sequencer/unit/import/zendesk/objects_total_count.rb @@ -12,8 +12,8 @@ class Sequencer private def statistics_diff - %i[Groups Users Organizations Tickets].each_with_object({}) do |object, stats| - stats[object] = empty_diff.merge( + %i[Groups Users Organizations Tickets].index_with do |object| + empty_diff.merge( total: request(object).count! ) end diff --git a/lib/sequencer/unit/import/zendesk/ticket/comment/user_id.rb b/lib/sequencer/unit/import/zendesk/ticket/comment/user_id.rb index ad487df84..488624279 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/comment/user_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/comment/user_id.rb @@ -6,7 +6,7 @@ class Sequencer module Zendesk module Ticket module Comment - class UserID < Sequencer::Unit::Base + class UserId < Sequencer::Unit::Base uses :resource, :user_map provides :user_id diff --git a/lib/sequencer/unit/import/zendesk/ticket/group_id.rb b/lib/sequencer/unit/import/zendesk/ticket/group_id.rb index 1068520f2..722516ec3 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/group_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/group_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class GroupID < Sequencer::Unit::Common::Provider::Named + class GroupId < Sequencer::Unit::Common::Provider::Named uses :resource, :group_map diff --git a/lib/sequencer/unit/import/zendesk/ticket/organization_id.rb b/lib/sequencer/unit/import/zendesk/ticket/organization_id.rb index 63d6088e6..54f281fae 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/organization_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/organization_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class OrganizationID < Sequencer::Unit::Common::Provider::Named + class OrganizationId < Sequencer::Unit::Common::Provider::Named uses :resource, :organization_map diff --git a/lib/sequencer/unit/import/zendesk/ticket/owner_id.rb b/lib/sequencer/unit/import/zendesk/ticket/owner_id.rb index b0927fce8..0444ca29b 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/owner_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/owner_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class OwnerID < Sequencer::Unit::Common::Provider::Named + class OwnerId < Sequencer::Unit::Common::Provider::Named uses :resource, :user_map diff --git a/lib/sequencer/unit/import/zendesk/ticket/priority_id.rb b/lib/sequencer/unit/import/zendesk/ticket/priority_id.rb index 23fb67c01..6f8331e18 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/priority_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/priority_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class PriorityID < Sequencer::Unit::Common::Provider::Named + class PriorityId < Sequencer::Unit::Common::Provider::Named uses :resource diff --git a/lib/sequencer/unit/import/zendesk/ticket/state_id.rb b/lib/sequencer/unit/import/zendesk/ticket/state_id.rb index 80a361e98..ab29fe023 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/state_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/state_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class StateID < Sequencer::Unit::Common::Provider::Named + class StateId < Sequencer::Unit::Common::Provider::Named uses :resource diff --git a/lib/sequencer/unit/import/zendesk/ticket/user_id.rb b/lib/sequencer/unit/import/zendesk/ticket/user_id.rb index 7716fc708..e180a17c6 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/user_id.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/user_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module Ticket - class UserID < Sequencer::Unit::Common::Provider::Named + class UserId < Sequencer::Unit::Common::Provider::Named uses :resource, :user_map diff --git a/lib/sequencer/unit/import/zendesk/user/organization_id.rb b/lib/sequencer/unit/import/zendesk/user/organization_id.rb index 9c8f76055..100a19ee4 100644 --- a/lib/sequencer/unit/import/zendesk/user/organization_id.rb +++ b/lib/sequencer/unit/import/zendesk/user/organization_id.rb @@ -5,7 +5,7 @@ class Sequencer module Import module Zendesk module User - class OrganizationID < Sequencer::Unit::Common::Provider::Named + class OrganizationId < Sequencer::Unit::Common::Provider::Named uses :resource, :organization_map diff --git a/lib/sequencer/unit/ldap/config.rb b/lib/sequencer/unit/ldap/config.rb index ac4af49b6..ee649edd4 100644 --- a/lib/sequencer/unit/ldap/config.rb +++ b/lib/sequencer/unit/ldap/config.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'import/ldap' - class Sequencer class Unit module Ldap diff --git a/lib/sequencer/unit/ldap/connection.rb b/lib/sequencer/unit/ldap/connection.rb index 963238924..aa48f14dd 100644 --- a/lib/sequencer/unit/ldap/connection.rb +++ b/lib/sequencer/unit/ldap/connection.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'ldap' - class Sequencer class Unit module Ldap diff --git a/lib/sequencer/units.rb b/lib/sequencer/units.rb index f9302ba83..bd3c2866d 100644 --- a/lib/sequencer/units.rb +++ b/lib/sequencer/units.rb @@ -1,8 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require_dependency 'sequencer/units/attribute' -require_dependency 'sequencer/units/attributes' - class Sequencer class Units < SimpleDelegator include ::Enumerable diff --git a/lib/session_helper.rb b/lib/session_helper.rb index 3ddca6c37..bd8350bae 100644 --- a/lib/session_helper.rb +++ b/lib/session_helper.rb @@ -3,7 +3,6 @@ module SessionHelper def self.json_hash(user) collections, assets = default_collections(user) - { session: user.filter_attributes(user.attributes), models: models(user), @@ -20,10 +19,10 @@ module SessionHelper # load collections to deliver from external files dir = File.expand_path('..', __dir__) - files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb") + files = Dir.glob( "#{dir}/lib/session_helper/collection_*.rb") files.each do |file| - load file - (default_collection, assets) = ExtraCollection.session(default_collection, assets, user) + file =~ %r{/(session_helper/collection_.*)\.rb\z} + (default_collection, assets) = $1.camelize.constantize.session(default_collection, assets, user) end [default_collection, assets] diff --git a/app/controllers/sessions/collection_base.rb b/lib/session_helper/collection_base.rb similarity index 97% rename from app/controllers/sessions/collection_base.rb rename to lib/session_helper/collection_base.rb index d973f70c2..3f3a16351 100644 --- a/app/controllers/sessions/collection_base.rb +++ b/lib/session_helper/collection_base.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -module ExtraCollection +module SessionHelper::CollectionBase module_function diff --git a/app/controllers/sessions/collection_dashboard.rb b/lib/session_helper/collection_dashboard.rb similarity index 90% rename from app/controllers/sessions/collection_dashboard.rb rename to lib/session_helper/collection_dashboard.rb index 1e32228e9..39b9049b3 100644 --- a/app/controllers/sessions/collection_dashboard.rb +++ b/lib/session_helper/collection_dashboard.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -module ExtraCollection +module SessionHelper::CollectionDashboard module_function diff --git a/app/controllers/sessions/collection_ticket.rb b/lib/session_helper/collection_ticket.rb similarity index 97% rename from app/controllers/sessions/collection_ticket.rb rename to lib/session_helper/collection_ticket.rb index 78f1eb31d..1423731ae 100644 --- a/app/controllers/sessions/collection_ticket.rb +++ b/lib/session_helper/collection_ticket.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -module ExtraCollection +module SessionHelper::CollectionTicket module_function diff --git a/lib/stats.rb b/lib/stats.rb index 44a9b6922..fd517fa22 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -41,7 +41,6 @@ returns raise "Dashboard::Stats backend #{stats_item.name} is not defined" end - require_dependency backend.to_filename backend = backend.constantize data[backend] = backend.generate(user) diff --git a/lib/tasks/zammad/db/reset.rake b/lib/tasks/zammad/db/reset.rake index 93ee907dc..f60d0e90e 100644 --- a/lib/tasks/zammad/db/reset.rake +++ b/lib/tasks/zammad/db/reset.rake @@ -12,6 +12,13 @@ namespace :zammad do # there is no way in rake to achieve that %w[db:drop:_unsafe db:create db:migrate db:seed].each do |task| + if task == 'db:drop:_unsafe' + # ensure all DB connections are closed before dropping the DB + # since Rails > 5.2 two connections are present (after `db:migrate`) that + # block dropping the DB for PostgreSQL + ActiveRecord::Base.connection_handler.connection_pools.each(&:disconnect!) + end + $stdout = StringIO.new if task == 'db:migrate'.freeze Rake::Task[task].reenable diff --git a/lib/twitter/streaming/client_custom.rb b/lib/twitter/streaming/client_custom.rb index f8557a8ff..93b01e4b0 100644 --- a/lib/twitter/streaming/client_custom.rb +++ b/lib/twitter/streaming/client_custom.rb @@ -2,7 +2,6 @@ # file is based on Twitter::Streaming::Client, needed to get custom_connection_handle # to close connection after config has changed -require_dependency 'twitter/streaming/connection_custom' class Twitter::Streaming::ClientCustom < Twitter::Streaming::Client diff --git a/lib/zammad/application/initializer/db_preflight_check.rb b/lib/zammad/application/initializer/db_preflight_check.rb index 7d5f2102c..5ff55d0e4 100644 --- a/lib/zammad/application/initializer/db_preflight_check.rb +++ b/lib/zammad/application/initializer/db_preflight_check.rb @@ -8,7 +8,7 @@ require 'zammad/application/initializer/db_preflight_check/nulldb' module Zammad class Application class Initializer - module DBPreflightCheck + module DbPreflightCheck def self.perform adapter.perform end diff --git a/lib/zammad/application/initializer/db_preflight_check/base.rb b/lib/zammad/application/initializer/db_preflight_check/base.rb index 72e7bb269..272910e07 100644 --- a/lib/zammad/application/initializer/db_preflight_check/base.rb +++ b/lib/zammad/application/initializer/db_preflight_check/base.rb @@ -14,7 +14,7 @@ module Zammad class Application class Initializer - module DBPreflightCheck + module DbPreflightCheck module Base def check_version_compatibility return if Gem::Version.new(current_version) >= Gem::Version.new(min_version) diff --git a/lib/zammad/application/initializer/db_preflight_check/mysql2.rb b/lib/zammad/application/initializer/db_preflight_check/mysql2.rb index 40fb84e2a..52b242eae 100644 --- a/lib/zammad/application/initializer/db_preflight_check/mysql2.rb +++ b/lib/zammad/application/initializer/db_preflight_check/mysql2.rb @@ -13,7 +13,7 @@ module Zammad class Application class Initializer - module DBPreflightCheck + module DbPreflightCheck module Mysql2 extend Base diff --git a/lib/zammad/application/initializer/db_preflight_check/nulldb.rb b/lib/zammad/application/initializer/db_preflight_check/nulldb.rb index 3af08e3af..cff45f70a 100644 --- a/lib/zammad/application/initializer/db_preflight_check/nulldb.rb +++ b/lib/zammad/application/initializer/db_preflight_check/nulldb.rb @@ -3,7 +3,7 @@ module Zammad class Application class Initializer - module DBPreflightCheck + module DbPreflightCheck module Nulldb # no-op def self.perform; end diff --git a/lib/zammad/application/initializer/db_preflight_check/postgresql.rb b/lib/zammad/application/initializer/db_preflight_check/postgresql.rb index b4d325bc3..3f0bb193f 100644 --- a/lib/zammad/application/initializer/db_preflight_check/postgresql.rb +++ b/lib/zammad/application/initializer/db_preflight_check/postgresql.rb @@ -13,7 +13,7 @@ module Zammad class Application class Initializer - module DBPreflightCheck + module DbPreflightCheck module Postgresql extend Base diff --git a/spec/factories/token.rb b/spec/factories/token.rb index 2a123d95d..948003056 100644 --- a/spec/factories/token.rb +++ b/spec/factories/token.rb @@ -7,8 +7,8 @@ FactoryBot.define do persistent { true } preferences do - permission_hash = permissions.each_with_object({}) do |permission, result| - result[permission] = true + permission_hash = permissions.index_with do |_permission| + true end { diff --git a/spec/lib/import/otrs/history_examples.rb b/spec/lib/import/otrs/history_examples.rb index b99910ac9..c50486359 100644 --- a/spec/lib/import/otrs/history_examples.rb +++ b/spec/lib/import/otrs/history_examples.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ require 'rails_helper' -require 'history' def history_from_json(file, zammad_structure) expect(History).to receive(:add).with(zammad_structure) diff --git a/spec/lib/ldap/group_spec.rb b/spec/lib/ldap/group_spec.rb index 1f4b650d3..3700eab7a 100644 --- a/spec/lib/ldap/group_spec.rb +++ b/spec/lib/ldap/group_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Ldap::Group do end end - context 'initialization config parameters' do + describe 'initialization config parameters' do it 'reuses given Ldap instance if given' do config = {} @@ -62,7 +62,7 @@ RSpec.describe Ldap::Group do end end - context 'instance methods' do + describe 'instance methods' do let(:initialization_config) do { diff --git a/spec/lib/ldap/user_spec.rb b/spec/lib/ldap/user_spec.rb index 6c73f7476..09aac1eb2 100644 --- a/spec/lib/ldap/user_spec.rb +++ b/spec/lib/ldap/user_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Ldap::User do # expectations and reuse it in 'let' instance # as additional parameter - context 'initialization config parameters' do + describe 'initialization config parameters' do it 'reuses given Ldap instance if given' do expect(Ldap).not_to receive(:new) @@ -75,7 +75,7 @@ RSpec.describe Ldap::User do end end - context 'instance methods' do + describe 'instance methods' do let(:initialization_config) do { @@ -204,7 +204,7 @@ RSpec.describe Ldap::User do # Each of these test cases depends on # sample TCP transmission data recorded with TCR, # stored in test/data/tcr_cassettes. - context 'on mocked LDAP connections' do + describe 'on mocked LDAP connections' do around do |example| cassette_name = example.description.gsub(%r{[^0-9A-Za-z.\-]+}, '_') @@ -217,7 +217,7 @@ RSpec.describe Ldap::User do end end - describe '#attributes' do + describe 'attributes' do let(:subject) { described_class.new(config, ldap: ldap) } let(:ldap) { Ldap.new(config) } let(:config) do diff --git a/spec/lib/ldap_spec.rb b/spec/lib/ldap_spec.rb index d28df3695..3abca51b5 100644 --- a/spec/lib/ldap_spec.rb +++ b/spec/lib/ldap_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' RSpec.describe Ldap do - context 'initialization config parameters' do + describe 'initialization config parameters' do # required as 'let' to perform test based # expectations and reuse it in mock_initialization @@ -29,7 +29,7 @@ RSpec.describe Ldap do ) end - context 'bind credentials' do + describe 'bind credentials' do it 'uses given credentials' do @@ -115,7 +115,7 @@ RSpec.describe Ldap do ) end - context 'host_url' do + describe 'host_url' do it 'parses protocol and host' do config = { host_url: 'ldaps://localhost' @@ -205,7 +205,7 @@ RSpec.describe Ldap do end end - context 'instance methods' do + describe 'instance methods' do # required as 'let' to perform test based # expectations and reuse it in 'let' instance diff --git a/spec/lib/stats_spec.rb b/spec/lib/stats_spec.rb index 4d7884d26..94aaf2ebc 100644 --- a/spec/lib/stats_spec.rb +++ b/spec/lib/stats_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Stats do it 'fails for unknown backend' do Setting.set('Stats::TicketWaitingTime', 'Stats::UNKNOWN') - expect { described_class.generate }.to raise_error(LoadError) + expect { described_class.generate }.to raise_error(NameError) end end end diff --git a/spec/lib/zammad/application/initializer/session_store_spec.rb b/spec/lib/zammad/application/initializer/session_store_spec.rb index 8d4767bf6..06735e4c9 100644 --- a/spec/lib/zammad/application/initializer/session_store_spec.rb +++ b/spec/lib/zammad/application/initializer/session_store_spec.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ require 'rails_helper' -require_dependency 'zammad/application/initializer/session_store' RSpec.describe Zammad::Application::Initializer::SessionStore do describe '.perform' do diff --git a/spec/models/application_model/checks_import_examples.rb b/spec/models/application_model/checks_import_examples.rb index b78c313ac..6c85a96e3 100644 --- a/spec/models/application_model/checks_import_examples.rb +++ b/spec/models/application_model/checks_import_examples.rb @@ -21,7 +21,7 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do before { Setting.set('system_init_done', false) } it 'allows explicit setting of #id attribute' do - expect { subject.save }.not_to change(subject, :id) + expect { subject.save! }.not_to change(subject, :id) end end @@ -32,7 +32,7 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do before { Setting.set('import_mode', false) } it 'prevents explicit setting of #id attribute' do - expect { subject.save }.to change(subject, :id) + expect { subject.save! }.to change(subject, :id) end end @@ -41,13 +41,13 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do shared_examples 'importable classes' do it 'allows explicit setting of #id attribute' do - expect { subject.save }.not_to change(subject, :id) + expect { subject.save! }.not_to change(subject, :id) end end shared_examples 'non-importable classes' do it 'prevents explicit setting of #id attribute' do - expect { subject.save }.to change(subject, :id) + expect { subject.save! }.to change(subject, :id) end end diff --git a/spec/models/concerns/has_groups_examples.rb b/spec/models/concerns/has_groups_examples.rb index 2947d2401..a785d721d 100644 --- a/spec/models/concerns/has_groups_examples.rb +++ b/spec/models/concerns/has_groups_examples.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ RSpec.shared_examples 'HasGroups' do |group_access_factory:| - context 'group' do + describe 'group' do subject { create(group_access_factory) } let(:group_full) { create(:group) } @@ -46,7 +46,7 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:| expect(subject.groups).to respond_to(:access) end - context 'result' do + describe 'result' do before do subject.group_names_access_map = { @@ -154,7 +154,7 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:| expect(subject.group_ids_access('read')).to be_empty end - context 'single access' do + describe 'single access' do it 'lists access Group IDs' do result = subject.group_ids_access('read') @@ -167,7 +167,7 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:| end end - context 'access list' do + describe 'access list' do it 'lists access Group IDs' do result = subject.group_ids_access(%w[read change]) diff --git a/spec/models/concerns/has_roles_examples.rb b/spec/models/concerns/has_roles_examples.rb index 0855a5ce4..c5593b4f6 100644 --- a/spec/models/concerns/has_roles_examples.rb +++ b/spec/models/concerns/has_roles_examples.rb @@ -102,7 +102,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:| end end - context 'group' do + describe 'group' do before do role.group_names_access_map = { @@ -155,7 +155,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:| expect(result).not_to include(group_inactive.id) end - context 'single access' do + describe 'single access' do it 'lists access Group IDs' do result = subject.group_ids_access('read') @@ -177,7 +177,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:| end end - context 'access list' do + describe 'access list' do it 'lists access Group IDs' do result = subject.group_ids_access(%w[read change]) diff --git a/spec/models/concerns/has_search_index_backend_examples.rb b/spec/models/concerns/has_search_index_backend_examples.rb index 9daf2c1a2..12b8f43e5 100644 --- a/spec/models/concerns/has_search_index_backend_examples.rb +++ b/spec/models/concerns/has_search_index_backend_examples.rb @@ -9,7 +9,7 @@ RSpec.shared_examples 'HasSearchIndexBackend' do |indexed_factory:| allow(SearchIndexBackend).to receive(:enabled?).and_return(true) end - context 'record indexing' do + describe 'record indexing' do before do expect(subject).to be_present diff --git a/spec/models/import_job_spec.rb b/spec/models/import_job_spec.rb index 2b7f80482..12b86e59c 100644 --- a/spec/models/import_job_spec.rb +++ b/spec/models/import_job_spec.rb @@ -157,7 +157,7 @@ RSpec.describe ImportJob do expect do described_class.start_registered end.to change { - described_class.where.not(started_at: nil, finished_at: nil).count + described_class.where.not(started_at: nil).where.not(finished_at: nil).count }.by(1) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3e8a59316..ad2b531b1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1255,11 +1255,11 @@ RSpec.describe User, type: :model do user.save end - it 'updates CallerId record on touch/update (via Cti::CallerId.build)' do + it 'does not update CallerId record on touch/update (via Cti::CallerId.build)' do + expect(Cti::CallerId).to receive(:build).with(user) user.save - expect(Cti::CallerId).to receive(:build).with(user) - + expect(Cti::CallerId).not_to receive(:build).with(user) user.touch end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 64014fcc2..1b53554b4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -25,10 +25,14 @@ require 'rspec/rails' # Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } -# Checks for pending migration and applies them before tests are run. -# If you are not using ActiveRecord, you can remove this line. +# Checks if the database schema is up-to-date and re-creates the database if needed. ActiveRecord::Migration.maintain_test_schema! +# Since maintain_test_schema! may provide an unseeded database, but tests rely on the seeding. +if User.count.zero? + Rake::Task['db:seed'].execute +end + # make sure that all migrations of linked packages are executed Package::Migration.linked diff --git a/spec/requests/error_spec.rb b/spec/requests/error_spec.rb index 00023cf3d..9c0e00195 100644 --- a/spec/requests/error_spec.rb +++ b/spec/requests/error_spec.rb @@ -28,7 +28,7 @@ RSpec.describe 'Error handling', type: :request do let(:as) { :html } it { expect(response).to have_http_status(http_status) } - it { expect(response.content_type).to eq('text/html') } + it { expect(response.content_type).to start_with('text/html') } it { expect(response.body).to include('#{title}") } it { expect(response.body).to include("

#{headline}

") } diff --git a/spec/requests/report_spec.rb b/spec/requests/report_spec.rb index cd12d1019..78a2f74ee 100644 --- a/spec/requests/report_spec.rb +++ b/spec/requests/report_spec.rb @@ -79,7 +79,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do expect(response).to have_http_status(:ok) assert(@response['Content-Disposition']) - expect(@response['Content-Disposition']).to eq('attachment; filename="tickets--all--Created.xls"') + expect(@response['Content-Disposition']).to eq('attachment; filename="tickets--all--Created.xls"; filename*=UTF-8\'\'tickets--all--Created.xls') expect(@response['Content-Type']).to eq('application/vnd.ms-excel') end diff --git a/spec/requests/time_accounting_spec.rb b/spec/requests/time_accounting_spec.rb index ee42611c9..23aa301f9 100644 --- a/spec/requests/time_accounting_spec.rb +++ b/spec/requests/time_accounting_spec.rb @@ -37,7 +37,7 @@ RSpec.describe 'Time Accounting API endpoints', type: :request do expect(response).to have_http_status(:ok) expect(response['Content-Disposition']).to be_truthy - expect(response['Content-Disposition']).to eq("attachment; filename=\"by_ticket-#{year}-#{month}.xls\"") + expect(response['Content-Disposition']).to eq("attachment; filename=\"by_ticket-#{year}-#{month}.xls\"; filename*=UTF-8''by_ticket-#{year}-#{month}.xls") expect(response['Content-Type']).to eq('application/vnd.ms-excel') end end @@ -59,7 +59,7 @@ RSpec.describe 'Time Accounting API endpoints', type: :request do expect(response).to have_http_status(:ok) expect(response['Content-Disposition']).to be_truthy - expect(response['Content-Disposition']).to eq("attachment; filename=\"by_ticket-#{year}-#{month}.xls\"") + expect(response['Content-Disposition']).to eq("attachment; filename=\"by_ticket-#{year}-#{month}.xls\"; filename*=UTF-8''by_ticket-#{year}-#{month}.xls") expect(response['Content-Type']).to eq('application/vnd.ms-excel') end end diff --git a/spec/support/active_job.rb b/spec/support/active_job.rb index a93836695..4fda9be98 100644 --- a/spec/support/active_job.rb +++ b/spec/support/active_job.rb @@ -39,4 +39,10 @@ RSpec.configure do |config| ::ActiveJob::Base.queue_adapter = default_queue_adapter end end + + # Workaround needed for behavior change introduced in Rails >= 5.2 + # see: https://github.com/rails/rails/issues/37270 + config.before(:each) do + (ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter) + end end diff --git a/spec/system/examples/macros_examples.rb b/spec/system/examples/macros_examples.rb index a00368f50..3c9687037 100644 --- a/spec/system/examples/macros_examples.rb +++ b/spec/system/examples/macros_examples.rb @@ -12,8 +12,8 @@ RSpec.shared_examples 'macros' do |path:| # give user access to all groups including those created # by using FactoryBot outside of the example - group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result| - result[group_name] = 'full'.freeze + group_names_access_map = Group.all.pluck(:name).index_with do |_group_name| + 'full'.freeze end current_user do |user| diff --git a/spec/system/examples/text_modules_examples.rb b/spec/system/examples/text_modules_examples.rb index a1e3e6b63..d61e86597 100644 --- a/spec/system/examples/text_modules_examples.rb +++ b/spec/system/examples/text_modules_examples.rb @@ -34,8 +34,8 @@ RSpec.shared_examples 'text modules' do |path:| # give user access to all groups including those created # by using FactoryBot outside of the example - group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result| - result[group_name] = 'full'.freeze + group_names_access_map = Group.all.pluck(:name).index_with do |_group_name| + 'full'.freeze end current_user do |user| diff --git a/spec/system/ticket/view_spec.rb b/spec/system/ticket/view_spec.rb index c3c3b28dc..611245501 100644 --- a/spec/system/ticket/view_spec.rb +++ b/spec/system/ticket/view_spec.rb @@ -18,8 +18,8 @@ RSpec.describe 'Ticket views', type: :system do # give user access to all groups including those created # by using FactoryBot outside of the example - group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result| - result[group_name] = 'full'.freeze + group_names_access_map = Group.all.pluck(:name).index_with do |_group_name| + 'full'.freeze end current_user do |user| diff --git a/test/browser/admin_object_manager_test.rb b/test/browser/admin_object_manager_test.rb index 83e23e546..056c04d7e 100644 --- a/test/browser/admin_object_manager_test.rb +++ b/test/browser/admin_object_manager_test.rb @@ -680,7 +680,7 @@ class AdminObjectManagerTest < TestCase url: browser_url, ) - options = %w[äöü cat delete dog ß].map { |x| [x, "#{x.capitalize} Display"] }.to_h + options = %w[äöü cat delete dog ß].index_with { |x| "#{x.capitalize} Display" } options_no_dog = options.except('dog') options_no_dog_no_delete = options_no_dog.except('delete')