summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-24 10:52:17 +0800
committerGitHub <noreply@github.com>2019-10-24 10:52:17 +0800
commitbd7709a60200a760d872f8210dae9b527fc99d8f (patch)
tree241a710cf45f6530dcff1aa8cf1de56a571c6a2a /routers/api
parentab791fe7bbcf7b57e1ba0e577172b6d6252847a7 (diff)
downloadgitea-bd7709a60200a760d872f8210dae9b527fc99d8f.tar.gz
gitea-bd7709a60200a760d872f8210dae9b527fc99d8f.zip
Hide some user information via API if user have no enough permission (#8655)
* Hide some user information via API if user have no enough permission * fix test
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/convert/convert.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go
index 0262051390..07456f8dd6 100644
--- a/routers/api/v1/convert/convert.go
+++ b/routers/api/v1/convert/convert.go
@@ -237,12 +237,9 @@ func ToTeam(team *models.Team) *api.Team {
// ToUser convert models.User to api.User
func ToUser(user *models.User, signed, authed bool) *api.User {
result := &api.User{
- ID: user.ID,
UserName: user.Name,
AvatarURL: user.AvatarLink(),
FullName: markup.Sanitize(user.FullName),
- IsAdmin: user.IsAdmin,
- LastLogin: user.LastLoginUnix.AsTime(),
Created: user.CreatedUnix.AsTime(),
}
// hide primary email if API caller isn't user itself or an admin
@@ -250,8 +247,11 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
result.Email = ""
} else if user.KeepEmailPrivate && !authed {
result.Email = user.GetEmail()
- } else {
+ } else { // only user himself and admin could visit these information
+ result.ID = user.ID
result.Email = user.Email
+ result.IsAdmin = user.IsAdmin
+ result.LastLogin = user.LastLoginUnix.AsTime()
}
return result
}