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:
Jean-Baptiste Bellet
2021-11-08 11:23:27 +01:00
parent 8cb2a2cc96
commit 6266c3c5ae
2 changed files with 14 additions and 3 deletions

View File

@@ -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

View File

@@ -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