Skip to content

Commit 7c0d09a

Browse files
authored
fixed intersection weight for multiple edges with common terminal typ… (#500)
fixed intersection weight for multiple edges with common terminal types except the first one
1 parent 02ef40c commit 7c0d09a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pkg/go/graph/weighted_graph.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ func (wg *WeightedAuthorizationModelGraph) calculateNodeWeightWithEnforceTypeStr
562562
}
563563

564564
rewriteWeights := make(map[string]int, len(edges))
565-
for _, edge := range edges {
565+
for index, edge := range edges {
566566

567-
if len(rewriteWeights) == 0 {
567+
if index == 0 {
568568
for key, weight := range edge.weights {
569569
rewriteWeights[key] = weight
570570
}

pkg/go/graph/weighted_graph_builder_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,35 @@ func TestGraphConstructionDirectAssignation(t *testing.T) {
893893
require.Equal(t, "user", graph.edges["folder#viewer"][0].to.uniqueLabel)
894894
}
895895

896+
func TestMixingTerminalTypesInIntersection(t *testing.T) {
897+
t.Parallel()
898+
model := `
899+
model
900+
schema 1.1
901+
type user
902+
type user2
903+
type subteam
904+
relations
905+
define member: [user]
906+
type adhoc
907+
relations
908+
define member: [user]
909+
type team
910+
relations
911+
define member: [subteam#member]
912+
type group
913+
relations
914+
define team: [team]
915+
define subteam: [subteam]
916+
define adhoc_member: [adhoc#member]
917+
define member: [user2] and member from team and adhoc_member and member from subteam
918+
`
919+
authorizationModel := language.MustTransformDSLToProto(model)
920+
wgb := NewWeightedAuthorizationModelGraphBuilder()
921+
_, err := wgb.Build(authorizationModel)
922+
require.ErrorContains(t, err, "invalid model: not all paths return the same type for the node intersection:")
923+
}
924+
896925
func TestGraphConstructionMultipleUsersetWithoutOrder(t *testing.T) {
897926
t.Parallel()
898927
model := `

0 commit comments

Comments
 (0)