mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Inspecting 1488 files
......................C....C.C..........................C.........C.........................C............................................C..............................................................................................................C.C........................................CC..............................C...........C...........................................................................................................................................................................................................C........................................................................................................C.......................................................C.............C...........................................................................................C..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C...C....................................................................................................................C.............
Offenses:
app/controllers/admin/enterprises_controller.rb:50:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless params[:stimulus]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:50:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless params[:stimulus]) instead of wrapping the code inside a conditional expression.
if params[:stimulus]
^^
app/controllers/admin/enterprises_controller.rb:51:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@enterprise.is_primary_producer = params[:is_primary_producer]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:52:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@enterprise.sells = params[:enterprise_sells]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:53:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu")) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:55:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:56:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:266:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless user_id.positive? && @enterprise.user_ids.include?(user_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:266:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless user_id.positive? && @enterprise.user_ids.include?(user_id)) instead of wrapping the code inside a conditional expression.
if user_id.positive? && @enterprise.user_ids.include?(user_id)
^^
app/controllers/admin/enterprises_controller.rb:267:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@enterprise.update_contact(user_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:268:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:270:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:272:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:272:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless attrs[:calculator_type].present? && attrs[:calculator_attributes].present?) instead of wrapping the code inside a conditional expression.
if attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
^^
app/controllers/admin/enterprises_controller.rb:273:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
rule.update(calculator_type: attrs[:calculator_type])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:274:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
attrs[:calculator_attributes].merge!( id: rule.calculator.id )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:275:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:278:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:279:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if spree_current_user.admin?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:279:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if spree_current_user.admin?) instead of wrapping the code inside a conditional expression.
unless spree_current_user.admin?
^^^^^^
app/controllers/admin/enterprises_controller.rb:280:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
params[:sets_enterprise_set][:collection_attributes].each do |_i, enterprise_params| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:285:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:289:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:289:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if spree_current_user.admin? || spree_current_user == @enterprise.owner
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:289:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if spree_current_user.admin? || spree_current_user == @enterprise.owner) instead of wrapping the code inside a conditional expression.
unless spree_current_user.admin? || spree_current_user == @enterprise.owner
^^^^^^
app/controllers/admin/enterprises_controller.rb:290:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
enterprise_params.delete :sells
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:291:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:296:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:299:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if spree_current_user.admin?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:299:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if spree_current_user.admin?) instead of wrapping the code inside a conditional expression.
unless spree_current_user.admin?
^^^^^^
app/controllers/admin/enterprises_controller.rb:300:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
has_hub = spree_current_user.owned_enterprises.is_hub.any?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:301:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
new_enterprise_is_producer = Enterprise.new(enterprise_params).is_primary_producer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:302:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
enterprise_params[:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:303:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:307:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:307:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?) instead of wrapping the code inside a conditional expression.
unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
^^^^^^
app/controllers/admin/enterprises_controller.rb:308:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
enterprise_params.delete :owner_id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:309:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:309:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:313:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if spree_current_user.admin?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:313:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if spree_current_user.admin?) instead of wrapping the code inside a conditional expression.
unless spree_current_user.admin?
^^^^^^
app/controllers/admin/enterprises_controller.rb:314:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
bulk_params[:collection_attributes].each do |_i, enterprise_params| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:316:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:317:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:321:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:321:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?) instead of wrapping the code inside a conditional expression.
unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
^^^^^^
app/controllers/admin/enterprises_controller.rb:322:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
enterprise_params.delete :user_ids
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/enterprises_controller.rb:323:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/enterprises_controller.rb:325:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/enterprises_controller.rb:332:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/order_cycles_controller.rb:185:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless json_request?
^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:185:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless json_request?) instead of wrapping the code inside a conditional expression.
if json_request?
^^
app/controllers/admin/order_cycles_controller.rb:188:9: C: [Corrected] Layout/CommentIndentation: Incorrect indentation detected (column 8 instead of 6).
# to limit returned ocs to recent or undated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:188:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
orders_close_at_gt = raw_params[:q]&.delete(:orders_close_at_gt) || 31.days.ago
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:189:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
raw_params[:q] = { ...
^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:194:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@collection = collection
^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:195:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/order_cycles_controller.rb:196:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/order_cycles_controller.rb:248:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:248:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)) instead of wrapping the code inside a conditional expression.
unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
^^^^^^
app/controllers/admin/order_cycles_controller.rb:249:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
order_cycle_params.delete_if do |k, _v| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/order_cycles_controller.rb:252:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/order_cycles_controller.rb:254:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/product_import_controller.rb:59:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if params[:file] || (params[:filepath] && File.exist?(params[:filepath]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:59:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if params[:file] || (params[:filepath] && File.exist?(params[:filepath]))) instead of wrapping the code inside a conditional expression.
unless params[:file] || (params[:filepath] && File.exist?(params[:filepath]))
^^^^^^
app/controllers/admin/product_import_controller.rb:60:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to '/admin/product_import', notice: I18n.t(:product_import_file_not_found_notice)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:61:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/product_import_controller.rb:62:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/admin/product_import_controller.rb:93:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if importer.item_count
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:93:7: C: [Corrected] Style/GuardClause: Use a guard clause (return if importer.item_count) instead of wrapping the code inside a conditional expression.
unless importer.item_count
^^^^^^
app/controllers/admin/product_import_controller.rb:94:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to '/admin/product_import', ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:96:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
true
^^^^
app/controllers/admin/product_import_controller.rb:97:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/admin/product_import_controller.rb:99:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/api/v0/shipments_controller.rb:48:11: C: Style/GuardClause: Use a guard clause (unless @shipment.can_ready?; render(json: { error: I18n.t(:cannot_ready, scope: "spree.api.shipment") },
status: :unprocessable_entity) && return; end) instead of wrapping the code inside a conditional expression.
if @shipment.can_ready?
^^
app/controllers/application_controller.rb:118:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if (@distributor = current_distributor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:118:5: C: [Corrected] Style/GuardClause: Use a guard clause (return if (@distributor = current_distributor)) instead of wrapping the code inside a conditional expression.
unless (@distributor = current_distributor)
^^^^^^
app/controllers/application_controller.rb:119:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to main_app.root_path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:120:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
false
^^^^^
app/controllers/application_controller.rb:121:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/application_controller.rb:122:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/application_controller.rb:125:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if current_order_cycle
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:125:5: C: [Corrected] Style/GuardClause: Use a guard clause (return if current_order_cycle) instead of wrapping the code inside a conditional expression.
unless current_order_cycle
^^^^^^
app/controllers/application_controller.rb:126:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to main_app.shop_path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:127:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/application_controller.rb:129:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/application_controller.rb:131:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless current_distributor_closed?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:131:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless current_distributor_closed?) instead of wrapping the code inside a conditional expression.
if current_distributor_closed?
^^
app/controllers/application_controller.rb:132:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
current_order.empty!
^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:133:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
current_order.set_distribution! nil, nil
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:134:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
flash[:info] = I18n.t('order_cycles_closed_for_hub')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:135:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to main_app.root_url
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/application_controller.rb:136:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/application_controller.rb:139:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/home_controller.rb:7:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless ContentConfig.home_show_stats
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/home_controller.rb:7:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless ContentConfig.home_show_stats) instead of wrapping the code inside a conditional expression.
if ContentConfig.home_show_stats
^^
app/controllers/home_controller.rb:8:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@num_distributors = cached_count('distributors', Enterprise.is_distributor.activated.visible)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/home_controller.rb:9:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@num_producers = cached_count('producers', Enterprise.is_primary_producer.activated.visible)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/home_controller.rb:10:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@num_orders = cached_count('orders', Spree::Order.complete)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/home_controller.rb:11:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@num_users = cached_count( ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/home_controller.rb:14:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/home_controller.rb:15:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/spree/orders_controller.rb:136:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless params[:order] && params[:order][:line_items_attributes]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/orders_controller.rb:136:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless params[:order] && params[:order][:line_items_attributes]) instead of wrapping the code inside a conditional expression.
if params[:order] && params[:order][:line_items_attributes]
^^
app/controllers/spree/orders_controller.rb:137:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
params[:order][:line_items_attributes] = ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/orders_controller.rb:139:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/spree/orders_controller.rb:140:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/controllers/spree/orders_controller.rb:183:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless items.empty?
^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/orders_controller.rb:183:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless items.empty?) instead of wrapping the code inside a conditional expression.
if items.empty?
^^
app/controllers/spree/orders_controller.rb:184:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
flash[:error] = I18n.t(:orders_cannot_remove_the_final_item)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/orders_controller.rb:185:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
redirect_to main_app.order_path(order_to_update)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/orders_controller.rb:186:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/spree/orders_controller.rb:188:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/enterprise.rb:518:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if owner.can_own_more_enterprises?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:518:5: C: [Corrected] Style/GuardClause: Use a guard clause (return if owner.can_own_more_enterprises?) instead of wrapping the code inside a conditional expression.
unless owner.can_own_more_enterprises?
^^^^^^
app/models/enterprise.rb:519:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
errors.add(:owner, I18n.t(:enterprise_owner_error, email: owner.email, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:521:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/enterprise.rb:522:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/enterprise.rb:546:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless is_hub
^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:546:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless is_hub) instead of wrapping the code inside a conditional expression.
if is_hub
^^
app/models/enterprise.rb:547:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
enterprises.is_primary_producer.each do |enterprise| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:553:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/enterprise.rb:555:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/enterprise.rb:557:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if preferred_shopfront_taxon_order =~ /\A((\d+,)*\d+)?\z/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:557:5: C: [Corrected] Style/GuardClause: Use a guard clause (return if preferred_shopfront_taxon_order =~ /\A((\d+,)*\d+)?\z/) instead of wrapping the code inside a conditional expression.
unless preferred_shopfront_taxon_order =~ /\A((\d+,)*\d+)?\z/
^^^^^^
app/models/enterprise.rb:558:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
errors.add(:shopfront_category_ordering, "must contain a list of taxons.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:559:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/enterprise.rb:562:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/enterprise.rb:563:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if preferred_shopfront_producer_order =~ /\A((\d+,)*\d+)?\z/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:563:5: C: [Corrected] Style/GuardClause: Use a guard clause (return if preferred_shopfront_producer_order =~ /\A((\d+,)*\d+)?\z/) instead of wrapping the code inside a conditional expression.
unless preferred_shopfront_producer_order =~ /\A((\d+,)*\d+)?\z/
^^^^^^
app/models/enterprise.rb:564:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
errors.add(:shopfront_category_ordering, "must contain a list of producers.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:565:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/enterprise.rb:569:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/enterprise_group.rb:80:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless permalink.blank? || permalink_changed?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_group.rb:80:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless permalink.blank? || permalink_changed?) instead of wrapping the code inside a conditional expression.
if permalink.blank? || permalink_changed?
^^
app/models/enterprise_group.rb:81:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
requested = permalink.presence || permalink_was.presence || name.presence || 'group'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_group.rb:82:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
self.permalink = create_unique_permalink(requested.parameterize)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_group.rb:83:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/enterprise_group.rb:84:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/producer_property.rb:16:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless name.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/producer_property.rb:16:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless name.present?) instead of wrapping the code inside a conditional expression.
if name.present?
^^
app/models/producer_property.rb:16:12: C: [Correctable] Rails/Blank: Use if name.blank? instead of unless name.present?.
return unless name.present?
^^^^^^^^^^^^^^^^^^^^
app/models/producer_property.rb:17:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
self.property = Spree::Property.find_by(name: name) || ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/producer_property.rb:19:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/producer_property.rb:20:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/product_import/entry_processor.rb:42:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless total_saved_count.zero?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/product_import/entry_processor.rb:42:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless total_saved_count.zero?) instead of wrapping the code inside a conditional expression.
if total_saved_count.zero?
^^
app/models/product_import/entry_processor.rb:43:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@importer.errors.add(:importer, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/product_import/entry_processor.rb:45:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/product_import/entry_processor.rb:46:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/spree/order.rb:506:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless !completed? && shipments.any?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/order.rb:506:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless !completed? && shipments.any?) instead of wrapping the code inside a conditional expression.
if !completed? && shipments.any?
^^
app/models/spree/order.rb:507:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
shipments.destroy_all
^^^^^^^^^^^^^^^^^^^^^
app/models/spree/order.rb:508:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
restart_checkout_flow
^^^^^^^^^^^^^^^^^^^^^
app/models/spree/order.rb:509:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/spree/order.rb:510:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/models/spree/preferences/preferable_class_methods.rb:67:9: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless method_defined? preference_description_getter_method(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/preferable_class_methods.rb:67:9: C: [Corrected] Style/GuardClause: Use a guard clause (return unless method_defined? preference_description_getter_method(name)) instead of wrapping the code inside a conditional expression.
if method_defined? preference_description_getter_method(name)
^^
app/models/spree/preferences/preferable_class_methods.rb:68:11: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
remove_method preference_description_getter_method(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/preferable_class_methods.rb:69:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/models/spree/preferences/preferable_class_methods.rb:70:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
app/services/order_syncer.rb:90:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless !pickup_to_delivery || order.shipment.blank?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/order_syncer.rb:90:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless !pickup_to_delivery || order.shipment.blank?) instead of wrapping the code inside a conditional expression.
if !pickup_to_delivery || order.shipment.blank?
^^
app/services/order_syncer.rb:91:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
order.updater.shipping_address_from_distributor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/order_syncer.rb:92:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/services/order_syncer.rb:93:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
engines/order_management/app/services/order_management/order/updater.rb:166:9: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless payment.completed? || order.completed?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
engines/order_management/app/services/order_management/order/updater.rb:166:9: C: [Corrected] Style/GuardClause: Use a guard clause (return unless payment.completed? || order.completed?) instead of wrapping the code inside a conditional expression.
if payment.completed? || order.completed?
^^
engines/order_management/app/services/order_management/order/updater.rb:167:11: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
persist_totals
^^^^^^^^^^^^^^
engines/order_management/app/services/order_management/order/updater.rb:168:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
engines/order_management/app/services/order_management/order/updater.rb:169:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
lib/discourse/single_sign_on.rb:33:9: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
raise "Bad signature for payload #{diags}" unless parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/discourse/single_sign_on.rb:33:9: C: [Corrected] Style/GuardClause: Use a guard clause (raise "Bad signature for payload #{diags}" unless parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m) instead of wrapping the code inside a conditional expression.
if parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m
^^
lib/discourse/single_sign_on.rb:34:11: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
raise "The SSO field should be Base64 encoded, using only A-Z, a-z, 0-9, +, /, " \ ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/discourse/single_sign_on.rb:37:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/discourse/single_sign_on.rb:38:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/discourse/single_sign_on.rb:39:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/discourse/single_sign_on.rb:39:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/discourse/single_sign_on.rb:40:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/open_food_network/order_cycle_form_applicator.rb:76:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless manages_coordinator?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:76:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless manages_coordinator?) instead of wrapping the code inside a conditional expression.
if manages_coordinator?
^^
lib/open_food_network/order_cycle_form_applicator.rb:77:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
exchange.save!
^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:78:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
ExchangeVariantBulkUpdater.new(exchange).update!(variant_ids) unless variant_ids.nil?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:80:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
@touched_exchanges << exchange
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:81:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/open_food_network/order_cycle_form_applicator.rb:82:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
lib/open_food_network/order_cycle_form_applicator.rb:107:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless manages_coordinator?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:107:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless manages_coordinator?) instead of wrapping the code inside a conditional expression.
if manages_coordinator?
^^
lib/open_food_network/order_cycle_form_applicator.rb:108:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
untouched_exchanges.each(&:destroy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/open_food_network/order_cycle_form_applicator.rb:109:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/open_food_network/order_cycle_form_applicator.rb:111:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
lib/spree/core/controller_helpers/respond_with.rb:42:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
raise ActionController::UnknownFormat unless format
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/spree/core/controller_helpers/respond_with.rb:42:7: C: [Corrected] Style/GuardClause: Use a guard clause (raise ActionController::UnknownFormat unless format) instead of wrapping the code inside a conditional expression.
if format
^^
lib/spree/core/controller_helpers/respond_with.rb:43:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
_process_format(format)
^^^^^^^^^^^^^^^^^^^^^^^
lib/spree/core/controller_helpers/respond_with.rb:44:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
collector
^^^^^^^^^
lib/spree/core/controller_helpers/respond_with.rb:45:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/spree/core/controller_helpers/respond_with.rb:46:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
lib/spree/core/controller_helpers/respond_with.rb:46:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/spree/core/controller_helpers/respond_with.rb:47:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/spree/core/controller_helpers/respond_with.rb:47:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
lib/spree/core/controller_helpers/respond_with.rb:48:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/spree/core/controller_helpers/respond_with.rb:48:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
spec/support/request/distribution_helper.rb:10:7: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless order_cycle && page.has_select?('order_order_cycle_id')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/request/distribution_helper.rb:10:7: C: [Corrected] Style/GuardClause: Use a guard clause (return unless order_cycle && page.has_select?('order_order_cycle_id')) instead of wrapping the code inside a conditional expression.
if order_cycle && page.has_select?('order_order_cycle_id')
^^
spec/support/request/distribution_helper.rb:11:9: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
select_by_value order_cycle.id, from: 'order_order_cycle_id'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/request/distribution_helper.rb:12:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/support/request/distribution_helper.rb:13:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
spec/support/request/shop_workflow.rb:127:5: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return unless oc.exchanges.from_enterprise(supplier).incoming.empty?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/request/shop_workflow.rb:127:5: C: [Corrected] Style/GuardClause: Use a guard clause (return unless oc.exchanges.from_enterprise(supplier).incoming.empty?) instead of wrapping the code inside a conditional expression.
if oc.exchanges.from_enterprise(supplier).incoming.empty?
^^
spec/support/request/shop_workflow.rb:128:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
create(:exchange, order_cycle: oc, incoming: true, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/request/shop_workflow.rb:130:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/support/request/shop_workflow.rb:131:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.
spec/system/support/precompile_assets.rb:18:5: C: [Corrected] Style/GuardClause: Use a guard clause (next if Webpacker.dev_server.running?) instead of wrapping the code inside a conditional expression.
if Webpacker.dev_server.running?
^^
spec/system/support/precompile_assets.rb:19:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/support/precompile_assets.rb:20:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
spec/system/support/precompile_assets.rb:20:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/support/precompile_assets.rb:21:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
$stdout.puts "\n Precompiling assets.\n"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/support/precompile_assets.rb:23:7: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
Webpacker.compile
^^^^^^^^^^^^^^^^^
spec/system/support/precompile_assets.rb:24:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
spec/system/support/precompile_assets.rb:24:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
1488 files inspected, 220 offenses detected, 218 offenses corrected, 1 more offense can be corrected with `rubocop -A`
587 lines
20 KiB
Ruby
587 lines
20 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
class Enterprise < ApplicationRecord
|
|
SELLS = %w(unspecified none own any).freeze
|
|
ENTERPRISE_SEARCH_RADIUS = 100
|
|
# The next Rails version will have named variants but we need to store them
|
|
# ourselves for now.
|
|
LOGO_SIZES = [:thumb, :small, :medium].freeze
|
|
PROMO_IMAGE_SIZES = [:thumb, :medium, :large].freeze
|
|
WHITE_LABEL_LOGO_SIZES = [:default, :mobile].freeze
|
|
VALID_INSTAGRAM_REGEX = %r{\A[a-zA-Z0-9._]{1,30}([^/-]*)\z}
|
|
|
|
searchable_attributes :sells, :is_primary_producer, :name
|
|
searchable_associations :properties
|
|
searchable_scopes :is_primary_producer, :is_distributor, :is_hub, :activated, :visible,
|
|
:ready_for_checkout, :not_ready_for_checkout
|
|
|
|
preference :shopfront_message, :text, default: ""
|
|
preference :shopfront_closed_message, :text, default: ""
|
|
preference :shopfront_taxon_order, :string, default: ""
|
|
preference :shopfront_producer_order, :string, default: ""
|
|
preference :shopfront_order_cycle_order, :string, default: "orders_close_at"
|
|
preference :shopfront_product_sorting_method, :string, default: "by_category"
|
|
preference :invoice_order_by_supplier, :boolean, default: false
|
|
preference :product_low_stock_display, :boolean, default: false
|
|
|
|
# Allow hubs to restrict visible variants to only those in their inventory
|
|
preference :product_selection_from_inventory_only, :boolean, default: false
|
|
|
|
has_paper_trail only: [:owner_id, :sells], on: [:update]
|
|
|
|
has_many :relationships_as_parent, class_name: 'EnterpriseRelationship',
|
|
foreign_key: 'parent_id',
|
|
dependent: :destroy
|
|
has_many :relationships_as_child, class_name: 'EnterpriseRelationship',
|
|
foreign_key: 'child_id',
|
|
dependent: :destroy
|
|
has_and_belongs_to_many :groups, join_table: 'enterprise_groups_enterprises',
|
|
class_name: 'EnterpriseGroup'
|
|
has_many :producer_properties, foreign_key: 'producer_id'
|
|
has_many :properties, through: :producer_properties
|
|
has_many :supplied_products, class_name: 'Spree::Product',
|
|
foreign_key: 'supplier_id',
|
|
dependent: :destroy
|
|
has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id'
|
|
belongs_to :address, class_name: 'Spree::Address'
|
|
belongs_to :business_address, optional: true, class_name: 'Spree::Address', dependent: :destroy
|
|
has_many :enterprise_fees
|
|
has_many :enterprise_roles, dependent: :destroy
|
|
has_many :users, through: :enterprise_roles
|
|
belongs_to :owner, class_name: 'Spree::User',
|
|
inverse_of: :owned_enterprises
|
|
has_many :distributor_payment_methods,
|
|
inverse_of: :distributor, foreign_key: :distributor_id
|
|
has_many :distributor_shipping_methods,
|
|
inverse_of: :distributor, foreign_key: :distributor_id
|
|
has_many :payment_methods, through: :distributor_payment_methods
|
|
has_many :shipping_methods, through: :distributor_shipping_methods
|
|
has_many :customers
|
|
has_many :inventory_items
|
|
has_many :tag_rules
|
|
has_one :stripe_account, dependent: :destroy
|
|
has_many :vouchers
|
|
has_one :custom_tab, dependent: :destroy
|
|
|
|
delegate :latitude, :longitude, :city, :state_name, to: :address
|
|
|
|
accepts_nested_attributes_for :address
|
|
accepts_nested_attributes_for :business_address, reject_if: :business_address_empty?,
|
|
allow_destroy: true
|
|
accepts_nested_attributes_for :producer_properties, allow_destroy: true,
|
|
reject_if: lambda { |pp|
|
|
pp[:property_name].blank?
|
|
}
|
|
accepts_nested_attributes_for :tag_rules, allow_destroy: true,
|
|
reject_if: lambda { |tag_rule|
|
|
tag_rule[:preferred_customer_tags].blank?
|
|
}
|
|
accepts_nested_attributes_for :custom_tab
|
|
|
|
has_one_attached :terms_and_conditions
|
|
has_one_attached :logo, service: image_service do |attachment|
|
|
attachment.variant :thumb, resize_to_fill: [100, 100], crop: [0, 0, 100, 100]
|
|
attachment.variant :small, resize_to_fill: [180, 180], crop: [0, 0, 180, 180]
|
|
attachment.variant :medium, resize_to_fill: [300, 300], crop: [0, 0, 300, 300]
|
|
end
|
|
has_one_attached :promo_image, service: image_service do |attachment|
|
|
attachment.variant :thumb, resize_to_limit: [100, 100]
|
|
attachment.variant :medium, resize_to_fill: [720, 156]
|
|
attachment.variant :large, resize_to_fill: [1200, 260]
|
|
end
|
|
has_one_attached :white_label_logo, service: image_service do |attachment|
|
|
attachment.variant :default, resize_to_fill: [217, 44]
|
|
attachment.variant :mobile, resize_to_fill: [128, 26]
|
|
end
|
|
|
|
validates :logo,
|
|
processable_image: true,
|
|
content_type: %r{\Aimage/(png|jpeg|gif|jpg|svg\+xml|webp)\Z}
|
|
validates :promo_image,
|
|
processable_image: true,
|
|
content_type: %r{\Aimage/(png|jpeg|gif|jpg|svg\+xml|webp)\Z}
|
|
validates :terms_and_conditions, content_type: {
|
|
in: "application/pdf",
|
|
message: I18n.t(:enterprise_terms_and_conditions_type_error),
|
|
}
|
|
|
|
validates :name, presence: true
|
|
validate :name_is_unique
|
|
validates :sells, presence: true, inclusion: { in: SELLS }
|
|
validates :address, associated: true
|
|
validates :permalink, uniqueness: true, presence: true
|
|
validate :shopfront_taxons
|
|
validate :shopfront_producers
|
|
validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? }
|
|
validates :instagram,
|
|
format: {
|
|
with: VALID_INSTAGRAM_REGEX,
|
|
message: Spree.t('errors.messages.invalid_instagram_url')
|
|
}, allow_blank: true
|
|
validate :validate_white_label_logo_link
|
|
|
|
before_validation :initialize_permalink, if: lambda { permalink.nil? }
|
|
before_validation :set_unused_address_fields
|
|
after_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
|
|
|
|
after_create :set_default_contact
|
|
after_create :relate_to_owners_enterprises
|
|
after_rollback :restore_permalink
|
|
after_touch :touch_distributors
|
|
after_create_commit :send_welcome_email
|
|
|
|
scope :by_name, -> { order('name') }
|
|
scope :visible, -> { where(visible: "public") }
|
|
scope :not_hidden, -> { where.not(visible: "hidden") }
|
|
scope :activated, -> { where("sells != 'unspecified'") }
|
|
scope :ready_for_checkout, lambda {
|
|
joins(:shipping_methods).
|
|
joins(:payment_methods).
|
|
merge(Spree::PaymentMethod.available).
|
|
merge(Spree::ShippingMethod.frontend).
|
|
select('DISTINCT enterprises.*')
|
|
}
|
|
scope :not_ready_for_checkout, lambda {
|
|
# When ready_for_checkout is empty, return all rows when there are no enterprises ready for
|
|
# checkout.
|
|
ready_enterprises = Enterprise.default_scoped.ready_for_checkout.
|
|
except(:select).
|
|
select('DISTINCT enterprises.id')
|
|
|
|
if ready_enterprises.any?
|
|
where.not(enterprises: { id: ready_enterprises })
|
|
else
|
|
where(nil)
|
|
end
|
|
}
|
|
scope :is_primary_producer, -> { where("enterprises.is_primary_producer IS TRUE") }
|
|
scope :is_distributor, -> { where.not(sells: 'none') }
|
|
scope :is_hub, -> { where(sells: 'any') }
|
|
scope :supplying_variant_in, lambda { |variants|
|
|
joins(supplied_products: :variants).
|
|
where('spree_variants.id IN (?)', variants).
|
|
select('DISTINCT enterprises.*')
|
|
}
|
|
|
|
scope :with_order_cycles_as_supplier_outer, -> {
|
|
joins("
|
|
LEFT OUTER JOIN exchanges
|
|
ON (exchanges.sender_id = enterprises.id AND exchanges.incoming = 't')").
|
|
joins("LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)")
|
|
}
|
|
|
|
scope :with_order_cycles_as_distributor_outer, -> {
|
|
joins("
|
|
LEFT OUTER JOIN exchanges
|
|
ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
|
|
joins("LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)")
|
|
}
|
|
|
|
scope :with_order_cycles_outer, -> {
|
|
joins("
|
|
LEFT OUTER JOIN exchanges
|
|
ON (exchanges.receiver_id = enterprises.id OR exchanges.sender_id = enterprises.id)").
|
|
joins("LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)")
|
|
}
|
|
|
|
scope :with_order_cycles_and_exchange_variants_outer, -> {
|
|
with_order_cycles_as_distributor_outer.
|
|
joins("LEFT OUTER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)").
|
|
joins("LEFT OUTER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)")
|
|
}
|
|
|
|
scope :distributors_with_active_order_cycles, lambda {
|
|
with_order_cycles_as_distributor_outer.
|
|
merge(OrderCycle.active).
|
|
select('DISTINCT enterprises.*')
|
|
}
|
|
|
|
scope :distributing_products, lambda { |product_ids|
|
|
exchanges = joins("
|
|
INNER JOIN exchanges
|
|
ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')
|
|
").
|
|
joins('INNER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
|
|
joins('INNER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)').
|
|
where('spree_variants.product_id IN (?)', product_ids).select('DISTINCT enterprises.id')
|
|
|
|
where(id: exchanges)
|
|
}
|
|
|
|
scope :managed_by, lambda { |user|
|
|
if user.has_spree_role?('admin')
|
|
where(nil)
|
|
else
|
|
joins(:enterprise_roles).where('enterprise_roles.user_id = ?', user.id)
|
|
end
|
|
}
|
|
|
|
scope :parents_of_one_union_others, lambda { |one, others|
|
|
where("
|
|
enterprises.id IN
|
|
(SELECT parent_id FROM enterprise_relationships WHERE enterprise_relationships.child_id=?)
|
|
OR enterprises.id IN
|
|
(?)
|
|
", one, others)
|
|
}
|
|
|
|
def business_address_empty?(attributes)
|
|
attributes_exists = attributes['id'].present?
|
|
attributes_empty = attributes.slice(:company, :address1, :city, :phone,
|
|
:zipcode).values.all?(&:blank?)
|
|
attributes.merge!(_destroy: 1) if attributes_exists && attributes_empty
|
|
!attributes_exists && attributes_empty
|
|
end
|
|
|
|
# Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554
|
|
def self.distinct_count
|
|
count(distinct: true)
|
|
end
|
|
|
|
def contact
|
|
contact = users.where(enterprise_roles: { receives_notifications: true }).first
|
|
contact || owner
|
|
end
|
|
|
|
def update_contact(user_id)
|
|
enterprise_roles.update_all(["receives_notifications=(user_id=?)", user_id])
|
|
end
|
|
|
|
def activated?
|
|
contact.confirmed? && sells != 'unspecified'
|
|
end
|
|
|
|
def set_producer_property(property_name, property_value)
|
|
transaction do
|
|
property = Spree::Property.
|
|
where(name: property_name).
|
|
first_or_create!(presentation: property_name)
|
|
producer_property = ProducerProperty.
|
|
where(producer_id: id, property_id: property.id).
|
|
first_or_initialize
|
|
producer_property.value = property_value
|
|
producer_property.save!
|
|
end
|
|
end
|
|
|
|
def to_param
|
|
permalink
|
|
end
|
|
|
|
def relatives
|
|
Enterprise.where("
|
|
enterprises.id IN
|
|
(SELECT child_id FROM enterprise_relationships WHERE enterprise_relationships.parent_id=?)
|
|
OR enterprises.id IN
|
|
(SELECT parent_id FROM enterprise_relationships WHERE enterprise_relationships.child_id=?)
|
|
", id, id)
|
|
end
|
|
|
|
def plus_parents_and_order_cycle_producers(order_cycles)
|
|
oc_producer_ids = Exchange.in_order_cycle(order_cycles).incoming.pluck :sender_id
|
|
Enterprise.is_primary_producer.parents_of_one_union_others(id, oc_producer_ids | [id])
|
|
end
|
|
|
|
def relatives_including_self
|
|
Enterprise.where(id: relatives.pluck(:id) | [id])
|
|
end
|
|
|
|
def distributors
|
|
relatives_including_self.is_distributor
|
|
end
|
|
|
|
def suppliers
|
|
relatives_including_self.is_primary_producer
|
|
end
|
|
|
|
def logo_url(name)
|
|
image_url_for(logo, name)
|
|
end
|
|
|
|
def promo_image_url(name)
|
|
image_url_for(promo_image, name)
|
|
end
|
|
|
|
def white_label_logo_url(name = :default)
|
|
image_url_for(white_label_logo, name)
|
|
end
|
|
|
|
def website
|
|
strip_url self[:website]
|
|
end
|
|
|
|
def facebook
|
|
strip_url self[:facebook]
|
|
end
|
|
|
|
def linkedin
|
|
strip_url self[:linkedin]
|
|
end
|
|
|
|
def twitter
|
|
correct_twitter_url self[:twitter]
|
|
end
|
|
|
|
def instagram
|
|
correct_instagram_url self[:instagram]
|
|
end
|
|
|
|
def whatsapp_url
|
|
correct_whatsapp_url self[:whatsapp_phone]
|
|
end
|
|
|
|
def inventory_variants
|
|
if prefers_product_selection_from_inventory_only?
|
|
Spree::Variant.visible_for(self)
|
|
else
|
|
Spree::Variant.not_hidden_for(self)
|
|
end
|
|
end
|
|
|
|
def distributed_variants
|
|
Spree::Variant.
|
|
joins(:product).
|
|
merge(Spree::Product.in_distributor(self)).
|
|
select('spree_variants.*')
|
|
end
|
|
|
|
def is_distributor
|
|
sells != "none"
|
|
end
|
|
|
|
def is_hub
|
|
sells == 'any'
|
|
end
|
|
|
|
# Simplify enterprise categories for frontend logic and icons, and maybe other things.
|
|
def category
|
|
# Make this crazy logic human readable so we can argue about it sanely.
|
|
cat = is_primary_producer ? "producer_" : "non_producer_"
|
|
cat << ("sells_" + sells)
|
|
|
|
# Map backend cases to front end cases.
|
|
case cat
|
|
when "producer_sells_any"
|
|
:producer_hub # Producer hub who sells own and others produce and supplies other hubs.
|
|
when "producer_sells_own"
|
|
:producer_shop # Producer with shopfront and supplies other hubs.
|
|
when "producer_sells_none"
|
|
:producer # Producer only supplies through others.
|
|
when "non_producer_sells_any"
|
|
:hub # Hub selling others products in order cycles.
|
|
when "non_producer_sells_own"
|
|
:hub # Wholesaler selling through own shopfront? Does this need a separate name or even exist?
|
|
when "non_producer_sells_none"
|
|
:hub_profile # Hub selling outside the system.
|
|
end
|
|
end
|
|
|
|
# Return all taxons for all distributed products
|
|
def distributed_taxons
|
|
Spree::Taxon.
|
|
joins(:products).
|
|
where('spree_products.id IN (?)', Spree::Product.in_distributor(self).select(&:id)).
|
|
select('DISTINCT spree_taxons.*')
|
|
end
|
|
|
|
def current_distributed_taxons
|
|
Spree::Taxon
|
|
.select("DISTINCT spree_taxons.*")
|
|
.joins(products: :variants)
|
|
.joins("INNER JOIN (#{current_exchange_variants.to_sql}) \
|
|
AS exchange_variants ON spree_variants.id = exchange_variants.variant_id")
|
|
end
|
|
|
|
# Return all taxons for all supplied products
|
|
def supplied_taxons
|
|
Spree::Taxon.
|
|
joins(:products).
|
|
where('spree_products.id IN (?)', Spree::Product.in_supplier(self).select(&:id)).
|
|
select('DISTINCT spree_taxons.*')
|
|
end
|
|
|
|
def ready_for_checkout?
|
|
shipping_methods.frontend.any? && payment_methods.available.any?(&:configured?)
|
|
end
|
|
|
|
def self.find_available_permalink(test_permalink)
|
|
test_permalink = UrlGenerator.to_url(test_permalink)
|
|
test_permalink = "my-enterprise" if test_permalink.blank?
|
|
existing = Enterprise.
|
|
select(:permalink).
|
|
order(:permalink).
|
|
where("permalink LIKE ?", "#{test_permalink}%").
|
|
map(&:permalink)
|
|
|
|
if existing.include?(test_permalink)
|
|
used_indices = existing.map do |p|
|
|
p.slice!(/^#{test_permalink}/)
|
|
p.match(/^\d+$/).to_s.to_i
|
|
end.select{ |p| p }
|
|
options = (1..existing.length).to_a - used_indices
|
|
test_permalink + options.first.to_s
|
|
else
|
|
test_permalink
|
|
end
|
|
end
|
|
|
|
def can_invoice?
|
|
return true unless Spree::Config.enterprise_number_required_on_invoices?
|
|
|
|
abn.present?
|
|
end
|
|
|
|
def public?
|
|
visible == "public"
|
|
end
|
|
|
|
protected
|
|
|
|
def devise_mailer
|
|
EnterpriseMailer
|
|
end
|
|
|
|
private
|
|
|
|
def validate_white_label_logo_link
|
|
return if white_label_logo.blank?
|
|
|
|
return if white_label_logo_link.blank?
|
|
|
|
white_label_logo_link.strip!
|
|
uri = URI(white_label_logo_link)
|
|
self.white_label_logo_link = "http://#{white_label_logo_link}" if uri.scheme.nil?
|
|
rescue URI::InvalidURIError
|
|
errors.add(:white_label_logo_link, I18n.t(:invalid_url, url: white_label_logo_link))
|
|
end
|
|
|
|
def image_url_for(image, name)
|
|
return unless image.variable?
|
|
|
|
image_variant_url_for(image.variant(name))
|
|
rescue ActiveStorage::Error, MiniMagick::Error, ActionView::Template::Error => e
|
|
Bugsnag.notify "Enterprise ##{id} #{image.try(:name)} error: #{e.message}"
|
|
Rails.logger.error(e.message)
|
|
|
|
nil
|
|
end
|
|
|
|
def current_exchange_variants
|
|
ExchangeVariant.joins(exchange: :order_cycle)
|
|
.merge(Exchange.outgoing)
|
|
.select("DISTINCT exchange_variants.variant_id, exchanges.receiver_id AS enterprise_id")
|
|
.where("exchanges.receiver_id = ?", id)
|
|
.merge(OrderCycle.active.with_distributor(id))
|
|
end
|
|
|
|
def name_is_unique
|
|
dups = Enterprise.where(name: name)
|
|
dups = dups.where.not(id: id) unless new_record?
|
|
|
|
errors.add :name, I18n.t(:enterprise_name_error, email: dups.first.owner.email) if dups.any?
|
|
end
|
|
|
|
def send_welcome_email
|
|
EnterpriseMailer.welcome(self).deliver_later
|
|
end
|
|
|
|
def strip_url(url)
|
|
# Strip protocol and trailing slash
|
|
url&.sub(%r{(https?://)?}, '')&.sub(%r{/\z}, '')
|
|
end
|
|
|
|
def correct_whatsapp_url(phone_number)
|
|
phone_number && ("https://wa.me/" + phone_number.tr('+ ', ''))
|
|
end
|
|
|
|
def correct_instagram_url(url)
|
|
url && strip_url(url.downcase).sub(%r{(www\.)?instagram.com/}, '').delete("@")
|
|
end
|
|
|
|
def correct_twitter_url(url)
|
|
url && strip_url(url).sub(%r{(www\.)?twitter.com/}, '').delete("@")
|
|
end
|
|
|
|
def set_unused_address_fields
|
|
if address.present?
|
|
address.firstname = address.lastname = address.phone =
|
|
address.company = 'unused'
|
|
end
|
|
business_address.first_name = business_address.last_name = 'unused' if business_address.present?
|
|
end
|
|
|
|
def ensure_owner_is_manager
|
|
users << owner unless users.include?(owner)
|
|
end
|
|
|
|
def enforce_ownership_limit
|
|
return if owner.can_own_more_enterprises?
|
|
|
|
errors.add(:owner, I18n.t(:enterprise_owner_error, email: owner.email,
|
|
enterprise_limit: owner.enterprise_limit ))
|
|
end
|
|
|
|
def set_default_contact
|
|
update_contact owner_id
|
|
end
|
|
|
|
def relate_to_owners_enterprises
|
|
# When a new producer is created, it grants permissions to all pre-existing hubs
|
|
# When a new hub is created,
|
|
# - it grants permissions to all pre-existing hubs
|
|
# - all producers grant permission to it
|
|
|
|
enterprises = owner.owned_enterprises.where.not(enterprises: { id: self })
|
|
|
|
# We grant permissions to all pre-existing hubs
|
|
hub_permissions = [:add_to_order_cycle]
|
|
hub_permissions << :create_variant_overrides if is_primary_producer
|
|
enterprises.is_hub.each do |enterprise|
|
|
EnterpriseRelationship.create!(parent: self,
|
|
child: enterprise,
|
|
permissions_list: hub_permissions)
|
|
end
|
|
|
|
# All pre-existing producers grant permission to new hubs
|
|
return unless is_hub
|
|
|
|
enterprises.is_primary_producer.each do |enterprise|
|
|
EnterpriseRelationship.create!(parent: enterprise,
|
|
child: self,
|
|
permissions_list: [:add_to_order_cycle,
|
|
:create_variant_overrides])
|
|
end
|
|
end
|
|
|
|
def shopfront_taxons
|
|
return if preferred_shopfront_taxon_order =~ /\A((\d+,)*\d+)?\z/
|
|
|
|
errors.add(:shopfront_category_ordering, "must contain a list of taxons.")
|
|
end
|
|
|
|
def shopfront_producers
|
|
return if preferred_shopfront_producer_order =~ /\A((\d+,)*\d+)?\z/
|
|
|
|
errors.add(:shopfront_category_ordering, "must contain a list of producers.")
|
|
end
|
|
|
|
def restore_permalink
|
|
# If the permalink has errors, reset it to it's original value, so we can update the form
|
|
self.permalink = permalink_was if permalink_changed? && errors[:permalink].present?
|
|
end
|
|
|
|
def initialize_permalink
|
|
return unless name
|
|
|
|
self.permalink = Enterprise.find_available_permalink(name)
|
|
end
|
|
|
|
# Touch distributors without them touching their distributors.
|
|
# We avoid an infinite loop and don't need to touch the whole distributor tree.
|
|
def touch_distributors
|
|
Enterprise.distributing_products(supplied_products.select(:id)).
|
|
where.not(enterprises: { id: id }).
|
|
update_all(updated_at: Time.zone.now)
|
|
end
|
|
end
|