mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Switching enterprise index to its own dedicated serializer, so we can spit out ownership
This commit is contained in:
@@ -61,23 +61,23 @@
|
||||
|
||||
.omega.eight.columns
|
||||
%div{ ng: { if: "!enterprise.is_primary_producer"} }
|
||||
%a.button.selector{ ng: { click: "enterprise.sells='none'", class: "{selected: enterprise.sells=='none'}" } }
|
||||
%a.button.selector{ ng: { click: "enterprise.owned && (enterprise.sells='none')", class: "{selected: enterprise.sells=='none', disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Profile Only
|
||||
%p Connect through OFN
|
||||
.bottom ALWAYS FREE
|
||||
%a.button.selector{ ng: { click: "enterprise.sells='any'", class: "{selected: enterprise.sells=='any'}" } }
|
||||
%a.button.selector{ ng: { click: "enterprise.owned && (enterprise.sells='any')", class: "{selected: enterprise.sells=='any', disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Hub Shop
|
||||
%p Sell produce from others
|
||||
.bottom ALWAYS FREE
|
||||
|
||||
%div{ ng: { if: "enterprise.is_primary_producer"} }
|
||||
%a.button.selector{ ng: { click: "enterprise.sells='none'", class: "{selected: enterprise.sells=='none'}" } }
|
||||
%a.button.selector{ ng: { click: "enterprise.owned && (enterprise.sells='none')", class: "{selected: enterprise.sells=='none', disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Profile Only
|
||||
.bottom ALWAYS FREE
|
||||
%a.button.selector{ ng: { click: "enterprise.sells='own'", class: "{selected: enterprise.sells=='own'}" } }
|
||||
%a.button.selector{ ng: { click: "enterprise.owned && (enterprise.sells='own')", class: "{selected: enterprise.sells=='own', disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Producer Shop
|
||||
%p Sell your own produce
|
||||
@@ -85,7 +85,7 @@
|
||||
\%2 OF SALES
|
||||
%br
|
||||
CAPPED AT $50 PER MONTH
|
||||
%a.button.selector{ ng: { click: "enterprise.sells='any';", class: "{selected: enterprise.sells=='any'}" } }
|
||||
%a.button.selector{ ng: { click: "enterprise.owned && (enterprise.sells='any')", class: "{selected: enterprise.sells=='any', disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Producer Hub
|
||||
%p Sell produce from self and others
|
||||
@@ -94,7 +94,7 @@
|
||||
%br
|
||||
CAPPED AT $50 PER MONTH
|
||||
|
||||
%a.button.update.fullwidth{ ng: { class: "{disabled: saved() && !saving, saving: saving}", click: "save()" } }
|
||||
%a.button.update.fullwidth{ ng: { show: "enterprise.owned", class: "{disabled: saved() && !saving, saving: saving}", click: "save()" } }
|
||||
%span{ ng: {hide: "saved() || saving" } }
|
||||
SAVE
|
||||
%i.icon-save
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
%p Instead, non-producers specialise in linking producers to the end eater, whether it be by aggregating, grading, packing, selling or delivering food.
|
||||
|
||||
.omega.eight.columns
|
||||
%a.button.selector{ ng: { click: 'changeToProducer()', class: "{selected: enterprise.is_primary_producer==true}" } }
|
||||
%a.button.selector{ ng: { click: 'enterprise.owned && changeToProducer()', class: "{selected: enterprise.is_primary_producer==true, disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 PRODUCER
|
||||
%p Primary producers of food
|
||||
.bottom eg. GROWERS, BAKERS, BREWERS, MAKERS
|
||||
|
||||
%a.button.selector{ ng: { click: 'changeToNonProducer()', class: "{selected: enterprise.is_primary_producer==false}" } }
|
||||
%a.button.selector{ ng: { click: 'enterprise.owned && changeToNonProducer()', class: "{selected: enterprise.is_primary_producer==false, disabled: !enterprise.owned}" } }
|
||||
.top
|
||||
%h3 Non-Producer
|
||||
%p All other food enterprises
|
||||
.bottom eg. Grocery stores, Food co-ops, Buying groups
|
||||
|
||||
%a.button.update.fullwidth{ ng: { class: "{disabled: saved() && !saving, saving: saving}", click: "save()" } }
|
||||
%a.button.update.fullwidth{ ng: { show: "enterprise.owned", class: "{disabled: saved() && !saving, saving: saving}", click: "save()" } }
|
||||
%span{ ng: {hide: "saved() || saving" } }
|
||||
SAVE
|
||||
%i.icon-save
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
border-top-color: #9fc820;
|
||||
}
|
||||
}
|
||||
&.disabled{
|
||||
background-color: #C1C1C1;
|
||||
}
|
||||
.bottom {
|
||||
background: repeating-linear-gradient(60deg, rgba(84, 152, 218, 0), rgba(84, 152, 218, 0) 5px, rgba(255, 255, 255, 0.25) 5px, rgba(255, 255, 255, 0.25) 10px);
|
||||
margin-top: 1em;
|
||||
|
||||
@@ -27,7 +27,7 @@ module Admin
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json do
|
||||
render json: @collection, each_serializer: Api::Admin::BasicEnterpriseSerializer
|
||||
render json: @collection, each_serializer: Api::Admin::IndexEnterpriseSerializer, spree_current_user: spree_current_user
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -40,7 +40,7 @@ module Admin
|
||||
respond_with(@object) do |format|
|
||||
format.html { redirect_to location_after_save }
|
||||
format.js { render :layout => false }
|
||||
format.json { render json: @object, serializer: Api::Admin::BasicEnterpriseSerializer }
|
||||
format.json { render json: @object, serializer: Api::Admin::IndexEnterpriseSerializer, spree_current_user: spree_current_user }
|
||||
end
|
||||
else
|
||||
invoke_callbacks(:update, :fails)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids
|
||||
attributes :producer_profile_only, :permalink
|
||||
attributes :producer_profile_only
|
||||
end
|
||||
|
||||
8
app/serializers/api/admin/index_enterprise_serializer.rb
Normal file
8
app/serializers/api/admin/index_enterprise_serializer.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Api::Admin::IndexEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :permalink, :is_primary_producer, :sells, :producer_profile_only, :owned
|
||||
|
||||
def owned
|
||||
return true if options[:spree_current_user].admin?
|
||||
object.owner == options[:spree_current_user]
|
||||
end
|
||||
end
|
||||
34
spec/serializers/admin/index_enterprise_serializer_spec.rb
Normal file
34
spec/serializers/admin/index_enterprise_serializer_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
describe Api::Admin::IndexEnterpriseSerializer do
|
||||
include AuthenticationWorkflow
|
||||
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
context "when spree_current_user is a manager" do
|
||||
let(:user) { create_enterprise_user }
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: enterprise)
|
||||
end
|
||||
|
||||
it "sets 'owned' to false" do
|
||||
serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user
|
||||
serializer.to_json.should match "\"owned\":false"
|
||||
end
|
||||
end
|
||||
|
||||
context "when spree_current_user is " do
|
||||
let(:user) { enterprise.owner }
|
||||
|
||||
it "sets 'owned' to true" do
|
||||
serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user
|
||||
serializer.to_json.should match "\"owned\":true"
|
||||
end
|
||||
end
|
||||
|
||||
context "when spree_current_user is the owner" do
|
||||
let(:user) { create(:admin_user) }
|
||||
|
||||
it "sets 'owned' to true" do
|
||||
serializer = Api::Admin::IndexEnterpriseSerializer.new enterprise, spree_current_user: user
|
||||
serializer.to_json.should match "\"owned\":true"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user