mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
User can delete relationship between enterprises in both direction
A permits B B permits A Manager for A and B enterprises can delete the two relations. Update specs as well
This commit is contained in:
@@ -342,7 +342,8 @@ module Spree
|
||||
def add_relationship_management_abilities(user)
|
||||
can [:admin, :index, :create], EnterpriseRelationship
|
||||
can [:destroy], EnterpriseRelationship do |enterprise_relationship|
|
||||
user.enterprises.include? enterprise_relationship.parent
|
||||
user.enterprises.include?(enterprise_relationship.parent) ||
|
||||
user.enterprises.include?(enterprise_relationship.child)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -328,6 +328,8 @@ describe Spree::Ability do
|
||||
|
||||
let(:er1) { create(:enterprise_relationship, parent: s1, child: d1) }
|
||||
let(:er2) { create(:enterprise_relationship, parent: d1, child: s1) }
|
||||
let(:er3) { create(:enterprise_relationship, parent: s2, child: d2) }
|
||||
|
||||
let(:er_ps) {
|
||||
create(:enterprise_relationship, parent: s_related, child: s1,
|
||||
permissions_list: [:manage_products])
|
||||
@@ -429,8 +431,12 @@ describe Spree::Ability do
|
||||
is_expected.to have_ability(:destroy, for: er1)
|
||||
end
|
||||
|
||||
it "should be able to destroy enterprise relationships for other enterprises that are linked as child" do
|
||||
is_expected.to have_ability(:destroy, for: er2)
|
||||
end
|
||||
|
||||
it "should not be able to destroy enterprise relationships for other enterprises" do
|
||||
is_expected.not_to have_ability(:destroy, for: er2)
|
||||
is_expected.not_to have_ability(:destroy, for: er3)
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
@@ -655,8 +661,12 @@ describe Spree::Ability do
|
||||
is_expected.to have_ability(:destroy, for: er2)
|
||||
end
|
||||
|
||||
it "should be able to destroy enterprise relationships for other enterprises that are linked as child" do
|
||||
is_expected.to have_ability(:destroy, for: er1)
|
||||
end
|
||||
|
||||
it "should not be able to destroy enterprise relationships for other enterprises" do
|
||||
is_expected.not_to have_ability(:destroy, for: er1)
|
||||
is_expected.not_to have_ability(:destroy, for: er3)
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
|
||||
Reference in New Issue
Block a user