Skip to content

Commit

Permalink
feat: fixup access to history (#126)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade authored Jan 13, 2025
1 parent bd4747c commit a46bedb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions entfga/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func extractDefaultObjectType(val any) string {
return strings.Trim(strings.ReplaceAll(schemaName, "history", ""), "_")
}

// isHistorySchema checks if the schema name contains the word "history"
func isHistorySchema(schemaName string) bool {
return strings.Contains(schemaName, "History")
}

// extractIDField gets the key that is used for the id field
func extractIDField(val any) string {
idField, ok := val.(string)
Expand Down Expand Up @@ -172,6 +177,7 @@ func parseAuthzChecksTemplate(info templateInfo) error {
"hasCreateID": hasCreateID,
"hasMutationInputSet": hasMutationInputSet,
"ToLower": strings.ToLower,
"isHistorySchema": isHistorySchema,
})

// parse the template
Expand Down
5 changes: 5 additions & 0 deletions entfga/templates/authzChecks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
{{- $defaultObjectType := extractDefaultObjectType $n.Name }}
{{- $mutator := $n.MutationName }}
{{- $querier := $n.QueryName }}
{{- $isHistory := isHistorySchema $querier }}

{{/* Only include nodes with the Authz check anntoation. See: Annotations.Name */}}
{{- if $n.Annotations.Authz }}
Expand Down Expand Up @@ -90,7 +91,11 @@ var (

// check if the user has access to the object requested
ac := fgax.AccessCheck{
{{- if $isHistory }}
Relation: fgax.CanViewAuditLog,
{{- else }}
Relation: fgax.CanView,
{{- end }}
ObjectType: "{{ $objectType | ToLower }}",
SubjectType: auth.GetAuthzSubjectType(ctx),
SubjectID: subjectID,
Expand Down
2 changes: 2 additions & 0 deletions fgax/tuples.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
CanInviteMembers = "can_invite_members"
// CanInviteAdmins is the relation for inviting admins to an entity
CanInviteAdmins = "can_invite_admins"
// CanViewAuditLog is the relation for viewing the audit log of an entity
CanViewAuditLog = "audit_log_viewer"
)

const (
Expand Down

0 comments on commit a46bedb

Please sign in to comment.