ValidateSubjectType validates if the subject type and relation are present in the list of allowed relation types
(subject *base.Subject, relationTypes []string)
| 109 | |
| 110 | // ValidateSubjectType validates if the subject type and relation are present in the list of allowed relation types |
| 111 | func ValidateSubjectType(subject *base.Subject, relationTypes []string) (err error) { |
| 112 | if len(relationTypes) == 0 { |
| 113 | return errors.New(base.ErrorCode_ERROR_CODE_SUBJECT_TYPE_NOT_FOUND.String()) |
| 114 | } |
| 115 | |
| 116 | key := subject.GetType() |
| 117 | if subject.GetRelation() != "" && subject.GetRelation() != ELLIPSIS { |
| 118 | key += "#" + subject.GetRelation() // append relation to key |
| 119 | } |
| 120 | |
| 121 | if !slices.Contains(relationTypes, key) { // check if key is in relationTypes |
| 122 | return errors.New(base.ErrorCode_ERROR_CODE_SUBJECT_TYPE_NOT_FOUND.String()) // return error if not found |
| 123 | } |
| 124 | return nil // return nil if validation succeeds |
| 125 | } |
| 126 | |
| 127 | // SplitRelation splits a relation string by the separator "." and returns the result as a slice |
| 128 | func SplitRelation(relation string) (a []string) { |
no test coverage detected