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

Function RequireUser

pkg/auth/rights/require.go:200–214  ·  view source on GitHub ↗

RequireUser checks that context contains the required rights for the given user ID.

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

Source from the content-addressed store, hash-verified

198// RequireUser checks that context contains the required rights for the
199// given user ID.
200func RequireUser(ctx context.Context, id *ttnpb.UserIdentifiers, required ...ttnpb.Right) (err error) {
201 uid := unique.ID(ctx, id)
202 rights, err := ListUser(ctx, id)
203 if err != nil {
204 return err
205 }
206 if len(rights.GetRights()) == 0 {
207 return ErrNoUserRights.WithAttributes("uid", uid)
208 }
209 missing := ttnpb.RightsFrom(required...).Sub(rights).GetRights()
210 if len(missing) > 0 {
211 return ErrInsufficientUserRights.WithAttributes("uid", uid, "missing", rightsNames(missing...))
212 }
213 return nil
214}
215
216// RequireAny checks that context contains any rights for each of
217// the given entity identifiers.

Callers 15

requireRightsFunction · 0.92
TestRequireFunction · 0.92
requireProfileRightsFunction · 0.92
RequestValidationMethod · 0.92
listNotificationsMethod · 0.92
getUserMethod · 0.92
updateUserMethod · 0.92
deleteUserMethod · 0.92
restoreUserMethod · 0.92
purgeUserMethod · 0.92
createGatewayMethod · 0.92

Calls 7

IDFunction · 0.92
RightsFromFunction · 0.92
ListUserFunction · 0.85
rightsNamesFunction · 0.85
SubMethod · 0.80
GetRightsMethod · 0.45
WithAttributesMethod · 0.45

Tested by 2

requireRightsFunction · 0.74
TestRequireFunction · 0.74