Skip to content

Commit

Permalink
Fix what information is shown about user in API. (#9115)
Browse files Browse the repository at this point in the history
* Fix what information is shown about user in API.

* Use Email directly, as KeepEmailPrivate is already handled.
  • Loading branch information
davidsvantesson authored and techknowlogick committed Nov 24, 2019
1 parent e84326a commit d0edb60
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions modules/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,21 @@ func ToTeam(team *models.Team) *api.Team {
}

// ToUser convert models.User to api.User
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
func ToUser(user *models.User, signed, authed bool) *api.User {
result := &api.User{
UserName: user.Name,
AvatarURL: user.AvatarLink(),
FullName: markup.Sanitize(user.FullName),
Created: user.CreatedUnix.AsTime(),
}
// hide primary email if API caller isn't user itself or an admin
if !signed {
result.Email = ""
} else if user.KeepEmailPrivate && !authed {
result.Email = user.GetEmail()
} else { // only user himself and admin could visit these information
result.ID = user.ID
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
result.Email = user.Email
}
// only site admin will get these information and possibly user himself
if authed {
result.ID = user.ID
result.IsAdmin = user.IsAdmin
result.LastLogin = user.LastLoginUnix.AsTime()
}
Expand Down

0 comments on commit d0edb60

Please sign in to comment.