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 GetGraph bug #54

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
6 changes: 4 additions & 2 deletions graph/check_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ types:
can_invite: parent->can_read - viewer

# viewer can be user or group but owner can only be user
union_type_subset: viewer | owner
union_type_subset_arrow: viewer | parent->owner
negation_type_subset: viewer - owner

# viewer can be user or group but owner can only be user
negation_type_subset_arrow: viewer - parent->owner
intersection_type_subset: viewer & owner
intersection_type_subset_arrow: viewer & parent->owner

cycle:
relations:
Expand Down
4 changes: 3 additions & 1 deletion graph/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
dsc "github.com/aserto-dev/go-directory/aserto/directory/common/v3"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v3"
"github.com/aserto-dev/go-directory/pkg/derr"
"github.com/rs/zerolog/log"
"github.com/samber/lo"
)

Expand All @@ -25,8 +26,9 @@ func NewObjectSearch(m *model.Model, req *dsr.GetGraphRequest, reader RelationRe
// validate the model but skip name validation. To avoid name collisions, the inverted model
// uses mangled names that are not valid identifiers.
if err := im.Validate(model.SkipNameValidation, model.AllowPermissionInArrowBase); err != nil {
log.Err(err).Interface("req", req).Msg("inverted model is invalid")
// TODO: we should persist the inverted model instead of computing it on the fly.
return nil, derr.ErrUnknown.Msg("internal error: unable to search for objects.")
return nil, derr.ErrUnknown.Msg("internal error: unable to search objects.")
}

iParams := invertGetGraphRequest(im, req)
Expand Down
5 changes: 4 additions & 1 deletion model/inverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ func (ti *termInverter) invertArrow() {
itip := ti.inv.irelSub(ti.objName, ti.term.Base)
baseRel := ti.obj.Relations[ti.term.Base]

typeRefs := set.NewSet(ti.perm.Types()...)
typeRefs := set.NewSet(ti.term.Types()...)
if typeRefs.IsEmpty() {
typeRefs.Append(ti.perm.Types()...)
}
typeRefs.Intersect(ti.typeSet).Each(func(rr RelationRef) bool {
iName := InverseRelation(ti.objName, ti.permName, rr.Relation)
iPerm := permissionOrNew(ti.inv.im.Objects[rr.Object], iName, ti.kind)
Expand Down