Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: algebaric operation loop should be classified as loop in compile time #350

Open
wants to merge 1 commit into
base: feat/node_list_for_cycle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/go/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *AuthorizationModelGraph) nodeListHasNonComputedEdge(nodeList []graph.No
allEdges := g.Lines(nodeI.ID(), nodeJ.ID())
for allEdges.Next() {
edge, ok := allEdges.Line().(*AuthorizationModelEdge)
if ok && edge.edgeType != ComputedEdge {
if ok && (edge.edgeType == TTUEdge || edge.edgeType == DirectEdge) {
return true
}
}
Expand Down
59 changes: 47 additions & 12 deletions pkg/go/graph/graph_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ rankdir=BT
7 -> 6;
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: nil,
canHaveCyclesAtRuntime: [][]string{{"folder#a", "folder#b", "folder#c"}},
hasCyclesAtCompileTime: [][]string{{"folder#a", "folder#b", "folder#c"}},
canHaveCyclesAtRuntime: nil,
},
},
`multigraph`: {
Expand Down Expand Up @@ -820,8 +820,8 @@ rankdir=BT
9 -> 4 [style=dashed];
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: [][]string{{"folder#x", "folder#y"}},
canHaveCyclesAtRuntime: [][]string{{"folder#a", "folder#b", "folder#c"}},
hasCyclesAtCompileTime: [][]string{{"folder#x", "folder#y"}, {"folder#a", "folder#b", "folder#c"}},
canHaveCyclesAtRuntime: nil,
},
},
`potential_cycle_or_but_not`: {
Expand Down Expand Up @@ -861,8 +861,8 @@ rankdir=BT
7 -> 6;
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: nil,
canHaveCyclesAtRuntime: [][]string{{"resource#x", "resource#y", "resource#z"}},
hasCyclesAtCompileTime: [][]string{{"resource#x", "resource#y", "resource#z"}},
canHaveCyclesAtRuntime: nil,
},
},
`potential_cycle_four_union`: {
Expand Down Expand Up @@ -916,8 +916,7 @@ rankdir=BT
9 -> 6;
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: nil,
canHaveCyclesAtRuntime: [][]string{
hasCyclesAtCompileTime: [][]string{
{"group#member", "group#memberA"},
{"group#member", "group#memberB"},
{"group#member", "group#memberC"},
Expand All @@ -930,6 +929,7 @@ rankdir=BT
{"group#memberA", "group#memberB", "group#memberC"},
{"group#member", "group#memberA", "group#memberB", "group#memberC"},
},
canHaveCyclesAtRuntime: nil,
},
},
`potential_cycle_four_union_with_one_member_no_union`: {
Expand Down Expand Up @@ -978,13 +978,13 @@ rankdir=BT
8 -> 5;
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: nil,
canHaveCyclesAtRuntime: [][]string{
hasCyclesAtCompileTime: [][]string{
{"account#admin", "account#member"},
{"account#admin", "account#super_admin"},
{"account#member", "account#super_admin"},
{"account#admin", "account#member", "account#super_admin"},
},
canHaveCyclesAtRuntime: nil,
},
},
`intersection`: {
Expand Down Expand Up @@ -1031,13 +1031,48 @@ rankdir=BT
8 -> 3 [label=direct];
}`,
cycleInformation: CycleInformation{
hasCyclesAtCompileTime: nil,
canHaveCyclesAtRuntime: [][]string{
hasCyclesAtCompileTime: [][]string{
{"document#action1", "document#action2"},
{"document#action1", "document#action3"},
{"document#action2", "document#action3"},
{"document#action1", "document#action2", "document#action3"},
},
canHaveCyclesAtRuntime: nil,
},
},
`union_of_userset_other`: {
model: `
model
schema 1.1
type user

type document
relations
define editor: [user]
define viewer: [document#viewer] or editor`,
expectedOutput: `digraph {
graph [
rankdir=BT
];

// Node definitions.
0 [label=document];
1 [label="document#editor"];
2 [label=user];
3 [label="document#viewer"];
4 [label=union];

// Edge definitions.
1 -> 4;
2 -> 1 [label=direct];
3 -> 4 [label=direct];
4 -> 3;
}`,
cycleInformation: CycleInformation{
canHaveCyclesAtRuntime: [][]string{
{"document#viewer"},
},
hasCyclesAtCompileTime: nil,
},
},
}
Expand Down