MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ListUser

Function ListUser

pkg/auth/rights/list.go:150–178  ·  view source on GitHub ↗

ListUser lists the rights for the given user ID in the context.

(ctx context.Context, id *ttnpb.UserIdentifiers)

Source from the content-addressed store, hash-verified

148
149// ListUser lists the rights for the given user ID in the context.
150func ListUser(ctx context.Context, id *ttnpb.UserIdentifiers) (rights *ttnpb.Rights, err error) {
151 uid := unique.ID(ctx, id)
152 if inCtx, ok := fromContext(ctx); ok {
153 r, _ := inCtx.UserRights.GetRights(uid)
154 return r, nil
155 }
156 if inCtx, ok := cacheFromContext(ctx); ok {
157 if r, ok := inCtx.UserRights.GetRights(uid); ok {
158 return r, nil
159 }
160 }
161 defer func() {
162 if err == nil {
163 cacheInContext(ctx, func(r *Rights) { r.setUserRights(uid, rights) })
164 }
165 }()
166 fetcher, ok := fetcherFromContext(ctx)
167 if !ok {
168 panic(errNoFetcher)
169 }
170 rights, err = fetcher.UserRights(ctx, id)
171 if err != nil {
172 if errors.IsPermissionDenied(err) {
173 return &ttnpb.Rights{}, nil
174 }
175 return nil, err
176 }
177 return rights, nil
178}

Callers 4

EventIsVisibleFunction · 0.92
listUserRightsMethod · 0.92
RequireUserFunction · 0.85
RequireAnyFunction · 0.85

Calls 9

IDFunction · 0.92
IsPermissionDeniedFunction · 0.92
fromContextFunction · 0.85
cacheFromContextFunction · 0.85
cacheInContextFunction · 0.85
setUserRightsMethod · 0.80
fetcherFromContextFunction · 0.70
UserRightsMethod · 0.65
GetRightsMethod · 0.45

Tested by

no test coverage detected