add isAdmin to user model (#6231)

update vendor and add tests

fix swagger
This commit is contained in:
Lanre Adelowo 2019-03-03 23:57:24 +01:00 committed by techknowlogick
parent 8e202e28ad
commit 141c58f5a6
6 changed files with 28 additions and 2 deletions

4
Gopkg.lock generated
View File

@ -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"

View File

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

View File

@ -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())

View File

@ -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

View File

@ -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",

View File

@ -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