From fc6d996e02958d06a4aec5e2b33b86adca17384e Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Thu, 30 Nov 2023 12:37:31 +0100 Subject: [PATCH 1/7] remove couple not needed user data requests, return less fields in some conditions --- app/resources/v1/base_resource.rb | 9 +++++++++ .../v1/observation_document_resource.rb | 3 +-- app/resources/v1/observation_report_resource.rb | 7 ++++++- app/resources/v1/observation_resource.rb | 6 ++++++ app/resources/v1/observer_resource.rb | 1 - .../v1/operator_document_annex_resource.rb | 1 - app/resources/v1/operator_resource.rb | 1 - app/resources/v1/user_resource.rb | 17 +++++++++++++++++ 8 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/resources/v1/base_resource.rb b/app/resources/v1/base_resource.rb index 376a5719f..a7c7060a2 100644 --- a/app/resources/v1/base_resource.rb +++ b/app/resources/v1/base_resource.rb @@ -1,5 +1,14 @@ module V1 class BaseResource < JSONAPI::Resource abstract + + def observations_tool_user? + context[:app] == "observations-tool" && context[:current_user].present? && + ["ngo", "ngo_manager", "admin"].include?(context[:current_user].user_permission.user_role) + end + + def admin_user? + context[:current_user].present? && context[:current_user].user_permission.user_role == "admin" + end end end diff --git a/app/resources/v1/observation_document_resource.rb b/app/resources/v1/observation_document_resource.rb index 0a728750d..67bbd5269 100644 --- a/app/resources/v1/observation_document_resource.rb +++ b/app/resources/v1/observation_document_resource.rb @@ -7,8 +7,7 @@ class ObservationDocumentResource < BaseResource attributes :name, :attachment, :created_at, :updated_at has_one :observation - has_one :user - filters :observation_id, :name, :user_id + filters :observation_id, :name end end diff --git a/app/resources/v1/observation_report_resource.rb b/app/resources/v1/observation_report_resource.rb index b67331c90..3fd4a55cf 100644 --- a/app/resources/v1/observation_report_resource.rb +++ b/app/resources/v1/observation_report_resource.rb @@ -7,7 +7,6 @@ class ObservationReportResource < BaseResource attributes :title, :publication_date, :created_at, :updated_at, :attachment has_many :observers - has_one :user has_many :observations after_create :add_observers @@ -19,5 +18,11 @@ class ObservationReportResource < BaseResource def add_observers @model.update_observers if @model.observations.any? end + + def fetchable_fields + return super if observations_tool_user? + + super - [:created_at, :updated_at, :user] + end end end diff --git a/app/resources/v1/observation_resource.rb b/app/resources/v1/observation_resource.rb index b1b9bee15..0f36e9aa4 100644 --- a/app/resources/v1/observation_resource.rb +++ b/app/resources/v1/observation_resource.rb @@ -70,6 +70,12 @@ class ObservationResource < BaseResource records.where(id: records.joins(:observers).where(observers: {id: value}).pluck(:id)) } + def fetchable_fields + return super if observations_tool_user? + + super - [:admin_comment, :monitor_comment, :created_at, :updated_at, :user, :modified_user] + end + def self.sortable_fields(context) super + [:"country.iso", :"severity.level", :"subcategory.name", :"operator.name", :"country.name", :"law.written_infraction", diff --git a/app/resources/v1/observer_resource.rb b/app/resources/v1/observer_resource.rb index 74b3ecb43..753d46332 100644 --- a/app/resources/v1/observer_resource.rb +++ b/app/resources/v1/observer_resource.rb @@ -10,7 +10,6 @@ class ObserverResource < BaseResource :data_email, :data_phone, :organization_type, :delete_logo, :public_info has_many :countries - has_many :users has_many :observations filters :countries, :is_active diff --git a/app/resources/v1/operator_document_annex_resource.rb b/app/resources/v1/operator_document_annex_resource.rb index 84316417c..ac4877a2a 100644 --- a/app/resources/v1/operator_document_annex_resource.rb +++ b/app/resources/v1/operator_document_annex_resource.rb @@ -10,7 +10,6 @@ class OperatorDocumentAnnexResource < BaseResource :uploaded_by, :created_at, :updated_at has_one :operator_document, foreign_key_on: :related - has_one :user filters :status diff --git a/app/resources/v1/operator_resource.rb b/app/resources/v1/operator_resource.rb index 9a4d0449f..9c5bd7ade 100644 --- a/app/resources/v1/operator_resource.rb +++ b/app/resources/v1/operator_resource.rb @@ -13,7 +13,6 @@ class OperatorResource < BaseResource has_one :country has_many :fmus - has_many :users has_many :observations has_many :sawmills diff --git a/app/resources/v1/user_resource.rb b/app/resources/v1/user_resource.rb index 7bf8c87e8..62b2bf34a 100644 --- a/app/resources/v1/user_resource.rb +++ b/app/resources/v1/user_resource.rb @@ -19,5 +19,22 @@ def self.fields end filters :is_active, :email, :name + + def fetchable_fields + return super if owner? || admin_user? + return [:id, :name, :email] if password_reset_action? + + [:id, :name] + end + + private + + def password_reset_action? + context[:action] == "update" && context[:controller] == "v1/passwords" + end + + def owner? + context[:current_user].present? && context[:current_user].id == @model.id + end end end From 60f8ebb32d223f153a734eed9e36fdd12f1e5447 Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Thu, 30 Nov 2023 13:15:43 +0100 Subject: [PATCH 2/7] remove comments model --- app/models/comment.rb | 53 -------------------- app/models/government.rb | 10 ---- app/models/observation.rb | 1 - app/models/user.rb | 3 +- app/resources/v1/comment_resource.rb | 9 ---- app/resources/v1/observation_resource.rb | 1 - app/resources/v1/user_resource.rb | 1 - config/locales/en.yml | 8 --- config/locales/fr.yml | 9 ---- db/migrate/20231130113839_remove_comments.rb | 14 ++++++ db/schema.rb | 14 +----- spec/factories/comments.rb | 24 --------- spec/models/comment_spec.rb | 43 ---------------- 13 files changed, 16 insertions(+), 174 deletions(-) delete mode 100644 app/models/comment.rb delete mode 100644 app/resources/v1/comment_resource.rb create mode 100644 db/migrate/20231130113839_remove_comments.rb delete mode 100644 spec/factories/comments.rb delete mode 100644 spec/models/comment_spec.rb diff --git a/app/models/comment.rb b/app/models/comment.rb deleted file mode 100644 index 7ea251761..000000000 --- a/app/models/comment.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: comments -# -# id :integer not null, primary key -# commentable_id :integer -# commentable_type :string -# body :text -# user_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# - -class Comment < ApplicationRecord - belongs_to :commentable, polymorphic: true - belongs_to :user, inverse_of: :comments - - validates :body, presence: true - - validate :validate_body_length - - scope :recent, -> { order("comments.id DESC") } - scope :sort_by_created_at, -> { order("comments.sort_by_created_at DESC") } - - class << self - def build(options) - commentable = options["commentable_type"].classify.constantize if options["commentable_type"].present? - user = options["user"] if options["user"].present? - body = options["body"] if options["body"].present? - if commentable.present? && user.present? && body.present? - commentable = commentable.find(options["commentable_id"].to_i) - - new(commentable: commentable, user_id: user.id, body: body) - end - end - - def body_max_length - 1000 - end - end - - private - - def validate_body_length - validator = ActiveModel::Validations::LengthValidator.new( - attributes: :body, - maximum: Comment.body_max_length - ) - validator.validate(self) - end -end diff --git a/app/models/government.rb b/app/models/government.rb index 22589d0a8..1f2315c9b 100644 --- a/app/models/government.rb +++ b/app/models/government.rb @@ -41,16 +41,6 @@ class Government < ApplicationRecord default_scope { includes(:translations) } - class << self - def fetch_all(options) - country_id = options["country"] if options.present? && options["country"].present? - - governments = includes(:country) - governments = governments.filter_by_country(country_id) if country_id.present? - governments - end - end - alias_method :to_s, :government_entity def cache_key diff --git a/app/models/observation.rb b/app/models/observation.rb index 43cf39d11..425b83a9a 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -109,7 +109,6 @@ class Observation < ApplicationRecord has_many :observation_operators, dependent: :destroy has_many :relevant_operators, through: :observation_operators, source: :operator - has_many :comments, as: :commentable, dependent: :destroy has_many :observation_documents, dependent: :destroy accepts_nested_attributes_for :observation_documents, allow_destroy: true diff --git a/app/models/user.rb b/app/models/user.rb index 35fa93df8..a1cd06484 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -46,7 +46,6 @@ class User < ApplicationRecord has_one :api_key, dependent: :destroy has_one :user_permission has_many :observations, inverse_of: :user - has_many :comments, inverse_of: :user, dependent: :destroy has_many :observation_documents, inverse_of: :user has_many :observation_reports, inverse_of: :user has_many :operator_document_annexes, inverse_of: :user @@ -81,7 +80,7 @@ class User < ApplicationRecord class << self def fetch_all(options) - includes(:user_permission, :comments, :country) + includes(:user_permission, :country) end end diff --git a/app/resources/v1/comment_resource.rb b/app/resources/v1/comment_resource.rb deleted file mode 100644 index 28492f80d..000000000 --- a/app/resources/v1/comment_resource.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module V1 - class CommentResource < BaseResource - caching - - attributes :body - end -end diff --git a/app/resources/v1/observation_resource.rb b/app/resources/v1/observation_resource.rb index 0f36e9aa4..2bde818f6 100644 --- a/app/resources/v1/observation_resource.rb +++ b/app/resources/v1/observation_resource.rb @@ -13,7 +13,6 @@ class ObservationResource < BaseResource :is_physical_place, :complete, :hidden, :admin_comment, :monitor_comment has_many :species - has_many :comments has_many :observation_documents has_many :observers has_many :relevant_operators, class_name: "Operator" diff --git a/app/resources/v1/user_resource.rb b/app/resources/v1/user_resource.rb index 62b2bf34a..0b0404193 100644 --- a/app/resources/v1/user_resource.rb +++ b/app/resources/v1/user_resource.rb @@ -9,7 +9,6 @@ class UserResource < BaseResource has_one :country has_one :user_permission, foreign_key_on: :related - has_many :comments has_many :managed_observers, class_name: "Observer" has_one :observer has_one :operator diff --git a/config/locales/en.yml b/config/locales/en.yml index 9234b2e37..66b600801 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -587,12 +587,6 @@ en: locale: Locale #g name: Name #g - comment: - body: Body #g - commentable: :activerecord.models.commentable #g - commentable_type: Commentable type #g - user: :activerecord.models.user #g - contributor: category: Category #g logo: Logo #g @@ -824,7 +818,6 @@ en: observation: actions_taken: Actions taken #g admin_comment: Admin comment #g - comments: Comments #g country: :activerecord.models.country #g deleted_at: Deleted at #g evidence_on_report: Evidence on report #g @@ -1420,7 +1413,6 @@ en: user: api_key: :activerecord.models.api_key #g - comments: Comments #g country: :activerecord.models.country #g current_sign_in_at: Last sign-in on current_sign_in_ip: Current sign in ip #g diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2a7d2a902..249d3c669 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -463,9 +463,6 @@ fr: category: one: 'Catégorie' other: 'Catégories' - comment: - one: 'Commentaire' - other: 'Commentaires' contributor: one: 'Contributeur' other: 'Contributeurs' @@ -563,10 +560,6 @@ fr: category_type: 'Type de catégorie' name: 'Nom' - comment: - commentable_type: 'Type commentable' - body: 'Corps' - contributor: website: 'site Internet' logo: 'Logo' @@ -730,7 +723,6 @@ fr: observation: actions_taken: Les mesures prises #g admin_comment: Commentaire de l'administrateur #g - comments: commentaires #g country: :activerecord.models.country #g deleted_at: Supprimé le #g evidence_on_report: Preuve sur le rapport #g @@ -1332,7 +1324,6 @@ fr: user: api_key: :activerecord.models.api_key #g - comments: commentaires #g country: :activerecord.models.country #g current_sign_in_at: Dernière connexion à current_sign_in_ip: IP de connexion actuelle #g diff --git a/db/migrate/20231130113839_remove_comments.rb b/db/migrate/20231130113839_remove_comments.rb new file mode 100644 index 000000000..0c6c20c23 --- /dev/null +++ b/db/migrate/20231130113839_remove_comments.rb @@ -0,0 +1,14 @@ +class RemoveComments < ActiveRecord::Migration[7.0] + def change + drop_table :comments do |t| + t.integer :commentable_id + t.string :commentable_type + t.text :body + t.references :user, foreign_key: {on_delete: :nullify}, index: true + + t.timestamps + + t.index [:commentable_id, :commentable_type], name: "index_comments_on_commentable_id_and_commentable_type" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a86233708..6870db4ec 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_17_115001) do +ActiveRecord::Schema[7.0].define(version: 2023_11_30_113839) do # These are extensions that must be enabled in order to support this database enable_extension "address_standardizer" enable_extension "address_standardizer_data_us" @@ -93,17 +93,6 @@ t.index ["name", "category_id"], name: "index_category_translations_on_name_and_category_id" end - create_table "comments", id: :serial, force: :cascade do |t| - t.integer "commentable_id" - t.string "commentable_type" - t.text "body" - t.integer "user_id", null: false - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.index ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type" - t.index ["user_id"], name: "index_comments_on_user_id" - end - create_table "contributor_translations", id: :serial, force: :cascade do |t| t.integer "contributor_id", null: false t.string "locale", null: false @@ -1105,7 +1094,6 @@ add_foreign_key "annex_documents", "operator_document_annexes", on_delete: :cascade add_foreign_key "api_keys", "users" - add_foreign_key "comments", "users" add_foreign_key "country_links", "countries", on_delete: :cascade add_foreign_key "country_vpas", "countries", on_delete: :cascade add_foreign_key "gov_documents", "countries", on_delete: :cascade diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb deleted file mode 100644 index bb1157404..000000000 --- a/spec/factories/comments.rb +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: comments -# -# id :integer not null, primary key -# commentable_id :integer -# commentable_type :string -# body :text -# user_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# - -FactoryBot.define do - factory :comment do - sequence(:body) { |n| "CommentBody#{n}" } - - after(:build) do |random_comment| - random_comment.user ||= FactoryBot.create :user - random_comment.commentable ||= - FactoryBot.create :observation - end - end -end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb deleted file mode 100644 index 763a9bfdb..000000000 --- a/spec/models/comment_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# == Schema Information -# -# Table name: comments -# -# id :integer not null, primary key -# commentable_id :integer -# commentable_type :string -# body :text -# user_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# - -require "rails_helper" - -RSpec.describe Comment, type: :model do - subject(:comment) { FactoryBot.build(:comment) } - - it "is valid with valid attributes" do - expect(comment).to be_valid - end - - describe "Class methods" do - describe "#build" do - context "when commentable, user and body are present" do - it "build(a new Comment with the specified data" do - user = create(:user) - observation = create(:observation) - comment = Comment.build({ - "commentable_type" => "Observation", - "commentable_id" => observation.id, - "user" => user, - "body" => "body" - }) - - expect(comment.commentable).to eql observation - expect(comment.user_id).to eql user.id - expect(comment.body).to eql "body" - end - end - end - end -end From 80972086662d38f5c5759dcae341efcd83221b6f Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Thu, 30 Nov 2023 13:19:10 +0100 Subject: [PATCH 3/7] remove not used fetch_all methods --- app/models/observer.rb | 4 ---- app/models/operator.rb | 8 -------- app/models/species.rb | 6 ------ app/models/user.rb | 6 ------ spec/models/government_spec.rb | 24 ------------------------ spec/models/observer_spec.rb | 6 ------ spec/models/operator_spec.rb | 16 ---------------- spec/models/species_spec.rb | 8 -------- spec/models/user_spec.rb | 8 -------- 9 files changed, 86 deletions(-) diff --git a/app/models/observer.rb b/app/models/observer.rb index 45397b503..4229cedc2 100644 --- a/app/models/observer.rb +++ b/app/models/observer.rb @@ -72,10 +72,6 @@ class Observer < ApplicationRecord default_scope { includes(:translations) } class << self - def fetch_all(options) - includes(:countries, :users) - end - def observer_select by_name_asc.map { |c| ["#{c.name} (#{c.observer_type})", c.id] } end diff --git a/app/models/operator.rb b/app/models/operator.rb index db178311b..203539a8d 100644 --- a/app/models/operator.rb +++ b/app/models/operator.rb @@ -109,14 +109,6 @@ class Operator < ApplicationRecord } class << self - def fetch_all(options) - country_ids = options["country_ids"] if options.present? && options["country_ids"].present? - - operators = includes(:country, :users) - operators = operators.filter_by_country_ids(country_ids) if country_ids.present? - operators - end - def operator_select by_name_asc.map { |c| [c.name, c.id] } end diff --git a/app/models/species.rb b/app/models/species.rb index e0c92ba46..869e5dec7 100644 --- a/app/models/species.rb +++ b/app/models/species.rb @@ -34,12 +34,6 @@ class Species < ApplicationRecord default_scope { includes(:translations) } - class << self - def fetch_all(options) - includes(:countries) - end - end - def cache_key super + "-" + Globalize.locale.to_s end diff --git a/app/models/user.rb b/app/models/user.rb index a1cd06484..71aea5b33 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -78,12 +78,6 @@ class User < ApplicationRecord scope :inactive, -> { where(is_active: false) } scope :with_user_role, ->(role) { joins(:user_permission).where(user_permission: {user_role: role}) } - class << self - def fetch_all(options) - includes(:user_permission, :country) - end - end - def is_government(country_id) self&.user_permission&.user_role == "government" && self.country_id == country_id end diff --git a/spec/models/government_spec.rb b/spec/models/government_spec.rb index 7028953e3..11d6c14a8 100644 --- a/spec/models/government_spec.rb +++ b/spec/models/government_spec.rb @@ -29,28 +29,4 @@ end end end - - describe "Class methods" do - describe "#fetch_all" do - before do - @country = create(:country) - create(:government, country: @country) - create(:government) - end - - context "when country_ids is not specified" do - it "fetch all operators" do - expect(Government.fetch_all(nil).count).to eq(Government.all.size) - end - end - - context "when country is specified" do - it "fetch operators filtered by country" do - expect(Government.fetch_all({"country" => [@country.id]}).to_a).to eql( - Government.where(country_id: @country.id).includes(:country).to_a - ) - end - end - end - end end diff --git a/spec/models/observer_spec.rb b/spec/models/observer_spec.rb index 4705f1278..2334b0204 100644 --- a/spec/models/observer_spec.rb +++ b/spec/models/observer_spec.rb @@ -46,12 +46,6 @@ create_list(:observer, 3) end - describe "#fetch_all" do - it "fetch all operators" do - expect(Observer.fetch_all(nil)).to eq(Observer.includes(:countries, :users)) - end - end - describe "#observer_select" do it "return formatted information of observer sorted by name asc" do expect(Observer.observer_select).to eql( diff --git a/spec/models/operator_spec.rb b/spec/models/operator_spec.rb index 2f40d7566..8d5a40528 100644 --- a/spec/models/operator_spec.rb +++ b/spec/models/operator_spec.rb @@ -287,22 +287,6 @@ end describe "Class methods" do - describe "#fetch_all" do - context "when country_ids is not specified" do - it "fetch all operators" do - expect(Operator.fetch_all(nil).count).to eq(Operator.all.size) - end - end - - context "when country is specified" do - it "fetch operators filtered by country" do - expect(Operator.fetch_all({"country_ids" => [@country.id]}).to_a).to eql( - Operator.where(country_id: @country.id).to_a - ) - end - end - end - describe "#operator_select" do it "select operators ordered asd by name" do result = Operator.by_name_asc.map { |c| [c.name, c.id] } diff --git a/spec/models/species_spec.rb b/spec/models/species_spec.rb index 736a01d32..22c6bf71f 100644 --- a/spec/models/species_spec.rb +++ b/spec/models/species_spec.rb @@ -39,12 +39,4 @@ end end end - - describe "Class methods" do - describe "#fetch_all" do - it "returns all species" do - expect(Species.fetch_all(nil).count).to eq(Species.all.size) - end - end - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1684e9e67..a2ad2f176 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -314,12 +314,4 @@ end end end - - describe "Class methods" do - describe "#fetch_all" do - it "return all users" do - expect(User.fetch_all(nil).count).to eq(User.all.size) - end - end - end end From 5650f1c19d04e42a5eb4b324fddbb4df3356689d Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Thu, 30 Nov 2023 22:41:41 +0100 Subject: [PATCH 4/7] update gems --- Gemfile.lock | 333 ++++++++++++++++++++++++++------------------------- 1 file changed, 171 insertions(+), 162 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4e0dff773..67231c7cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,47 +54,47 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.7.2) - actionpack (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.7.2) - actionview (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.7.2) - actionpack (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.7.2) - activesupport (= 7.0.7.2) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -117,61 +117,61 @@ GEM sassc sassc-rails xdan-datetimepicker-rails (~> 2.5.1) - activeadmin_quill_editor (1.0.0) - activeadmin (~> 2.0) - activejob (7.0.7.2) - activesupport (= 7.0.7.2) + activeadmin_quill_editor (1.1.0) + activeadmin (>= 2.0, < 4) + activejob (7.0.8) + activesupport (= 7.0.8) globalid (>= 0.3.6) - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activerecord-import (1.4.1) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activerecord-import (1.5.1) activerecord (>= 4.2) - activerecord-postgis-adapter (8.0.2) + activerecord-postgis-adapter (8.0.3) activerecord (~> 7.0.0) rgeo-activerecord (~> 7.0.0) - activestorage (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activesupport (= 7.0.7.2) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.7.2) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) acts_as_list (1.1.0) activerecord (>= 4.2) - addressable (2.8.4) + addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) - airbrussh (1.4.1) + airbrussh (1.5.0) sshkit (>= 1.6.1, != 1.7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) - arbre (1.6.0) - activesupport (>= 3.0.0, < 7.1) - ruby2_keywords (>= 0.0.2, < 1.0) + arbre (1.7.0) + activesupport (>= 3.0.0) + ruby2_keywords (>= 0.0.2) ast (2.4.2) attr_extras (7.1.0) - bcrypt (3.1.19) + bcrypt (3.1.20) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.17.0) msgpack (~> 1.2) - brakeman (6.0.0) + brakeman (6.0.1) builder (3.2.4) - bullet (7.0.7) + bullet (7.1.4) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundler-audit (0.9.1) bundler (>= 1.2.0, < 3) thor (~> 1.0) cancancan (3.5.0) - capistrano (3.17.3) + capistrano (3.18.0) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -183,7 +183,7 @@ GEM dotenv (~> 2.0) capistrano-passenger (0.2.1) capistrano (~> 3.0) - capistrano-rails (1.6.2) + capistrano-rails (1.6.3) capistrano (~> 3.1) capistrano-bundler (>= 1.1, < 3) capistrano-rvm (0.1.2) @@ -198,41 +198,40 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - carrierwave (2.2.4) - activemodel (>= 5.0.0) - activesupport (>= 5.0.0) + carrierwave (3.0.5) + activemodel (>= 6.0.0) + activesupport (>= 6.0.0) addressable (~> 2.6) image_processing (~> 1.1) marcel (~> 1.0.0) - mini_mime (>= 0.1.3) ssrf_filter (~> 1.0) carrierwave-base64 (2.10.0) carrierwave (>= 2.2.1) marcel (~> 1.0.0) mime-types (~> 3.0) - chartkick (5.0.2) + chartkick (5.0.4) choice (0.2.0) concurrent-ruby (1.2.2) connection_pool (2.4.1) - countries (5.5.0) + countries (5.7.0) unaccent (~> 0.3) crack (0.4.5) rexml crass (1.0.6) - cuprite (0.14.3) + cuprite (0.15) capybara (~> 3.0) - ferrum (~> 0.13.0) + ferrum (~> 0.14.0) database_cleaner (2.0.2) database_cleaner-active_record (>= 2, < 3) database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - date (3.3.3) + date (3.3.4) debug (1.8.0) irb (>= 1.5.0) reline (>= 0.3.1) - devise (4.9.2) + devise (4.9.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -249,32 +248,32 @@ GEM launchy (~> 2.1) mail (~> 2.7) erubi (1.12.0) - execjs (2.8.1) - factory_bot (6.2.1) + execjs (2.9.1) + factory_bot (6.4.2) activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) + factory_bot_rails (6.4.2) + factory_bot (~> 6.4) railties (>= 5.0.0) - faker (3.2.0) + faker (3.2.2) i18n (>= 1.8.11, < 2) - ferrum (0.13) + ferrum (0.14) addressable (~> 2.5) concurrent-ruby (~> 1.1) webrick (~> 1.7) websocket-driver (>= 0.6, < 0.8) - ffi (1.15.5) + ffi (1.16.3) formtastic (4.0.0) actionpack (>= 5.2.0) formtastic_i18n (0.7.0) - globalid (1.2.0) + globalid (1.2.1) activesupport (>= 6.1) globalize (6.2.1) activemodel (>= 4.2, < 7.1) activerecord (>= 4.2, < 7.1) request_store (~> 1.0) - groupdate (6.2.1) - activesupport (>= 5.2) - has_scope (0.8.1) + groupdate (6.4.0) + activesupport (>= 6.1) + has_scope (0.8.2) actionpack (>= 5.2) activesupport (>= 5.2) hashdiff (1.0.1) @@ -287,20 +286,21 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inherited_resources (1.13.1) - actionpack (>= 5.2, < 7.1) - has_scope (~> 0.6) - railties (>= 5.2, < 7.1) - responders (>= 2, < 4) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) interactor (3.1.2) io-console (0.6.0) - irb (1.7.0) - reline (>= 0.3.0) + irb (1.9.1) + rdoc + reline (>= 0.3.8) jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.3) + json (2.7.0) jsonapi-resources (0.9.12) activerecord (>= 4.1) concurrent-ruby @@ -328,8 +328,8 @@ GEM letter_opener (~> 1.7) railties (>= 5.2) rexml - lint_roller (1.0.0) - loofah (2.21.3) + lint_roller (1.1.0) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -340,37 +340,37 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) - mime-types (3.4.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2023.1003) mini_magick (4.12.0) mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.19.0) + mini_portile2 (2.8.5) + minitest (5.20.0) mjml-rails (4.9.0) - msgpack (1.7.1) + msgpack (1.7.2) mustache (1.1.1) - net-imap (0.3.7) + net-imap (0.4.7) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol - net-ssh (7.1.0) - nio4r (2.5.9) - nokogiri (1.15.4) + net-ssh (7.2.0) + nio4r (2.7.0) + nokogiri (1.15.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.15.5-x86_64-linux) racc (~> 1.4) - oj (3.15.0) + oj (3.16.1) oj_mimic_json (1.0.1) - optimist (3.0.1) + optimist (3.1.0) orm_adapter (0.5.0) paper_trail (12.3.0) activerecord (>= 5.2) @@ -378,16 +378,18 @@ GEM parallel (1.23.0) paranoia (2.5.3) activerecord (>= 5.1, < 7.1) - parser (3.2.2.3) + parser (3.2.2.4) ast (~> 2.4.1) racc patience_diff (1.2.0) optimist (~> 3.0) - pg (1.5.3) - public_suffix (5.0.1) - puma (6.3.1) + pg (1.5.4) + psych (5.1.1.1) + stringio + public_suffix (5.0.4) + puma (6.4.0) nio4r (~> 2.0) - racc (1.7.1) + racc (1.7.3) rack (2.2.8) rack-cors (2.0.1) rack (>= 2.0.0) @@ -395,20 +397,20 @@ GEM rack (>= 1.2.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.7.2) - actioncable (= 7.0.7.2) - actionmailbox (= 7.0.7.2) - actionmailer (= 7.0.7.2) - actionpack (= 7.0.7.2) - actiontext (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activemodel (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) bundler (>= 1.15.0) - railties (= 7.0.7.2) + railties (= 7.0.8) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -421,19 +423,21 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.0.6) + rake (13.1.0) ransack (3.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n + rdoc (6.6.0) + psych (>= 4.0.0) redis (5.0.8) redis-client (>= 0.17.0) redis-actionpack (5.3.0) @@ -443,7 +447,7 @@ GEM redis-activesupport (5.3.0) activesupport (>= 3, < 8) redis-store (>= 1.3, < 2) - redis-client (0.17.1) + redis-client (0.18.0) connection_pool redis-rack (2.1.4) rack (>= 2.0.8, < 3) @@ -452,19 +456,19 @@ GEM redis-actionpack (>= 5.0, < 6) redis-activesupport (>= 5.0, < 6) redis-store (>= 1.2, < 2) - redis-store (1.9.2) + redis-store (1.10.0) redis (>= 4, < 6) - regexp_parser (2.8.1) - reline (0.3.5) + regexp_parser (2.8.2) + reline (0.4.1) io-console (~> 0.5) request_store (1.5.1) rack (>= 1.4) require_all (3.0.0) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.5) - rgeo (3.0.0) + rexml (3.2.6) + rgeo (3.0.1) rgeo-activerecord (7.0.1) activerecord (>= 5.0) rgeo (>= 1.0.0) @@ -482,10 +486,10 @@ GEM rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.5) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-rails (6.0.3) + rspec-rails (6.1.0) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) @@ -494,34 +498,37 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - rswag-api (2.9.0) - railties (>= 3.1, < 7.1) - rswag-ui (2.9.0) - actionpack (>= 3.1, < 7.1) - railties (>= 3.1, < 7.1) - rubocop (1.52.1) + rswag-api (2.13.0) + activesupport (>= 3.1, < 7.2) + railties (>= 3.1, < 7.2) + rswag-ui (2.13.0) + actionpack (>= 3.1, < 7.2) + railties (>= 3.1, < 7.2) + rubocop (1.57.2) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-performance (1.18.0) + rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.20.2) + rubocop-rails (2.22.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-graphviz (1.2.5) rexml ruby-progressbar (1.13.0) - ruby-vips (2.1.4) + ruby-vips (2.2.0) ffi (~> 1.12) ruby2_keywords (0.0.5) ruby_http_client (3.5.5) @@ -542,16 +549,16 @@ GEM sendgrid-actionmailer (3.2.0) mail (~> 2.7) sendgrid-ruby (~> 6.4) - sendgrid-ruby (6.6.2) + sendgrid-ruby (6.7.0) ruby_http_client (~> 3.4) - sentry-rails (5.9.0) + sentry-rails (5.14.0) railties (>= 5.0) - sentry-ruby (~> 5.9.0) - sentry-ruby (5.9.0) + sentry-ruby (~> 5.14.0) + sentry-ruby (5.14.0) concurrent-ruby (~> 1.0, >= 1.0.2) shoulda-matchers (4.0.1) activesupport (>= 4.2.0) - sidekiq (7.1.6) + sidekiq (7.2.0) concurrent-ruby (< 2) connection_pool (>= 2.3.0) rack (>= 2.2.4) @@ -562,35 +569,37 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sshkit (1.21.4) + sshkit (1.21.6) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - ssrf_filter (1.1.1) - standard (1.29.0) + ssrf_filter (1.1.2) + standard (1.32.0) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.52.0) + rubocop (~> 1.57.2) standard-custom (~> 1.0.0) - standard-performance (~> 1.1.0) - standard-custom (1.0.1) - lint_roller (~> 1.0) - standard-performance (1.1.0) + standard-performance (~> 1.2) + standard-custom (1.0.2) lint_roller (~> 1.0) - rubocop-performance (~> 1.18.0) + rubocop (~> 1.50) + standard-performance (1.2.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.19.1) + stringio (3.1.0) super_diff (0.10.0) attr_extras (>= 6.2.4) diff-lcs patience_diff - thor (1.2.2) - tilt (2.2.0) - timeout (0.4.0) + thor (1.3.0) + tilt (2.3.0) + timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) tzinfo-data (1.2023.3) @@ -598,19 +607,19 @@ GEM uglifier (4.2.0) execjs (>= 0.3.0, < 3) unaccent (0.4.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) uniform_notifier (1.16.0) valid_url (0.0.4) addressable rails warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.18.1) + webmock (3.19.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -623,7 +632,7 @@ GEM rails (>= 3.2.16) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.11) + zeitwerk (2.6.12) PLATFORMS ruby From 5fd8ba05b575c11142beef4a9f9ecf10cdaeaca8 Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Fri, 1 Dec 2023 09:29:04 +0100 Subject: [PATCH 5/7] fix lint errors --- app/admin/observation_report.rb | 2 +- app/admin/observation_reports_dashboard.rb | 2 +- app/admin/required_gov_document.rb | 2 -- app/controllers/api_controller.rb | 4 ++-- app/models/operator.rb | 4 ++-- app/models/user.rb | 4 ++-- app/resources/v1/operator_document_history_resource.rb | 2 +- config/initializers/enum_attributes_validation.rb | 4 ++-- lib/file_data_import/base_importer.rb | 8 ++++---- lib/tasks/check_data.rake | 2 +- lib/tasks/data_import_v2.rake | 2 +- lib/tasks/fix.rake | 2 +- lib/tasks/fmus.rake | 2 +- lib/tasks/nullify_operator_documents_user.rake | 2 +- lib/tasks/operator_document_history.rake | 4 ++-- spec/mailers/mailer_previews_spec.rb | 2 +- spec/models/operator_document_annex_spec.rb | 2 +- spec/support/system/cuprite_helpers.rb | 4 ++-- 18 files changed, 26 insertions(+), 28 deletions(-) diff --git a/app/admin/observation_report.rb b/app/admin/observation_report.rb index 304a234c4..e4cea0c71 100644 --- a/app/admin/observation_report.rb +++ b/app/admin/observation_report.rb @@ -112,7 +112,7 @@ def apply_filtering(chain) end column :observers do |o| links = [] - o.observers.joins(:translations).each do |observer| + o.observers.joins(:translations).find_each do |observer| links << link_to(observer.name, admin_monitor_path(observer.id)) end links.reduce(:+) diff --git a/app/admin/observation_reports_dashboard.rb b/app/admin/observation_reports_dashboard.rb index 2aa683368..2d87c7995 100644 --- a/app/admin/observation_reports_dashboard.rb +++ b/app/admin/observation_reports_dashboard.rb @@ -18,7 +18,7 @@ as: :select, multiple: true, label: -> { I18n.t("activerecord.models.observer") }, - collection: -> { Observer.where(id: ObservationReportStatistic.all.select(:observer_id).distinct).order(:name) } + collection: -> { Observer.where(id: ObservationReportStatistic.select(:observer_id).distinct).order(:name) } filter :date dependent_filters do diff --git a/app/admin/required_gov_document.rb b/app/admin/required_gov_document.rb index 1fddda8ef..8dc4e95bb 100644 --- a/app/admin/required_gov_document.rb +++ b/app/admin/required_gov_document.rb @@ -14,7 +14,6 @@ filter :required_gov_document_group, collection: -> { RequiredGovDocumentGroup - .all .left_joins(:parent) .order(Arel.sql("coalesce(parents_required_gov_document_groups.position, required_gov_document_groups.position)")) } @@ -60,7 +59,6 @@ def scoped_collection f.inputs "Required Gov Document Details" do editing = !object.new_record? f.input :required_gov_document_group, collection: RequiredGovDocumentGroup - .all .left_joins(:parent) .order(Arel.sql("coalesce(parents_required_gov_document_groups.position, required_gov_document_groups.position)")) f.input :country, input_html: {disabled: editing} diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 294ff25bf..a62b8e58f 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -98,11 +98,11 @@ def api_auth end def api_key_present? - !!request.env.fetch("HTTP_OTP_API_KEY", "").scan(/Bearer/).flatten.first + !!request.env.fetch("HTTP_OTP_API_KEY", "").scan("Bearer").flatten.first end def auth_present? - !!request.env.fetch("HTTP_AUTHORIZATION", "").scan(/Bearer/).flatten.first + !!request.env.fetch("HTTP_AUTHORIZATION", "").scan("Bearer").flatten.first end def bad_auth_key diff --git a/app/models/operator.rb b/app/models/operator.rb index 203539a8d..821c2d040 100644 --- a/app/models/operator.rb +++ b/app/models/operator.rb @@ -148,8 +148,8 @@ def recalculate_scores def clean_document_cache # TODO: try different technique for jsonapi cache invalidation, this is undocumented way for cleaning cache of jsonapi resources - Rails.cache.delete_matched(/operator_documents\/(#{operator_document_ids.join('|')})\//) - Rails.cache.delete_matched(/operator_document_histories\/(#{operator_document_history_ids.join('|')})\//) + Rails.cache.delete_matched(/operator_documents\/(#{operator_document_ids.join("|")})\//) + Rails.cache.delete_matched(/operator_document_histories\/(#{operator_document_history_ids.join("|")})\//) end def refresh_ranking diff --git a/app/models/user.rb b/app/models/user.rb index 71aea5b33..232b6a03f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -203,7 +203,7 @@ def notify_user end # Devise ActiveJob integration - def send_devise_notification(notification, *args) - devise_mailer.send(notification, self, *args).deliver_later + def send_devise_notification(notification, *) + devise_mailer.send(notification, self, *).deliver_later end end diff --git a/app/resources/v1/operator_document_history_resource.rb b/app/resources/v1/operator_document_history_resource.rb index 69909ff43..99f232cd2 100644 --- a/app/resources/v1/operator_document_history_resource.rb +++ b/app/resources/v1/operator_document_history_resource.rb @@ -43,7 +43,7 @@ def self.records(options = {}) OperatorDocumentHistory.from_operator_at_date(operator, date).non_signature rescue - return OperatorDocumentHistory.where("true = false") unless operator && date + OperatorDocumentHistory.where("true = false") unless operator && date end end end diff --git a/config/initializers/enum_attributes_validation.rb b/config/initializers/enum_attributes_validation.rb index 6b9fb69d1..226c3a34d 100644 --- a/config/initializers/enum_attributes_validation.rb +++ b/config/initializers/enum_attributes_validation.rb @@ -44,8 +44,8 @@ def validate_enum_attributes(*attributes, **opts) end end - def validate_enum_attribute(*attributes) - validate_enum_attributes(*attributes) + def validate_enum_attribute(*) + validate_enum_attributes(*) end end end diff --git a/lib/file_data_import/base_importer.rb b/lib/file_data_import/base_importer.rb index 688b7699a..63fdb4be4 100644 --- a/lib/file_data_import/base_importer.rb +++ b/lib/file_data_import/base_importer.rb @@ -48,16 +48,16 @@ def build(importer_type, file) raise InvalidImporterError, "Undefined importer #{importer_name}." end - def record(class_name, **options) - record_builder.record(class_name, **options) + def record(class_name, **) + record_builder.record(class_name, **) end def record_builder @record_builder ||= RecordBuilder.new end - def belongs_to(class_name, **options) - record_builder.belongs_to(class_name, **options) + def belongs_to(class_name, **) + record_builder.belongs_to(class_name, **) end end diff --git a/lib/tasks/check_data.rake b/lib/tasks/check_data.rake index d90a214d9..38893ddd6 100644 --- a/lib/tasks/check_data.rake +++ b/lib/tasks/check_data.rake @@ -35,7 +35,7 @@ namespace :check do task docs_forest_type_mismatch: :environment do mismatch_count = 0 - OperatorDocumentFmu.all.includes(:operator, :required_operator_document).find_each do |od| + OperatorDocumentFmu.includes(:operator, :required_operator_document).find_each do |od| next if od.fmu.forest_type == "fmu" fmu = od.fmu diff --git a/lib/tasks/data_import_v2.rake b/lib/tasks/data_import_v2.rake index ce3bf5c71..8c897baac 100644 --- a/lib/tasks/data_import_v2.rake +++ b/lib/tasks/data_import_v2.rake @@ -115,7 +115,7 @@ namespace :import do data_row = row.to_h operator = Operator.where(name: data_row["attributai"]).first - Fmu.where("geojson @> '{\"properties\": {\"nom_conces\": \"#{data_row["nom_conces"]}\"}}'").each do |fmu| + Fmu.where("geojson @> '{\"properties\": {\"nom_conces\": \"#{data_row["nom_conces"]}\"}}'").find_each do |fmu| start_date = Time.zone.at(data_row["date_attr"].to_f / 1000) if data_row["date_attr"].present? if operator.present? && fmu.present? diff --git a/lib/tasks/fix.rake b/lib/tasks/fix.rake index b1d9163a6..c03e165ee 100644 --- a/lib/tasks/fix.rake +++ b/lib/tasks/fix.rake @@ -352,7 +352,7 @@ namespace :fix do end end - puts "TOTAL COUNT #{DocumentFile.all.count}" + puts "TOTAL COUNT #{DocumentFile.count}" puts "NO OPERATORS #{count_no_operator}" puts "NO RELATION #{count_no_relation}" puts "WRONG NAME #{count_wrong_name}" diff --git a/lib/tasks/fmus.rake b/lib/tasks/fmus.rake index de46016f3..3f23774c2 100644 --- a/lib/tasks/fmus.rake +++ b/lib/tasks/fmus.rake @@ -4,7 +4,7 @@ namespace :fmus do with_current_but_not_sync = [] without_current_and_not_sync = [] # Fmu.unscoped.all.each do |fmu| - Fmu.all.each do |fmu| + Fmu.find_each do |fmu| # has current in fmu_operator if fmu.fmu_operator&.operator_id unless fmu.fmu_operator&.operator_id == fmu.properties["operator_id"] diff --git a/lib/tasks/nullify_operator_documents_user.rake b/lib/tasks/nullify_operator_documents_user.rake index b81c066cb..55827f427 100644 --- a/lib/tasks/nullify_operator_documents_user.rake +++ b/lib/tasks/nullify_operator_documents_user.rake @@ -5,7 +5,7 @@ namespace :operator_documents do # puts od_wit_nil_user.count # puts 'Going to nullify #{od_wit_nil_user.count} operator documents user_id because user does not exists' - OperatorDocument.with_deleted.all.each do |od| + OperatorDocument.with_deleted.find_each do |od| od.update_columns(user_id: nil) if od.user.nil? end diff --git a/lib/tasks/operator_document_history.rake b/lib/tasks/operator_document_history.rake index 7e55f920f..5440d60d3 100644 --- a/lib/tasks/operator_document_history.rake +++ b/lib/tasks/operator_document_history.rake @@ -2,7 +2,7 @@ namespace :operator_documents_histories do desc "Checks if current ODHs status match with current OD status" task check_sync: :environment do unsync_docs = {} - Operator.all.each do |opt| + Operator.find_each do |opt| docs = [] odhs = OperatorDocumentHistory.from_operator_at_date(opt.id, Time.zone.today) odhs.each do |odh| @@ -32,7 +32,7 @@ namespace :operator_documents_histories do desc "Creates new ODHs for those unsync" task resync: :environment do - Operator.all.each do |opt| + Operator.find_each do |opt| odhs = OperatorDocumentHistory.from_operator_at_date(opt.id, Time.zone.today) odhs.each do |odh| od = odh.operator_document diff --git a/spec/mailers/mailer_previews_spec.rb b/spec/mailers/mailer_previews_spec.rb index 466ab04b1..b84873669 100644 --- a/spec/mailers/mailer_previews_spec.rb +++ b/spec/mailers/mailer_previews_spec.rb @@ -29,7 +29,7 @@ ) end - ActionMailer::Preview.all.each do |preview| + ActionMailer::Preview.all.each do |preview| # rubocop:disable Rails/FindEach next if preview.emails.empty? describe preview.preview_name do diff --git a/spec/models/operator_document_annex_spec.rb b/spec/models/operator_document_annex_spec.rb index a547d09a4..bb6788bad 100644 --- a/spec/models/operator_document_annex_spec.rb +++ b/spec/models/operator_document_annex_spec.rb @@ -46,7 +46,7 @@ it "set all operator_document_annex statuses to doc_expired" do OperatorDocumentAnnex.expire_document_annexes - OperatorDocumentAnnex.where("expire_date IS NOT NULL and expire_date < '#{Time.zone.today}'::date and status = 3").each do |operator_document_annex| + OperatorDocumentAnnex.where("expire_date IS NOT NULL and expire_date < '#{Time.zone.today}'::date and status = 3").find_each do |operator_document_annex| expect(operator_document_annex.status).to eql "doc_expired" end end diff --git a/spec/support/system/cuprite_helpers.rb b/spec/support/system/cuprite_helpers.rb index ac2cac58c..f64223eb2 100644 --- a/spec/support/system/cuprite_helpers.rb +++ b/spec/support/system/cuprite_helpers.rb @@ -7,7 +7,7 @@ def pause end # Drop #debug anywhere in a test to open a Chrome inspector and pause the execution - def debug(*args) - page.driver.debug(*args) + def debug(*) + page.driver.debug(*) end end From 84fc6b91c848b4f3d5609352072391c79ac7b193 Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Fri, 1 Dec 2023 10:31:59 +0100 Subject: [PATCH 6/7] fix private files urls --- app/uploaders/application_uploader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/uploaders/application_uploader.rb b/app/uploaders/application_uploader.rb index 9d745856d..b9430c3e4 100644 --- a/app/uploaders/application_uploader.rb +++ b/app/uploaders/application_uploader.rb @@ -17,7 +17,7 @@ def cache_dir end def url(*args) - return "/private#{super}" if private_upload? + return super.gsub("/uploads/", "/private/uploads/") if private_upload? super end From f1ad53fa69e44a7f82f28bd3cc1984c050baf133 Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Fri, 1 Dec 2023 13:15:25 +0100 Subject: [PATCH 7/7] fix issue with removing even private attachment after destroy, not real destroy --- app/models/gov_document.rb | 2 ++ app/models/observation_document.rb | 2 ++ app/models/observation_report.rb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/models/gov_document.rb b/app/models/gov_document.rb index e324785b9..437786936 100644 --- a/app/models/gov_document.rb +++ b/app/models/gov_document.rb @@ -45,8 +45,10 @@ class GovDocument < ApplicationRecord after_update :move_previous_attachment_to_private_directory, if: :saved_change_to_attachment? + skip_callback :commit, :after, :remove_attachment! after_destroy :move_attachment_to_private_directory after_restore :move_attachment_to_public_directory + after_real_destroy :remove_attachment! scope :with_archived, -> { unscope(where: :deleted_at) } scope :to_expire, ->(date) { where("expire_date < ?", date).where(status: EXPIRABLE_STATUSES) } diff --git a/app/models/observation_document.rb b/app/models/observation_document.rb index 663c49ebf..fdfaa5972 100644 --- a/app/models/observation_document.rb +++ b/app/models/observation_document.rb @@ -25,6 +25,8 @@ class ObservationDocument < ApplicationRecord belongs_to :user, inverse_of: :observation_documents, touch: true, optional: true belongs_to :observation, inverse_of: :observation_documents, touch: true + skip_callback :commit, :after, :remove_attachment! after_destroy :move_attachment_to_private_directory after_restore :move_attachment_to_public_directory + after_real_destroy :remove_attachment! end diff --git a/app/models/observation_report.rb b/app/models/observation_report.rb index 254ef5246..91e5fc766 100644 --- a/app/models/observation_report.rb +++ b/app/models/observation_report.rb @@ -28,8 +28,10 @@ class ObservationReport < ApplicationRecord has_many :observers, through: :observation_report_observers has_many :observations, dependent: :destroy + skip_callback :commit, :after, :remove_attachment! after_destroy :move_attachment_to_private_directory after_restore :move_attachment_to_public_directory + after_real_destroy :remove_attachment! scope :bigger_date, ->(date) { where("observation_reports.created_at <= ?", date + 1.day) }