Merge pull request #9087 from georgethoppil/enterprise-invisible

Change enterprise visibility scope
This commit is contained in:
Filipe
2022-04-22 10:52:32 +01:00
committed by GitHub
14 changed files with 78 additions and 24 deletions

View File

@@ -120,7 +120,8 @@ class Enterprise < ApplicationRecord
after_rollback :restore_permalink
scope :by_name, -> { order('name') }
scope :visible, -> { where(visible: true) }
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).
@@ -267,7 +268,7 @@ class Enterprise < ApplicationRecord
def plus_relatives_and_oc_producers(order_cycles)
oc_producer_ids = Exchange.in_order_cycle(order_cycles).incoming.pluck :sender_id
Enterprise.is_primary_producer.relatives_of_one_union_others(id, oc_producer_ids | [id])
Enterprise.not_hidden.is_primary_producer.relatives_of_one_union_others(id, oc_producer_ids | [id])
end
def relatives_including_self
@@ -401,6 +402,10 @@ class Enterprise < ApplicationRecord
abn.present?
end
def public?
visible == "public"
end
protected
def devise_mailer

View File

@@ -13,8 +13,8 @@ module Api
:default_tag_group, :require_login, :allow_guest_orders, :allow_order_changes,
:logo, :promo_image, :terms_and_conditions,
:terms_and_conditions_file_name, :terms_and_conditions_updated_at,
:preferred_invoice_order_by_supplier,
:preferred_product_low_stock_display
:preferred_invoice_order_by_supplier, :preferred_product_low_stock_display,
:visible
has_one :owner, serializer: Api::Admin::UserSerializer
has_many :users, serializer: Api::Admin::UserSerializer

View File

@@ -42,11 +42,14 @@
%div{'ofn-with-tip' => t('.visible_in_search_tip')}
%a= t('admin.whats_this')
.two.columns
= f.radio_button :visible, true
= f.label :visible, t('.visible'), value: 'true'
.five.columns.omega
= f.radio_button :visible, false
= f.label :visible, t('.not_visible'), value: 'false'
= f.radio_button :visible, "public", 'ng-model' => 'Enterprise.visible'
= f.label :visible, t('.visible'), value: 'public'
.two.columns
= f.radio_button :visible, "only_through_links", 'ng-model' => 'Enterprise.visible'
= f.label :visible, t('.not_visible'), value: 'only_through_links'
.four.columns.omega
= f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible'
= f.label :visible, t('.hidden'), value: 'hidden'
.permalink{ ng: { controller: "permalinkCtrl" } }
.row{ ng: { show: "Enterprise.sells == 'own' || Enterprise.sells == 'any'" } }
.three.columns.alpha

View File

@@ -26,7 +26,7 @@
#package_selection{ hidden: true }
= render partial: "/admin/enterprises/change_type_form"
- if !@enterprise.visible
- unless @enterprise.public?
.alert-box
%strong
= t "spree_admin_single_enterprise_hint"

View File

@@ -922,9 +922,10 @@ en:
sells: Sells
sells_tip: "None - enterprise does not sell to customers directly.<br />Own - Enterprise sells own products to customers.<br />Any - Enterprise can sell own or other enterprises products.<br />"
visible_in_search: Visible in search?
visible_in_search_tip: Determines whether this enterprise will be visible to customers when searching the site.
visible: Visible
not_visible: Not visible
visible_in_search_tip: "Shops can be <br />1. publicly visible, appearing on the OFN map and listings. <br />2. Hidden on maps and listings but referenced by other shops and linked in their profile. <br />3. Completely hidden."
visible: Public
not_visible: Hidden
hidden: Hide all references
permalink: Permalink (no spaces)
permalink_tip: "This permalink is used to create the url to your shop: %{link}your-shop-name/shop"
link_to_front: Link to shop front

View File

@@ -0,0 +1,20 @@
class ChangeVisibleDataTypeForEnterprises < ActiveRecord::Migration[6.1]
class Enterprise < ActiveRecord::Base; end
def up
add_column :enterprises, :visible_tmp, :string, limit: 255, default: "public", null: false
Enterprise.reset_column_information
Enterprise.where(:visible => 0).update_all(visible_tmp: "only_through_links")
remove_column :enterprises, :visible
rename_column :enterprises, :visible_tmp, :visible
end
def down
add_column :enterprises, :visible_tmp, :boolean, default: true, null: false
Enterprise.reset_column_information
Enterprise.where("visible != 'public'").update_all(visible_tmp: false)
remove_column :enterprises, :visible
rename_column :enterprises, :visible_tmp, :visible
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_04_07_051248) do
ActiveRecord::Schema.define(version: 2022_04_10_162955) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -191,7 +191,6 @@ ActiveRecord::Schema.define(version: 2022_04_07_051248) do
t.string "promo_image_content_type", limit: 255
t.integer "promo_image_file_size"
t.datetime "promo_image_updated_at"
t.boolean "visible", default: true
t.string "facebook", limit: 255
t.string "instagram", limit: 255
t.string "linkedin", limit: 255
@@ -213,6 +212,7 @@ ActiveRecord::Schema.define(version: 2022_04_07_051248) do
t.datetime "terms_and_conditions_updated_at"
t.integer "business_address_id"
t.boolean "show_customer_names_to_suppliers", default: false, null: false
t.string "visible", limit: 255, default: "public", null: false
t.index ["address_id"], name: "index_enterprises_on_address_id"
t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells"
t.index ["name"], name: "index_enterprises_on_name", unique: true

