MCPcopy
hub / github.com/dgraph-io/dgraph / UnmarshalUser

Function UnmarshalUser

acl/utils.go:84–100  ·  view source on GitHub ↗

UnmarshalUser extracts the first User pointed by the userKey in the query response.

(resp *api.Response, userKey string)

Source from the content-addressed store, hash-verified

82
83// UnmarshalUser extracts the first User pointed by the userKey in the query response.
84func UnmarshalUser(resp *api.Response, userKey string) (user *User, err error) {
85 m := make(map[string][]User)
86
87 err = json.Unmarshal(resp.GetJson(), &m)
88 if err != nil {
89 return nil, fmt.Errorf("unable to unmarshal the query user response: %w", err)
90 }
91 users := m[userKey]
92 if len(users) == 0 {
93 // the user does not exist
94 return nil, nil
95 }
96 if len(users) > 1 {
97 return nil, fmt.Errorf("found multiple users: %s", resp.GetJson())
98 }
99 return &users[0], nil
100}
101
102// Acl represents the permissions in the ACL system.
103// An Acl can have a predicate and permission for that predicate.

Callers 2

authorizeUserFunction · 0.92
queryUserFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected