MCPcopy Index your code
hub / github.com/apache/casbin / GetValuesForFieldInPolicy

Method GetValuesForFieldInPolicy

model/policy.go:405–420  ·  view source on GitHub ↗

GetValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.

(sec string, ptype string, fieldIndex int)

Source from the content-addressed store, hash-verified

403
404// GetValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.
405func (model Model) GetValuesForFieldInPolicy(sec string, ptype string, fieldIndex int) ([]string, error) {
406 values := []string{}
407
408 _, err := model.GetAssertion(sec, ptype)
409 if err != nil {
410 return nil, err
411 }
412
413 for _, rule := range model[sec][ptype].Policy {
414 values = append(values, rule[fieldIndex])
415 }
416
417 util.ArrayRemoveDuplicates(&values)
418
419 return values, nil
420}
421
422// GetValuesForFieldInPolicyAllTypes gets all values for a field for all rules in a policy of all ptypes, duplicated values are removed.
423func (model Model) GetValuesForFieldInPolicyAllTypes(sec string, fieldIndex int) ([]string, error) {

Calls 2

GetAssertionMethod · 0.95
ArrayRemoveDuplicatesFunction · 0.92

Tested by

no test coverage detected