From f97a1d921175a20222ec4e09d425cb3fd3f5b6b1 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 10 Dec 2020 10:13:57 +0100 Subject: [PATCH] Maintenance: Updated rubocop(-* gems) to latest version (1.6.1). --- Gemfile.lock | 10 +++++----- app/models/concerns/has_translations.rb | 4 ++-- app/models/object_manager/attribute.rb | 2 +- app/models/scheduler.rb | 2 +- app/models/ticket/screen_options.rb | 2 +- app/models/user.rb | 2 +- ...22_issue_1977_remove_invalid_user_foreign_keys.rb | 6 +++--- .../20190531180304_initialize_knowledge_base.rb | 4 ++++ ...10075534_maintenance_missing_kb_unique_indexes.rb | 12 ++++++++++++ 9 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20201210075534_maintenance_missing_kb_unique_indexes.rb diff --git a/Gemfile.lock b/Gemfile.lock index 9e1d0863e..3c0cc7e5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -452,13 +452,13 @@ GEM rspec-support (~> 3.9.0) rspec-support (3.9.3) rszr (0.5.2) - rubocop (1.4.2) + rubocop (1.6.1) parallel (~> 1.10) parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.1.1) + rubocop-ast (>= 1.2.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) rubocop-ast (1.3.0) @@ -466,10 +466,10 @@ GEM rubocop-performance (1.9.1) rubocop (>= 0.90.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.8.1) + rubocop-rails (2.9.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.87.0) + rubocop (>= 0.90.0, < 2.0) rubocop-rspec (2.0.1) rubocop (~> 1.0) rubocop-ast (>= 1.1.0) diff --git a/app/models/concerns/has_translations.rb b/app/models/concerns/has_translations.rb index c61f9a17a..6877ef36b 100644 --- a/app/models/concerns/has_translations.rb +++ b/app/models/concerns/has_translations.rb @@ -17,9 +17,9 @@ module HasTranslations output = eager_load(:translations).joins(translations: { kb_locale: :knowledge_base }) if system_locale_or_id.present? - output.where('knowledge_base_locales.system_locale_id = ?', system_locale_or_id) + output.where('knowledge_base_locales.system_locale_id' => system_locale_or_id) else - output.where('knowledge_base_locales.system_locale_id = ?', -1) + output.where('knowledge_base_locales.system_locale_id' => -1) end } end diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 88ea4fac5..969531957 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -467,7 +467,7 @@ returns =end def self.discard_changes - ObjectManager::Attribute.where('to_create = ?', true).each(&:destroy) + ObjectManager::Attribute.where(to_create: true).each(&:destroy) ObjectManager::Attribute.where('to_delete = ? OR to_config = ?', true, true).each do |attribute| attribute.to_migrate = false attribute.to_delete = false diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index ba14ddda2..3beb557be 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -37,7 +37,7 @@ class Scheduler < ApplicationModel end # read/load jobs and check if each has already been started - jobs = Scheduler.where('active = ?', true).order(prio: :asc) + jobs = Scheduler.where(active: true).order(prio: :asc) jobs.each do |job| # ignore job is still running diff --git a/app/models/ticket/screen_options.rb b/app/models/ticket/screen_options.rb index 6d5f8c393..4ad1c8763 100644 --- a/app/models/ticket/screen_options.rb +++ b/app/models/ticket/screen_options.rb @@ -111,7 +111,7 @@ returns agents = {} agent_role_ids = Role.with_permissions('ticket.agent').pluck(:id) - agent_user_ids = User.joins(:roles).where(users: { active: true }).where('roles_users.role_id IN (?)', agent_role_ids).pluck(:id) + agent_user_ids = User.joins(:roles).where(users: { active: true }).where('roles_users.role_id' => agent_role_ids).pluck(:id) groups.each do |group| filter[:group_id].push group.id assets = group.assets(assets) diff --git a/app/models/user.rb b/app/models/user.rb index 86125887f..3abd6338b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -680,7 +680,7 @@ 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 IN (?)', roles_ids).order('users.updated_at DESC') + return User.where(active: true).joins(:users_roles).where('roles_users.role_id' => roles_ids).order('users.updated_at DESC') end User.where(active: true) diff --git a/db/migrate/20180426134922_issue_1977_remove_invalid_user_foreign_keys.rb b/db/migrate/20180426134922_issue_1977_remove_invalid_user_foreign_keys.rb index ff0994f67..a9ed00609 100644 --- a/db/migrate/20180426134922_issue_1977_remove_invalid_user_foreign_keys.rb +++ b/db/migrate/20180426134922_issue_1977_remove_invalid_user_foreign_keys.rb @@ -6,15 +6,15 @@ class Issue1977RemoveInvalidUserForeignKeys < ActiveRecord::Migration[5.1] # cleanup OnlineNotification.joins('LEFT OUTER JOIN users ON online_notifications.user_id = users.id') - .where('users.id IS NULL') + .where('users.id' => nil) .destroy_all RecentView.joins('LEFT OUTER JOIN users ON recent_views.created_by_id = users.id') - .where('users.id IS NULL') + .where('users.id' => nil) .destroy_all Avatar.joins('LEFT OUTER JOIN users ON avatars.o_id = users.id') - .where('users.id IS NULL') + .where('users.id' => nil) .where(object_lookup_id: ObjectLookup.by_name('User')) .destroy_all diff --git a/db/migrate/20190531180304_initialize_knowledge_base.rb b/db/migrate/20190531180304_initialize_knowledge_base.rb index 96170ca6d..947210835 100644 --- a/db/migrate/20190531180304_initialize_knowledge_base.rb +++ b/db/migrate/20190531180304_initialize_knowledge_base.rb @@ -26,6 +26,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0] t.timestamps null: false # rubocop:disable Zammad/ExistsDateTimePrecision end + add_index :knowledge_base_locales, %i[system_locale_id knowledge_base_id], name: 'index_kb_locale_on_kb_system_locale_kb', unique: true create_table :knowledge_base_translations do |t| t.string :title, limit: 250, null: false @@ -36,6 +37,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0] t.timestamps null: false # rubocop:disable Zammad/ExistsDateTimePrecision end + add_index :knowledge_base_translations, %i[kb_locale_id knowledge_base_id], name: 'index_kb_t_on_kb_locale_kb', unique: true create_table :knowledge_base_categories do |t| t.references :knowledge_base, null: false, foreign_key: { to_table: :knowledge_bases } @@ -55,6 +57,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0] t.timestamps null: false # rubocop:disable Zammad/ExistsDateTimePrecision end + add_index :knowledge_base_category_translations, %i[kb_locale_id category_id], name: 'index_kb_c_t_on_kb_locale_category', unique: true create_table :knowledge_base_answers do |t| t.references :category, null: false, foreign_key: { to_table: :knowledge_base_categories } @@ -89,6 +92,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0] t.timestamps null: false # rubocop:disable Zammad/ExistsDateTimePrecision end + add_index :knowledge_base_answer_translations, %i[kb_locale_id answer_id], name: 'index_kb_a_t_on_kb_locale_answer', unique: true create_table :knowledge_base_menu_items do |t| t.references :kb_locale, null: false, foreign_key: { to_table: :knowledge_base_locales, on_delete: :cascade } diff --git a/db/migrate/20201210075534_maintenance_missing_kb_unique_indexes.rb b/db/migrate/20201210075534_maintenance_missing_kb_unique_indexes.rb new file mode 100644 index 000000000..c91aac12e --- /dev/null +++ b/db/migrate/20201210075534_maintenance_missing_kb_unique_indexes.rb @@ -0,0 +1,12 @@ +class MaintenanceMissingKbUniqueIndexes < ActiveRecord::Migration[5.2] + def change + + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + add_index :knowledge_base_locales, %i[system_locale_id knowledge_base_id], name: 'index_kb_locale_on_kb_system_locale_kb', unique: true + add_index :knowledge_base_translations, %i[kb_locale_id knowledge_base_id], name: 'index_kb_t_on_kb_locale_kb', unique: true + add_index :knowledge_base_category_translations, %i[kb_locale_id category_id], name: 'index_kb_c_t_on_kb_locale_category', unique: true + add_index :knowledge_base_answer_translations, %i[kb_locale_id answer_id], name: 'index_kb_a_t_on_kb_locale_answer', unique: true + end +end