mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
Inspecting 1483 files
........................................................................................................................C..................................................................................................................C...........CC.C..........................................C......C..........C.........................C......................CC..........C........................................................................................................................C.......................................................................................................C........................................................C...........................................................................................................................................C......................................C.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Offenses:
app/controllers/spree/admin/products_controller.rb:183:11: C: [Corrected] Rails/WhereNot: Use where.not(spree_variants: { import_date: nil }) instead of manually constructing negated SQL in where.
where('spree_variants.import_date IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/concerns/permalink_generator.rb:37:26: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
scope_with_deleted.where('id != ?', id)
^^^^^^^^^^^^^^^^^^^^
app/models/concerns/permalink_generator.rb:37:40: C: [Corrected] Style/HashSyntax: Omit the hash value.
scope_with_deleted.where.not(id: id)
^^
app/models/enterprise.rb:152:7: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: ready_enterprises }) instead of manually constructing negated SQL in where.
where("enterprises.id NOT IN (?)", ready_enterprises)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:158:31: C: [Corrected] Rails/WhereNot: Use where.not(sells: 'none') instead of manually constructing negated SQL in where.
scope :is_distributor, -> { where('sells != ?', 'none') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:479:17: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
dups = dups.where('id != ?', id) unless new_record?
^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:534:43: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: self }) instead of manually constructing negated SQL in where.
enterprises = owner.owned_enterprises.where('enterprises.id != ?', self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:583:7: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: id }) instead of manually constructing negated SQL in where.
where('enterprises.id != ?', id).
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_fee.rb:40:24: C: [Corrected] Rails/WhereNot: Use where.not(spree_calculators: { type: PER_ORDER_CALCULATORS }) instead of manually constructing negated SQL in where.
joins(:calculator).where('spree_calculators.type NOT IN (?)', PER_ORDER_CALCULATORS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_relationship.rb:78:19: C: [Corrected] Rails/WhereNot: Use where.not(name: perms) instead of manually constructing negated SQL in where.
permissions.where('name NOT IN (?)', perms).destroy_all
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/product_import/inventory_reset_strategy.rb:27:16: C: [Corrected] Rails/WhereNot: Use where.not(id: excluded_items_ids) instead of manually constructing negated SQL in where.
relation.where('id NOT IN (?)', excluded_items_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/proxy_order.rb:19:25: C: [Corrected] Rails/WhereNot: Use where.not(proxy_orders: { canceled_at: nil }) instead of manually constructing negated SQL in where.
scope :canceled, -> { where('proxy_orders.canceled_at IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/credit_card.rb:26:39: C: [Corrected] Rails/WhereNot: Use where.not(gateway_customer_profile_id: nil) instead of manually constructing negated SQL in where.
scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/product.rb:166:9: C: [Corrected] Rails/WhereNot: Use where.not(order_cycles: { id: nil }) instead of manually constructing negated SQL in where.
where('order_cycles.id IS NOT NULL')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/variant.rb:94:30: C: [Corrected] Rails/WhereNot: Use where.not(deleted_at: nil) instead of manually constructing negated SQL in where.
scope :deleted, lambda { where('deleted_at IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/variant.rb:165:43: C: [Corrected] Rails/WhereNot: Use where.not(spree_prices: { amount: nil }) instead of manually constructing negated SQL in where.
where('spree_prices.amount IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/zone.rb:141:19: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
Spree::Zone.where('id != ?', id).update_all(default_tax: false) if default_tax
^^^^^^^^^^^^^^^^^^^^
app/models/spree/zone.rb:141:33: C: [Corrected] Style/HashSyntax: Omit the hash value.
Spree::Zone.where.not(id: id).update_all(default_tax: false) if default_tax
^^
app/models/variant_override.rb:32:7: C: [Corrected] Rails/WhereNot: Use where.not(variant_overrides: { import_date: nil }) instead of manually constructing negated SQL in where.
where('variant_overrides.import_date IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/cap_quantity.rb:45:22: C: [Corrected] Rails/WhereNot: Use where.not(variant_id: available_variants_for.select(&:id)) instead of manually constructing negated SQL in where.
order.line_items.where('variant_id NOT IN (?)', available_variants_for.select(&:id))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb:32:18: C: [Corrected] Rails/WhereNot: Use where.not(spree_variants: { id: excluded_items_ids }) instead of manually constructing negated SQL in where.
relation.where('spree_variants.id NOT IN (?)', excluded_items_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb:78:18: C: [Corrected] Rails/WhereNot: Use where.not(order_cycle_id: order_cycle_ids) instead of manually constructing negated SQL in where.
orphaned.where('order_cycle_id NOT IN (?)', order_cycle_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:27:14: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: nil }) instead of manually constructing negated SQL in where.
.where("enterprises.id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:39:14: C: [Corrected] Rails/WhereNot: Use where.not(enterprise_id: nil) instead of manually constructing negated SQL in where.
.where("enterprise_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:40:14: C: [Corrected] Rails/WhereNot: Use where.not(user_id: nil) instead of manually constructing negated SQL in where.
.where("user_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/tasks/data/anonymize_data.rake:50:16: C: [Corrected] Rails/WhereNot: Use where.not(user_id: nil) instead of manually constructing negated SQL in where.
Customer.where("user_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1483 files inspected, 26 offenses detected, 26 offenses corrected
76 lines
2.8 KiB
Ruby
76 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'highline'
|
|
|
|
namespace :ofn do
|
|
namespace :data do
|
|
desc 'Anonymize data'
|
|
task anonymize: :environment do
|
|
guard_and_warn
|
|
|
|
anonymize_users_data
|
|
|
|
Spree::Address.update_all("
|
|
firstname = concat('Ms. Number', id), lastname = 'Jones', phone = '01234567890',
|
|
alternative_phone = '01234567890', address1 = 'Dummy address',
|
|
address2 = 'Dummy address continuation',
|
|
company = null, latitude = null, longitude = null")
|
|
|
|
anonymize_payments_data
|
|
anonymize_payments_accounts
|
|
|
|
Spree::TokenizedPermission.update_all("token = null")
|
|
|
|
# Delete all preferences that may contain sensitive information
|
|
Spree::Preference
|
|
.where("key like '%gateway%' OR key like '%billing_integration%' OR key like '%s3%'")
|
|
.delete_all
|
|
end
|
|
|
|
def guard_and_warn
|
|
if Rails.env.production?
|
|
Rails.logger.info("This task cannot be executed in production")
|
|
exit
|
|
end
|
|
|
|
message = "\n <%= color('This will permanently change DB contents', :yellow) %>,
|
|
are you sure you want to proceed? (y/N)"
|
|
exit unless HighLine.new.agree(message) { |q| q.default = "n" }
|
|
end
|
|
|
|
private
|
|
|
|
def anonymize_users_data
|
|
Spree::User.update_all("email = concat(id, '_ofn_user@example.com'),
|
|
login = concat(id, '_ofn_user@example.com'),
|
|
unconfirmed_email = concat(id, '_ofn_user@example.com')")
|
|
Customer.where("user_id IS NULL")
|
|
.update_all("email = concat(id, '_ofn_customer@example.com'),
|
|
name = concat('Customer Number ', id, ' (without connected User)')")
|
|
Customer.where.not(user_id: nil)
|
|
.update_all("email = concat(user_id, '_ofn_user@example.com'),
|
|
name = concat('Customer Number ', id, ' - User ', user_id)")
|
|
|
|
Spree::Order.update_all("email = concat(id, '_ofn_order@example.com')")
|
|
end
|
|
|
|
def anonymize_payments_data
|
|
Spree::PaymentMethod.update_all("name = concat('Dummy Payment Method', id),
|
|
description = name,
|
|
environment = '#{Rails.env}'")
|
|
Spree::Payment.update_all("response_code = null, avs_response = null,
|
|
cvv_response_code = null, identifier = null,
|
|
cvv_response_message = null")
|
|
Spree::CreditCard.update_all("
|
|
month = 12, year = 2020, start_month = 12, start_year = 2000,
|
|
cc_type = 'VISA', first_name = 'Dummy', last_name = 'Dummy', last_digits = '2543'")
|
|
end
|
|
|
|
def anonymize_payments_accounts
|
|
Spree::PaypalExpressCheckout.update_all("token = null")
|
|
StripeAccount.delete_all
|
|
ActiveRecord::Base.connection.execute("delete from spree_paypal_accounts")
|
|
end
|
|
end
|
|
end
|