Skip to content

Commit

Permalink
Merge pull request #1940 from josephschorr/schema-prefix-rewrite-caveat
Browse files Browse the repository at this point in the history
Ensure the object type prefix is used for caveat refs as well
  • Loading branch information
josephschorr authored Jun 15, 2024
2 parents 819f424 + c670d53 commit ebe0417
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
17 changes: 12 additions & 5 deletions pkg/schemadsl/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,22 @@ func TestCompile(t *testing.T) {
{
"relation with required caveat",
withTenantPrefix,
`definition simple {
`
caveat somecaveat(someparam int) { someparam == 42}
definition simple {
relation viewer: user with somecaveat
}`,
"",
[]SchemaDefinition{
namespace.MustCaveatDefinition(caveats.MustEnvForVariables(
map[string]caveattypes.VariableType{
"someparam": caveattypes.IntType,
},
), "sometenant/somecaveat", "someparam == 42"),
namespace.Namespace("sometenant/simple",
namespace.MustRelation("viewer", nil,
namespace.AllowedRelationWithCaveat("sometenant/user", "...",
namespace.AllowedCaveat("somecaveat")),
namespace.AllowedCaveat("sometenant/somecaveat")),
),
),
},
Expand All @@ -178,7 +185,7 @@ func TestCompile(t *testing.T) {
namespace.Namespace("sometenant/simple",
namespace.MustRelation("viewer", nil,
namespace.AllowedRelationWithCaveat("sometenant/user", "...",
namespace.AllowedCaveat("somecaveat")),
namespace.AllowedCaveat("sometenant/somecaveat")),
namespace.AllowedRelation("sometenant/user", "..."),
),
),
Expand All @@ -195,10 +202,10 @@ func TestCompile(t *testing.T) {
namespace.Namespace("sometenant/simple",
namespace.MustRelation("viewer", nil,
namespace.AllowedRelationWithCaveat("sometenant/user", "...",
namespace.AllowedCaveat("somecaveat")),
namespace.AllowedCaveat("sometenant/somecaveat")),
namespace.AllowedRelation("sometenant/user", "..."),
namespace.AllowedRelationWithCaveat("sometenant/team", "member",
namespace.AllowedCaveat("anothercaveat")),
namespace.AllowedCaveat("sometenant/anothercaveat")),
),
),
},
Expand Down
9 changes: 7 additions & 2 deletions pkg/schemadsl/compiler/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func translateSpecificTypeReference(tctx translationContext, typeRefNode *dslNod
return ref, nil
}

func addWithCaveats(_ translationContext, typeRefNode *dslNode, ref *core.AllowedRelation) error {
func addWithCaveats(tctx translationContext, typeRefNode *dslNode, ref *core.AllowedRelation) error {
caveats := typeRefNode.List(dslshape.NodeSpecificReferencePredicateCaveat)
if len(caveats) == 0 {
return nil
Expand All @@ -645,8 +645,13 @@ func addWithCaveats(_ translationContext, typeRefNode *dslNode, ref *core.Allowe
return err
}

nspath, err := tctx.prefixedPath(name)
if err != nil {
return err
}

ref.RequiredCaveat = &core.AllowedCaveat{
CaveatName: name,
CaveatName: nspath,
}
return nil
}

0 comments on commit ebe0417

Please sign in to comment.