Skip to content

Commit d0edb60

Browse files
davidsvantessontechknowlogick
authored andcommitted
Fix what information is shown about user in API. (#9115)
* Fix what information is shown about user in API. * Use Email directly, as KeepEmailPrivate is already handled.
1 parent e84326a commit d0edb60

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

modules/convert/convert.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,21 @@ func ToTeam(team *models.Team) *api.Team {
256256
}
257257

258258
// ToUser convert models.User to api.User
259+
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
259260
func ToUser(user *models.User, signed, authed bool) *api.User {
260261
result := &api.User{
261262
UserName: user.Name,
262263
AvatarURL: user.AvatarLink(),
263264
FullName: markup.Sanitize(user.FullName),
264265
Created: user.CreatedUnix.AsTime(),
265266
}
266-
// hide primary email if API caller isn't user itself or an admin
267-
if !signed {
268-
result.Email = ""
269-
} else if user.KeepEmailPrivate && !authed {
270-
result.Email = user.GetEmail()
271-
} else { // only user himself and admin could visit these information
272-
result.ID = user.ID
267+
// hide primary email if API caller is anonymous or user keep email private
268+
if signed && (!user.KeepEmailPrivate || authed) {
273269
result.Email = user.Email
270+
}
271+
// only site admin will get these information and possibly user himself
272+
if authed {
273+
result.ID = user.ID
274274
result.IsAdmin = user.IsAdmin
275275
result.LastLogin = user.LastLoginUnix.AsTime()
276276
}

0 commit comments

Comments
 (0)