MCPcopy Index your code
hub / github.com/Permify/permify / ValidateTuple

Function ValidateTuple

internal/validation/validation.go:15–48  ·  view source on GitHub ↗

ValidateTuple checks if the provided tuple conforms to the entity definition and relation schema provided. It returns an error if the tuple is invalid.

(definition *base.EntityDefinition, tup *base.Tuple)

Source from the content-addressed store, hash-verified

13// ValidateTuple checks if the provided tuple conforms to the entity definition
14// and relation schema provided. It returns an error if the tuple is invalid.
15func ValidateTuple(definition *base.EntityDefinition, tup *base.Tuple) (err error) {
16 // Check if the entity and the subject of the tuple are the same
17 if tuple.IsEntityAndSubjectEquals(tup) {
18 return errors.New(base.ErrorCode_ERROR_CODE_ENTITY_AND_SUBJECT_CANNOT_BE_EQUAL.String())
19 }
20
21 // Initialize variables for the relation definition and valid types
22 var rel *base.RelationDefinition
23 var vt []string
24
25 // Get the relation definition for the tuple's relation within the entity definition
26 rel, err = schema.GetRelationByNameInEntityDefinition(definition, tup.GetRelation())
27 if err != nil {
28 return err
29 }
30
31 // Iterate over relation references and build the list of valid types
32 for _, t := range rel.GetRelationReferences() {
33 if t.GetRelation() != "" {
34 vt = append(vt, fmt.Sprintf("%s#%s", t.GetType(), t.GetRelation()))
35 } else {
36 vt = append(vt, t.GetType())
37 }
38 }
39
40 // Validate if the subject type is among the valid types
41 err = tuple.ValidateSubjectType(tup.GetSubject(), vt)
42 if err != nil {
43 return err
44 }
45
46 // If no errors were encountered, return nil
47 return nil
48}
49
50// ValidateTupleFilter checks if the provided filter conforms to the entity definition
51func ValidateTupleFilter(tupleFilter *base.TupleFilter) (err error) {

Callers 4

RunWithShapeMethod · 0.92
WriteMethod · 0.92
WriteRelationshipsMethod · 0.92
validation_test.goFile · 0.85

Calls 8

GetRelationReferencesMethod · 0.95
IsEntityAndSubjectEqualsFunction · 0.92
ValidateSubjectTypeFunction · 0.92
StringMethod · 0.65
GetTypeMethod · 0.65
GetRelationMethod · 0.45
GetSubjectMethod · 0.45

Tested by

no test coverage detected