MCPcopy Create free account
hub / github.com/Permify/permify / IsTupleFilterEmpty

Function IsTupleFilterEmpty

internal/validation/validation.go:111–145  ·  view source on GitHub ↗

IsTupleFilterEmpty checks whether any of the fields in a TupleFilter are filled. It assumes that a filter is "empty" if all its fields are unset or have zero values.

(filter *base.TupleFilter)

Source from the content-addressed store, hash-verified

109// IsTupleFilterEmpty checks whether any of the fields in a TupleFilter are filled.
110// It assumes that a filter is "empty" if all its fields are unset or have zero values.
111func IsTupleFilterEmpty(filter *base.TupleFilter) bool {
112 // If the entity type is set, the filter is not empty.
113 if filter.GetEntity().GetType() != "" {
114 return false // Entity type is present, therefore filter is not empty.
115 }
116
117 // If the entity IDs slice is not empty, the filter is not empty.
118 if len(filter.GetEntity().GetIds()) > 0 {
119 return false // Entity IDs are present, therefore filter is not empty.
120 }
121
122 // If the relation is set, the filter is not empty.
123 if filter.GetRelation() != "" {
124 return false // Relation is present, therefore filter is not empty.
125 }
126
127 // If the subject type is set, the filter is not empty.
128 if filter.GetSubject().GetType() != "" {
129 return false // Subject type is present, therefore filter is not empty.
130 }
131
132 // If the subject IDs slice is not empty, the filter is not empty.
133 if len(filter.GetSubject().GetIds()) > 0 {
134 return false // Subject IDs are present, therefore filter is not empty.
135 }
136
137 // If the subject relation is set, the filter is not empty.
138 if filter.GetSubject().GetRelation() != "" {
139 return false // Subject relation is present, therefore filter is not empty.
140 }
141
142 // If none of the above conditions are met, then all fields are unset or have zero values,
143 // which means the filter is empty.
144 return true
145}
146
147// IsAttributeFilterEmpty checks if the provided AttributeFilter object is empty.
148// An AttributeFilter is considered empty if none of its fields have been set.

Callers 5

deleteMethod · 0.92
DeleteMethod · 0.92
validation_test.goFile · 0.85
ValidateTupleFilterFunction · 0.85
ValidateFiltersFunction · 0.85

Calls 5

GetTypeMethod · 0.65
GetEntityMethod · 0.45
GetIdsMethod · 0.45
GetRelationMethod · 0.45
GetSubjectMethod · 0.45

Tested by

no test coverage detected