]> source.dussan.org Git - gitea.git/commitdiff
Hide some user information via API if user have no enough permission (#8655) (#8657)
authorLunny Xiao <xiaolunwen@gmail.com>
Thu, 24 Oct 2019 05:59:53 +0000 (13:59 +0800)
committerLauris BH <lauris@nix.lv>
Thu, 24 Oct 2019 05:59:53 +0000 (08:59 +0300)
* Hide some user information via API if user have no enough permission

* fix test

integrations/api_team_user_test.go
routers/api/v1/convert/convert.go

index 70d52c13601d663292d58e2f26d13514f34d76cf..4df4dac016ad64ee070f0f7d8c4ed15f8e1b18a4 100644 (file)
@@ -29,7 +29,6 @@ func TestAPITeamUser(t *testing.T) {
        var user2 *api.User
        DecodeJSON(t, resp, &user2)
        user2.Created = user2.Created.In(time.Local)
-       user2.LastLogin = user2.LastLogin.In(time.Local)
        user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
 
        assert.Equal(t, convert.ToUser(user, true, false), user2)
index e0e7f609c7417ceb89f9d3d810edf999f520f1b4..724086dc6cd1904bbbaef298cf84f7f3a405deaf 100644 (file)
@@ -232,12 +232,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
@@ -245,8 +242,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
 }