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

Method getUser

pkg/identityserver/user_registry.go:292–347  ·  view source on GitHub ↗
(ctx context.Context, req *ttnpb.GetUserRequest)

Source from the content-addressed store, hash-verified

290}
291
292func (is *IdentityServer) getUser(ctx context.Context, req *ttnpb.GetUserRequest) (usr *ttnpb.User, err error) {
293 req.FieldMask = cleanFieldMaskPaths(ttnpb.UserFieldPathsNested, req.FieldMask, getPaths, nil)
294 if err = rights.RequireUser(ctx, req.GetUserIds(), ttnpb.Right_RIGHT_USER_INFO); err != nil {
295 if err := is.RequireAuthenticated(ctx); err != nil {
296 return nil, err
297 }
298 if !ttnpb.HasOnlyAllowedFields(req.FieldMask.GetPaths(), ttnpb.PublicUserFields...) {
299 return nil, err
300 }
301 defer func() { usr = usr.PublicSafe() }()
302 }
303 contactInfoInPath := ttnpb.HasAnyField(req.FieldMask.GetPaths(), "contact_info")
304 if contactInfoInPath {
305 req.FieldMask.Paths = ttnpb.ExcludeFields(req.FieldMask.Paths, "contact_info")
306 req.FieldMask.Paths = ttnpb.AddFields(
307 req.FieldMask.Paths, "primary_email_address", "primary_email_address_validated_at",
308 )
309 }
310
311 if ttnpb.HasAnyField(ttnpb.TopLevelFields(req.FieldMask.GetPaths()), "profile_picture") {
312 if is.configFromContext(ctx).ProfilePicture.UseGravatar {
313 if !ttnpb.HasAnyField(req.FieldMask.GetPaths(), "primary_email_address") {
314 req.FieldMask.Paths = ttnpb.AddFields(req.FieldMask.GetPaths(), "primary_email_address")
315 defer func() {
316 if usr != nil {
317 usr.PrimaryEmailAddress = ""
318 }
319 }()
320 }
321 defer func() { fillGravatar(ctx, usr) }()
322 }
323 defer func() { is.setFullProfilePictureURL(ctx, usr) }()
324 }
325
326 err = is.store.Transact(ctx, func(ctx context.Context, st store.Store) (err error) {
327 usr, err = st.GetUser(ctx, req.GetUserIds(), req.FieldMask.GetPaths())
328 if err != nil {
329 return err
330 }
331 if contactInfoInPath {
332 usr.ContactInfo = []*ttnpb.ContactInfo{
333 {
334 ContactType: ttnpb.ContactType_CONTACT_TYPE_OTHER,
335 ContactMethod: ttnpb.ContactMethod_CONTACT_METHOD_EMAIL,
336 Value: usr.PrimaryEmailAddress,
337 ValidatedAt: usr.PrimaryEmailAddressValidatedAt,
338 },
339 }
340 }
341 return err
342 })
343 if err != nil {
344 return nil, err
345 }
346 return usr, nil
347}
348
349func (is *IdentityServer) listUsers(ctx context.Context, req *ttnpb.ListUsersRequest) (users *ttnpb.Users, err error) {

Callers 2

GetMethod · 0.80
init.jsFile · 0.80

Implementers 5

mockInteroppkg/component/interop_test.go
interopServerpkg/joinserver/http_interop.go
noopServerpkg/interop/server.go
mockTargetpkg/interop/server_test.go
interopServerpkg/identityserver/http_interop.go

Calls 15

RequireAuthenticatedMethod · 0.95
configFromContextMethod · 0.95
RequireUserFunction · 0.92
HasOnlyAllowedFieldsFunction · 0.92
HasAnyFieldFunction · 0.92
ExcludeFieldsFunction · 0.92
AddFieldsFunction · 0.92
TopLevelFieldsFunction · 0.92
cleanFieldMaskPathsFunction · 0.85
fillGravatarFunction · 0.85
TransactMethod · 0.65

Tested by

no test coverage detected