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

feat(coverage) : improve accuracy for evaluating permission condition #844

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions pkg/development/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,50 @@ func references(entity *base.EntityDefinition) (coverage SchemaCoverage) {
// Format and append the permission to the coverage struct
formattedPermission := fmt.Sprintf("%s#%s", entity.GetName(), permission.GetName())
coverage.Assertions = append(coverage.Assertions, formattedPermission)
conditionsAssertions(permission.GetChild(), entity.GetName(), &coverage.Assertions)
}
// Return the coverage struct
return
}

// Get assertions from permission condition
func conditionsAssertions(child *base.Child, entityName string, assertions *[]string) {
leaf := child.GetLeaf()
if leaf != nil {
compUserSet := leaf.GetComputedUserSet()
if compUserSet != nil {
relation := fmt.Sprintf("%s#%s", entityName, compUserSet.GetRelation())
if !slices.Contains(*assertions, relation) {
*assertions = append(*assertions, relation)
}
}
tupleToUserSet := leaf.GetTupleToUserSet()
if tupleToUserSet != nil {
tupComp := tupleToUserSet.GetComputed()
if tupComp != nil {
relation := fmt.Sprintf("%s#%s", entityName, tupComp.GetRelation())
if !slices.Contains(*assertions, relation) {
*assertions = append(*assertions, relation)
}
}
tupSet := tupleToUserSet.GetTupleSet()
if tupSet != nil {
relation := fmt.Sprintf("%s#%s", entityName, tupSet.GetRelation())
if !slices.Contains(*assertions, relation) {
*assertions = append(*assertions, relation)
}
}
}
}
rewrite := child.GetRewrite()
if rewrite != nil {
children := rewrite.GetChildren()
for _, child := range children {
conditionsAssertions(child, entityName, assertions)
}
}
}

// relationships - Get relationships for a given entity
func relationships(en string, relationships []string) []string {
var rels []string
Expand Down