From f1aa0121b7fa26896731dcdb37c1bd5cd483c06c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 25 Aug 2019 08:24:49 +0200 Subject: [PATCH] fix rubocop offenses --- .gitignore | 2 +- .rubocop.yml | 1 + app/models/user.rb | 3 +- ...90517154500_add_extra_provider_contacts.rb | 24 ++++----- .../20190521152430_add_billing_contact.rb | 2 + .../20190522162430_remove_general_contact.rb | 2 + db/migrate/20190604093226_add_events_table.rb | 2 + ...0621202343_remove_general_contact_phone.rb | 2 + .../20190629072238_add_researchers_table.rb | 5 +- .../20190723114539_add_consortium_lead_id.rb | 2 + .../20190727035047_add_client_type_column.rb | 2 + .../20190727170040_add_client_fields.rb | 2 + ...5190522_rename_consortum_lead_id_column.rb | 2 + ...20190807002912_add_salesforce_id_column.rb | 2 + lib/tasks/activity.rake | 2 + lib/tasks/client.rake | 4 +- lib/tasks/doi.rake | 2 + lib/tasks/elasticsearch.rake | 3 +- lib/tasks/event.rake | 2 + lib/tasks/handle.rake | 54 ++++++++++--------- lib/tasks/memcached.rake | 2 + lib/tasks/prefix.rake | 2 + lib/tasks/provider.rake | 22 ++++---- lib/tasks/researcher.rake | 24 +++++---- 24 files changed, 105 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 774725973..91c1f7c5d 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,4 @@ doc/dependencies* !.env.travis docker-compose.override.yml .ruby-version -.vscode \ No newline at end of file +.vscode diff --git a/.rubocop.yml b/.rubocop.yml index a70dfcb82..1e3bae333 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,4 @@ +require: rubocop-performance inherit_from: .rubocop_todo.yml # from https://github.com/rails/rails/blob/master/.rubocop.yml diff --git a/app/models/user.rb b/app/models/user.rb index a0807c00f..56630bd8f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,7 +35,8 @@ def initialize(credentials, options={}) "uid" => uid, "name" => payload["name"], "email" => payload["email"], - "role_id" => researcher.role_id + "role_id" => researcher.role_id, + "beta_tester" => researcher.beta_tester } @jwt = encode_token(payload.merge(iat: Time.now.to_i, exp: Time.now.to_i + 3600 * 24 * 30)) diff --git a/db/migrate/20190517154500_add_extra_provider_contacts.rb b/db/migrate/20190517154500_add_extra_provider_contacts.rb index e6c1b1579..61a325777 100644 --- a/db/migrate/20190517154500_add_extra_provider_contacts.rb +++ b/db/migrate/20190517154500_add_extra_provider_contacts.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true class AddExtraProviderContacts < ActiveRecord::Migration[5.2] - def up - add_column :allocator, :general_contact, :json - add_column :allocator, :technical_contact, :json - add_column :allocator, :service_contact, :json - add_column :allocator, :voting_contact, :json - end + def up + add_column :allocator, :general_contact, :json + add_column :allocator, :technical_contact, :json + add_column :allocator, :service_contact, :json + add_column :allocator, :voting_contact, :json + end - def down - remove_column :allocator, :general_contact - remove_column :allocator, :technical_contact - remove_column :allocator, :service_contact - remove_column :allocator, :voting_contact - end + def down + remove_column :allocator, :general_contact + remove_column :allocator, :technical_contact + remove_column :allocator, :service_contact + remove_column :allocator, :voting_contact end +end diff --git a/db/migrate/20190521152430_add_billing_contact.rb b/db/migrate/20190521152430_add_billing_contact.rb index 768ca19a0..43b03a770 100644 --- a/db/migrate/20190521152430_add_billing_contact.rb +++ b/db/migrate/20190521152430_add_billing_contact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddBillingContact < ActiveRecord::Migration[5.2] def up add_column :allocator, :billing_contact, :json diff --git a/db/migrate/20190522162430_remove_general_contact.rb b/db/migrate/20190522162430_remove_general_contact.rb index ec6a14b11..c32435799 100644 --- a/db/migrate/20190522162430_remove_general_contact.rb +++ b/db/migrate/20190522162430_remove_general_contact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveGeneralContact < ActiveRecord::Migration[5.2] def up remove_column :allocator, :general_contact diff --git a/db/migrate/20190604093226_add_events_table.rb b/db/migrate/20190604093226_add_events_table.rb index 9fa3f6bbe..3f929806e 100644 --- a/db/migrate/20190604093226_add_events_table.rb +++ b/db/migrate/20190604093226_add_events_table.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddEventsTable < ActiveRecord::Migration[5.2] def change create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| diff --git a/db/migrate/20190621202343_remove_general_contact_phone.rb b/db/migrate/20190621202343_remove_general_contact_phone.rb index 150fea5ae..16a0978a4 100644 --- a/db/migrate/20190621202343_remove_general_contact_phone.rb +++ b/db/migrate/20190621202343_remove_general_contact_phone.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveGeneralContactPhone < ActiveRecord::Migration[5.2] def up remove_column :allocator, :contact_name diff --git a/db/migrate/20190629072238_add_researchers_table.rb b/db/migrate/20190629072238_add_researchers_table.rb index ff22d3ecf..a0f5a017f 100644 --- a/db/migrate/20190629072238_add_researchers_table.rb +++ b/db/migrate/20190629072238_add_researchers_table.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class AddResearchersTable < ActiveRecord::Migration[5.2] def up create_table "researchers", force: :cascade do |t| @@ -11,7 +12,7 @@ def up t.string "authentication_token", limit: 191 t.string "role_id", limit: 255, default: "user" t.boolean "auto_update", default: true - t.datetime "expires_at", default: '1970-01-01 00:00:00', null: false + t.datetime "expires_at", default: "1970-01-01 00:00:00", null: false t.datetime "created_at", precision: 3 t.datetime "updated_at", precision: 3 t.text "other_names", limit: 65535 @@ -28,7 +29,7 @@ def up t.boolean "is_public", default: true t.boolean "beta_tester", default: false end - + add_index "researchers", ["uid"], name: "index_researchers_on_uid", unique: true, using: :btree end diff --git a/db/migrate/20190723114539_add_consortium_lead_id.rb b/db/migrate/20190723114539_add_consortium_lead_id.rb index 7c3d8c85f..add859490 100644 --- a/db/migrate/20190723114539_add_consortium_lead_id.rb +++ b/db/migrate/20190723114539_add_consortium_lead_id.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddConsortiumLeadId < ActiveRecord::Migration[5.2] def change add_column :allocator, :consortium_lead_id, :string diff --git a/db/migrate/20190727035047_add_client_type_column.rb b/db/migrate/20190727035047_add_client_type_column.rb index 6769151fd..e9e4df782 100644 --- a/db/migrate/20190727035047_add_client_type_column.rb +++ b/db/migrate/20190727035047_add_client_type_column.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddClientTypeColumn < ActiveRecord::Migration[5.2] def change add_column :datacentre, :client_type, :string, limit: 191 diff --git a/db/migrate/20190727170040_add_client_fields.rb b/db/migrate/20190727170040_add_client_fields.rb index 0cec5bf22..5ef98ccb3 100644 --- a/db/migrate/20190727170040_add_client_fields.rb +++ b/db/migrate/20190727170040_add_client_fields.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddClientFields < ActiveRecord::Migration[5.2] def change remove_index :datacentre, [:re3data] diff --git a/db/migrate/20190805190522_rename_consortum_lead_id_column.rb b/db/migrate/20190805190522_rename_consortum_lead_id_column.rb index 946496435..d53f8cac1 100644 --- a/db/migrate/20190805190522_rename_consortum_lead_id_column.rb +++ b/db/migrate/20190805190522_rename_consortum_lead_id_column.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameConsortumLeadIdColumn < ActiveRecord::Migration[5.2] def change rename_column :allocator, :consortium_lead_id, :consortium_id diff --git a/db/migrate/20190807002912_add_salesforce_id_column.rb b/db/migrate/20190807002912_add_salesforce_id_column.rb index 7292a2003..6c79a455d 100644 --- a/db/migrate/20190807002912_add_salesforce_id_column.rb +++ b/db/migrate/20190807002912_add_salesforce_id_column.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddSalesforceIdColumn < ActiveRecord::Migration[5.2] def change add_column :datacentre, :salesforce_id, :string, limit: 191 diff --git a/lib/tasks/activity.rake b/lib/tasks/activity.rake index c02f9f4d9..610aaa6a7 100644 --- a/lib/tasks/activity.rake +++ b/lib/tasks/activity.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :activity do desc "Create index for activities" task :create_index => :environment do diff --git a/lib/tasks/client.rake b/lib/tasks/client.rake index c88e534f9..aea73c84a 100644 --- a/lib/tasks/client.rake +++ b/lib/tasks/client.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :client do desc "Create index for clients" task :create_index => :environment do @@ -184,4 +186,4 @@ namespace :client do puts "Client prefix for client #{target.symbol} and prefix #{prefix} created." end end -end \ No newline at end of file +end diff --git a/lib/tasks/doi.rake b/lib/tasks/doi.rake index 2f08e8f85..ea69240ff 100644 --- a/lib/tasks/doi.rake +++ b/lib/tasks/doi.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :doi do desc "Create index for dois" task :create_index => :environment do diff --git a/lib/tasks/elasticsearch.rake b/lib/tasks/elasticsearch.rake index e9f2c9f15..278cbe24a 100644 --- a/lib/tasks/elasticsearch.rake +++ b/lib/tasks/elasticsearch.rake @@ -1,2 +1,3 @@ -require 'elasticsearch/rails/tasks/import' +# frozen_string_literal: true +require 'elasticsearch/rails/tasks/import' diff --git a/lib/tasks/event.rake b/lib/tasks/event.rake index 7acd101ba..3f485156a 100644 --- a/lib/tasks/event.rake +++ b/lib/tasks/event.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :event do desc "Create index for events" task :create_index => :environment do diff --git a/lib/tasks/handle.rake b/lib/tasks/handle.rake index 4e5f6ab17..11ad087c0 100644 --- a/lib/tasks/handle.rake +++ b/lib/tasks/handle.rake @@ -1,46 +1,48 @@ +# frozen_string_literal: true + namespace :handle do - desc 'Get DOIs by prefix' - task :get_dois => :environment do - if ENV['PREFIX'].nil? - puts "ENV['PREFIX'] is required." + desc "Get DOIs by prefix" + task get_dois: :environment do + if ENV["PREFIX"].nil? + puts "ENV[\"PREFIX\"] is required." exit end - Doi.get_dois(prefix: ENV['PREFIX']) + Doi.get_dois(prefix: ENV["PREFIX"]) end - desc 'Get DOI' - task :get_doi => :environment do - if ENV['DOI'].nil? - puts "ENV['DOI'] is required." + desc "Get DOI" + task get_doi: :environment do + if ENV["DOI"].nil? + puts "ENV[\"DOI\"] is required." exit end - response = Doi.get_doi(doi: ENV['DOI']) - url = response.body.dig('data', 'values', 0, 'data', 'value') - puts "DOI #{ENV['DOI']} uses URL #{url}" if url.present? + response = Doi.get_doi(doi: ENV["DOI"]) + url = response.body.dig("data", "values", 0, "data", "value") + puts "DOI #{ENV["DOI"]} uses URL #{url}" if url.present? end - desc 'Delete DOI' - task :delete_doi => :environment do - if ENV['DOI'].nil? - puts "ENV['DOI'] is required." + desc "Delete DOI" + task delete_doi: :environment do + if ENV["DOI"].nil? + puts "ENV[\"DOI\"] is required." exit - elsif !ENV['DOI'].start_with?("10.5072") + elsif !ENV["DOI"].start_with?("10.5072") puts "Only DOIs with prefix 10.5072 can be deleted." exit end - response = Doi.delete_doi(doi: ENV['DOI']) - puts "Deleted DOI #{ENV['DOI']}." if response.body.dig('data', 'responseCode') == 1 + response = Doi.delete_doi(doi: ENV["DOI"]) + puts "Deleted DOI #{ENV["DOI"]}." if response.body.dig("data", "responseCode") == 1 end - desc 'Delete DOIs with test prefix' - task :delete_dois => :environment do - if ENV['PREFIX'].nil? - puts "ENV['PREFIX'] is required." + desc "Delete DOIs with test prefix" + task delete_dois: :environment do + if ENV["PREFIX"].nil? + puts "ENV[\"PREFIX\"] is required." exit - elsif ENV['PREFIX'] != "10.5072" + elsif ENV["PREFIX"] != "10.5072" puts "Only DOIs with prefix 10.5072 can be deleted." exit end @@ -50,7 +52,7 @@ namespace :handle do puts "Found #{dois.length} DOIs." dois.each do |doi| response = Doi.delete_doi(doi: doi) - puts "Deleted DOI #{doi}." if response.body.dig('data', 'responseCode') == 1 + puts "Deleted DOI #{doi}." if response.body.dig("data", "responseCode") == 1 end end -end \ No newline at end of file +end diff --git a/lib/tasks/memcached.rake b/lib/tasks/memcached.rake index f3673b71f..c9b80195e 100644 --- a/lib/tasks/memcached.rake +++ b/lib/tasks/memcached.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :memcached do desc 'Clears the Rails cache' task :flush => :environment do diff --git a/lib/tasks/prefix.rake b/lib/tasks/prefix.rake index 54608ceb4..2fd2b28a2 100644 --- a/lib/tasks/prefix.rake +++ b/lib/tasks/prefix.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :prefix do desc 'Delete prefix and associated DOIs' task :delete => :environment do diff --git a/lib/tasks/provider.rake b/lib/tasks/provider.rake index 88ca22ccd..cda8fd20a 100644 --- a/lib/tasks/provider.rake +++ b/lib/tasks/provider.rake @@ -1,51 +1,53 @@ +# frozen_string_literal: true + namespace :provider do desc "Create index for providers" - task :create_index => :environment do + task create_index: :environment do puts Provider.create_index end desc "Delete index for providers" - task :delete_index => :environment do + task delete_index: :environment do puts Provider.delete_index end desc "Upgrade index for providers" - task :upgrade_index => :environment do + task upgrade_index: :environment do puts Provider.upgrade_index end desc "Show index stats for providers" - task :index_stats => :environment do + task index_stats: :environment do puts Provider.index_stats end desc "Switch index for providers" - task :switch_index => :environment do + task switch_index: :environment do puts Provider.switch_index end desc "Return active index for providers" - task :active_index => :environment do + task active_index: :environment do puts Provider.active_index + " is the active index." end desc "Start using alias indexes for providers" - task :start_aliases => :environment do + task start_aliases: :environment do puts Provider.start_aliases end desc "Monitor reindexing for providers" - task :monitor_reindex => :environment do + task monitor_reindex: :environment do puts Provider.monitor_reindex end desc "Wrap up starting using alias indexes for providers" - task :finish_aliases => :environment do + task finish_aliases: :environment do puts Provider.finish_aliases end desc 'Import all providers' - task :import => :environment do + task import: :environment do Provider.import(index: Provider.inactive_index) end end diff --git a/lib/tasks/researcher.rake b/lib/tasks/researcher.rake index bc7aaba89..4fd2dd557 100644 --- a/lib/tasks/researcher.rake +++ b/lib/tasks/researcher.rake @@ -1,51 +1,53 @@ +# frozen_string_literal: true + namespace :researcher do desc "Create index for researchers" - task :create_index => :environment do + task create_index: :environment do puts Researcher.create_index end desc "Delete index for researchers" - task :delete_index => :environment do + task delete_index: :environment do puts Researcher.delete_index end desc "Upgrade index for researchers" - task :upgrade_index => :environment do + task upgrade_index: :environment do puts Researcher.upgrade_index end desc "Show index stats for researchers" - task :index_stats => :environment do + task index_stats: :environment do puts Researcher.index_stats end desc "Switch index for researchers" - task :switch_index => :environment do + task switch_index: :environment do puts Researcher.switch_index end desc "Return active index for researchers" - task :active_index => :environment do + task active_index: :environment do puts Researcher.active_index + " is the active index." end desc "Start using alias indexes for researchers" - task :start_aliases => :environment do + task start_aliases: :environment do puts Researcher.start_aliases end desc "Monitor reindexing for researchers" - task :monitor_reindex => :environment do + task monitor_reindex: :environment do puts Researcher.monitor_reindex end desc "Wrap up starting using alias indexes for researchers" - task :finish_aliases => :environment do + task finish_aliases: :environment do puts Researcher.finish_aliases end desc 'Import all researchers' - task :import => :environment do + task import: :environment do Researcher.import(index: Researcher.inactive_index) end -end \ No newline at end of file +end