Skip to content

Commit

Permalink
use snack case for object type on authz annotations (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
  • Loading branch information
golanglemonade authored Dec 13, 2024
1 parent cb7ddc0 commit c9e8632
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion history/generateschemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"entgo.io/ent/entc"
"entgo.io/ent/entc/gen"
"entgo.io/ent/entc/load"
"github.com/stoewer/go-strcase"
"github.com/theopenlane/iam/entfga"
)

Expand Down Expand Up @@ -243,7 +244,7 @@ func (t *templateInfo) getAuthzPolicyInfo(schema *load.Schema) error {

// default to schema name if object type is not set
if annotations.ObjectType == "" {
t.AuthzPolicy.ObjectType = strings.ToLower(schema.Name)
t.AuthzPolicy.ObjectType = strcase.SnakeCase(schema.Name)
} else {
t.AuthzPolicy.ObjectType = annotations.ObjectType
}
Expand Down
9 changes: 9 additions & 0 deletions history/generateschemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func TestGetAuthzPolicyInfo(t *testing.T) {
IDField: "Ref",
},
},
{
name: "self referencing schema, snake case",
schemaName: "ActionPlan",
expectedValue: authzPolicyInfo{
ObjectType: "action_plan",
NillableIDField: false,
IDField: "Ref",
},
},
{
name: "org owned schema",
schemaName: "List",
Expand Down
30 changes: 30 additions & 0 deletions history/testdata/schema/action_plan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package schema

import (
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"github.com/theopenlane/iam/entfga"
)

type ActionPlan struct {
ent.Schema
}

func (ActionPlan) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
}
}

func (ActionPlan) Indexes() []ent.Index {
return []ent.Index{}
}

func (ActionPlan) Annotations() []schema.Annotation {
return []schema.Annotation{
entfga.Annotations{
IncludeHooks: false,
},
}
}

0 comments on commit c9e8632

Please sign in to comment.