mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Owners can update sells on enterprises they own
This commit is contained in:
@@ -171,13 +171,15 @@ module Admin
|
||||
def check_can_change_bulk_sells
|
||||
unless spree_current_user.admin?
|
||||
params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
|
||||
enterprise_params.delete :sells
|
||||
enterprise_params.delete :sells unless spree_current_user == Enterprise.find_by_id(enterprise_params[:id]).owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_can_change_sells
|
||||
params[:enterprise].delete :sells unless spree_current_user.admin?
|
||||
unless spree_current_user.admin? || spree_current_user == @enterprise.owner
|
||||
params[:enterprise].delete :sells
|
||||
end
|
||||
end
|
||||
|
||||
def override_owner
|
||||
|
||||
@@ -184,6 +184,15 @@ module Admin
|
||||
end
|
||||
|
||||
context "as owner" do
|
||||
it "allows 'sells' to be changed" do
|
||||
controller.stub spree_current_user: profile_enterprise.owner
|
||||
enterprise_params = { id: profile_enterprise, enterprise: { sells: 'any' } }
|
||||
|
||||
spree_put :update, enterprise_params
|
||||
profile_enterprise.reload
|
||||
expect(profile_enterprise.sells).to eq 'any'
|
||||
end
|
||||
|
||||
it "allows owner to be changed" do
|
||||
controller.stub spree_current_user: distributor_owner
|
||||
update_params = { id: distributor, enterprise: { owner_id: distributor_manager } }
|
||||
@@ -386,6 +395,21 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
context "as the owner of an enterprise" do
|
||||
it "allows 'sells' and 'owner' to be changed" do
|
||||
controller.stub spree_current_user: original_owner
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
|
||||
|
||||
spree_put :bulk_update, bulk_enterprise_params
|
||||
profile_enterprise1.reload
|
||||
profile_enterprise2.reload
|
||||
expect(profile_enterprise1.sells).to eq 'any'
|
||||
expect(profile_enterprise2.sells).to eq 'any'
|
||||
expect(profile_enterprise1.owner).to eq original_owner
|
||||
expect(profile_enterprise2.owner).to eq original_owner
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
it "allows 'sells' and 'owner' to be changed" do
|
||||
profile_enterprise1.enterprise_roles.build(user: new_owner).save
|
||||
|
||||
Reference in New Issue
Block a user