View File

@@ -43,7 +43,7 @@ module OpenFoodNetwork
def warnings
warnings = []
unless @enterprise.visible
unless @enterprise.public?
warnings << {
description: I18n.t('admin.enterprise_issues.not_visible', enterprise: @enterprise.name),
link: "<a class='button fullwidth' href='#{edit_admin_enterprise_path(@enterprise)}'>#{I18n.t(:edit)}</a>"

View File

@@ -28,6 +28,12 @@ FactoryBot.define do
sells { "none" }
end
factory :supplier_enterprise_hidden, parent: :enterprise do
is_primary_producer { true }
sells { "none" }
visible { "hidden" }
end
factory :distributor_enterprise, parent: :enterprise do
is_primary_producer { false }
sells { "any" }

View File

@@ -6,7 +6,7 @@ require 'open_food_network/enterprise_issue_validator'
module OpenFoodNetwork
describe EnterpriseIssueValidator do
describe "warnings" do
let(:enterprise_invisible) { create(:enterprise, visible: false) }
let(:enterprise_invisible) { create(:enterprise, visible: "only_through_links") }
let(:warnings) { EnterpriseIssueValidator.new(enterprise_invisible).warnings }
it "reports invisible enterprises" do

View File

@@ -5,13 +5,18 @@ require 'spec_helper'
describe Api::EnterpriseShopfrontSerializer do
let!(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:producer) { create(:supplier_enterprise) }
let!(:producer_hidden) { create(:supplier_enterprise_hidden) }
let!(:relationship) { create(:enterprise_relationship, parent: hub, child: producer) }
let!(:relationship2) { create(:enterprise_relationship, parent: hub, child: producer_hidden) }
let!(:taxon1) { create(:taxon, name: 'Meat') }
let!(:taxon2) { create(:taxon, name: 'Veg') }
let!(:product) {
create(:product, supplier: producer, primary_taxon: taxon1, taxons: [taxon1, taxon2] )
}
let!(:product2) {
create(:product, supplier: producer_hidden, primary_taxon: taxon1, taxons: [taxon1, taxon2] )
}
let(:close_time) { 2.days.from_now }
let!(:oc) { create(:simple_order_cycle, orders_close_at: close_time, distributors: [hub]) }
@@ -20,6 +25,10 @@ describe Api::EnterpriseShopfrontSerializer do
create(:exchange, order_cycle: oc, incoming: false,
sender: producer, receiver: hub)
}
let!(:ex2) {
create(:exchange, order_cycle: oc, incoming: false,
sender: producer_hidden, receiver: hub)
}
let(:serializer) { Api::EnterpriseShopfrontSerializer.new hub }
@@ -41,7 +50,7 @@ describe Api::EnterpriseShopfrontSerializer do
expect(serializer.serializable_hash[:hubs].to_json).to match hub.name
end
it "serializes an array of producers" do
it "serializes an array of producers that are public or linked by links" do
expect(serializer.serializable_hash[:producers]).to be_a ActiveModel::ArraySerializer
expect(serializer.serializable_hash[:producers].to_json).to match producer.name
end

View File

@@ -201,7 +201,7 @@ describe '
expect(page).to have_field 'enterprise_name', with: 'Eaterprises'
@enterprise.reload
expect(@enterprise.owner).to eq user
expect(page).to have_checked_field "enterprise_visible_true"
expect(page).to have_checked_field "enterprise_visible_public"
click_link "Business Details"
expect(page).to have_checked_field "enterprise_charges_sales_tax_true"

View File

@@ -32,7 +32,7 @@ describe '
context "when visibilty is set to false" do
before do
d1.visible = false
d1.visible = "only_through_links"
d1.save!
end

View File

@@ -71,10 +71,20 @@ describe 'Groups', js: true do
coordinator: create(:distributor_enterprise))
}
let(:producer) { create(:supplier_enterprise) }
let(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true, visible: true) }
let(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true, visible: true) }
let(:d3) { create(:distributor_enterprise, with_payment_and_shipping: true, visible: false) }
let(:d4) { create(:distributor_enterprise, with_payment_and_shipping: true, visible: true) }
let(:d1) {
create(:distributor_enterprise, with_payment_and_shipping: true, visible: "public")
}
let(:d2) {
create(:distributor_enterprise, with_payment_and_shipping: true, visible: "public")
}
let(:d3) {
create(:distributor_enterprise,
with_payment_and_shipping: true,
visible: "only_through_links")
}
let(:d4) {
create(:distributor_enterprise, with_payment_and_shipping: true, visible: "public")
}
let(:p1) { create(:simple_product, supplier: producer) }
let(:p2) { create(:simple_product, supplier: create(:supplier_enterprise)) }
let(:p3) { create(:simple_product, supplier: create(:supplier_enterprise)) }