add isAdmin to user model (#6231)

update vendor and add tests

fix swagger
tokarchuk/v1.17
Lanre Adelowo 6 years ago committed by techknowlogick
parent 8e202e28ad
commit 141c58f5a6
  1. 4
      Gopkg.lock
  2. 1
      models/user.go
  3. 17
      models/user_test.go
  4. 1
      routers/api/v1/user/user.go
  5. 5
      templates/swagger/v1_json.tmpl
  6. 2
      vendor/code.gitea.io/sdk/gitea/user.go

4
Gopkg.lock generated

@ -11,11 +11,11 @@
[[projects]]
branch = "master"
digest = "1:59b2036a2d4b51fc91018adebd33ec4a893aa2b11af3a606445fe8df5640f514"
digest = "1:dbf849e6552740945ac1c6c6acba590fbc594e4efa80cf05568dec8579ae0dab"
name = "code.gitea.io/sdk"
packages = ["gitea"]
pruneopts = "NUT"
revision = "9c4f6485997bcff568e30cfe45165018ac5772c1"
revision = "e4effe4df2b895ca51482d24edb8748704326f1a"
[[projects]]
digest = "1:5d72bbcc9c8667b11c3dc3cbe681c5a6f71e5096744c0bf7726ab5c6425d5dc4"

@ -211,6 +211,7 @@ func (u *User) APIFormat() *api.User {
Email: u.getEmail(),
AvatarURL: u.AvatarLink(),
Language: u.Language,
IsAdmin: u.IsAdmin,
}
}

@ -23,6 +23,23 @@ func TestGetUserEmailsByNames(t *testing.T) {
assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, GetUserEmailsByNames([]string{"user8", "user5"}))
}
func TestUser_APIFormat(t *testing.T) {
user, err := GetUserByID(1)
assert.NoError(t, err)
assert.True(t, user.IsAdmin)
apiUser := user.APIFormat()
assert.True(t, apiUser.IsAdmin)
user, err = GetUserByID(2)
assert.NoError(t, err)
assert.False(t, user.IsAdmin)
apiUser = user.APIFormat()
assert.False(t, apiUser.IsAdmin)
}
func TestCanCreateOrganization(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

@ -75,6 +75,7 @@ func Search(ctx *context.APIContext) {
UserName: users[i].Name,
AvatarURL: users[i].AvatarLink(),
FullName: markup.Sanitize(users[i].FullName),
IsAdmin: users[i].IsAdmin,
}
if ctx.IsSigned && (!users[i].KeepEmailPrivate || ctx.User.IsAdmin) {
results[i].Email = users[i].Email

@ -8640,6 +8640,11 @@
"format": "int64",
"x-go-name": "ID"
},
"is_admin": {
"description": "Is the user an administrator",
"type": "boolean",
"x-go-name": "IsAdmin"
},
"language": {
"description": "User locale",
"type": "string",

@ -24,6 +24,8 @@ type User struct {
AvatarURL string `json:"avatar_url"`
// User locale
Language string `json:"language"`
// Is the user an administrator
IsAdmin bool `json:"is_admin"`
}
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility

Loading…
Cancel
Save