Skip to content

Commit

Permalink
Add missing check in relation inversion logic (#57)
Browse files Browse the repository at this point in the history
It was adding terms that refer to non-existent realtions.
  • Loading branch information
ronenh authored Sep 23, 2024
1 parent 60f4d5f commit 5736b57
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion graph/check_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ types:
owner: user
parent: folder
viewer: user | user:* | group#member
auditor: user#manager
permissions:
can_view: viewer
can_change_owner: owner | parent->is_owner
Expand Down Expand Up @@ -86,4 +87,3 @@ types:
editors:
relations:
member: user | group#member

2 changes: 1 addition & 1 deletion graph/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *ObjectSearch) Search() (*dsr.GetGraphResponse, error) {
}

func invertGetGraphRequest(im *model.Model, req *dsr.GetGraphRequest) *relation {
rel := model.InverseRelation(model.ObjectName(req.ObjectType), model.RelationName(req.Relation))
rel := model.InverseRelation(model.ObjectName(req.ObjectType), model.RelationName(req.Relation), model.RelationName(req.SubjectRelation))
relPerm := model.PermForRel(rel)
if im.Objects[model.ObjectName(req.SubjectType)].HasPermission(relPerm) {
rel = relPerm
Expand Down
4 changes: 4 additions & 0 deletions graph/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ var searchObjectsTests = []searchTest{
{"group:?#member@user:user3", []object{{"group", "d1_subviewers"}, {"group", "d1_viewers"}}},
{"group:?#member@user:yin_user", []object{{"group", "yin"}, {"group", "yang"}}},
{"doc:?#viewer@group:d1_subviewers#member", []object{{"doc", "doc1"}}},
{"doc:?#auditor@user:boss", []object{{"doc", "doc1"}}},
{"doc:?#auditor@user:employee#manager", []object{{"doc", "doc1"}}},

// wildcard
{"doc:?#viewer@user:user1", []object{{"doc", "doc1"}, {"doc", "doc2"}}},
Expand Down Expand Up @@ -192,6 +194,8 @@ func relations() RelationsReader {
"doc:doc2#viewer@user:*",
"doc:doc2#viewer@user:user2",
"doc:doc3#parent@folder:folder2",
"user:employee#manager@user:boss",
"doc:doc1#auditor@user:employee#manager",

"group:d1_viewers#member@group:d1_subviewers#member",
"group:d1_subviewers#member@user:user3",
Expand Down
4 changes: 3 additions & 1 deletion model/inverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func (i *inverter) invertRelation(on ObjectName, rn RelationName, r *Relation) {
p := permissionOrNew(i.im.Objects[subj.Object], ipn, permissionKindUnion)
i.addSubstitution(ipr, ipn)
if _, ok := unionObjs[subj.Object]; ok {
p.AddTerm(&PermissionTerm{RelOrPerm: InverseRelation(on, rn, subj.Relation)})
if i.im.Objects[subj.Object].HasRelOrPerm(ipr) {
p.AddTerm(&PermissionTerm{RelOrPerm: ipr})
}
}
p.AddTerm(&PermissionTerm{Base: InverseRelation(rr.Object, rr.Relation, subj.Relation), RelOrPerm: irn})
}
Expand Down

0 comments on commit 5736b57

Please sign in to comment.