Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isAdmin to user API response #6231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.