Skip to content

Commit

Permalink
add isAdmin to user model
Browse files Browse the repository at this point in the history
update vendor and add tests

fix swagger
  • Loading branch information
adelowo committed Mar 3, 2019
1 parent 8e202e2 commit a0e94b7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (u *User) APIFormat() *api.User {
Email: u.getEmail(),
AvatarURL: u.AvatarLink(),
Language: u.Language,
IsAdmin: u.IsAdmin,
}
}

Expand Down
17 changes: 17 additions & 0 deletions models/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions vendor/code.gitea.io/sdk/gitea/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0e94b7

Please sign in to comment.