Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 78721a4

Browse files
ngourdonlafriks
authored andcommitted
Adds missing methods in the admin user API (#173)
* add AdminListUsers to list all users * add AdminDeleteUserPublicKey
1 parent 82f69ae commit 78721a4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gitea/admin_user.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
"code.gitea.io/gitea/modules/structs"
1414
)
1515

16+
// AdminListUsers lists all users
17+
func (c *Client) AdminListUsers() ([]*User, error) {
18+
users := make([]*User, 0, 10)
19+
return users, c.getParsedResponse("GET", "/admin/users", nil, nil, &users)
20+
}
21+
1622
// AdminCreateUser create a user
1723
func (c *Client) AdminCreateUser(opt structs.CreateUserOption) (*User, error) {
1824
body, err := json.Marshal(&opt)
@@ -39,7 +45,7 @@ func (c *Client) AdminDeleteUser(user string) error {
3945
return err
4046
}
4147

42-
// AdminCreateUserPublicKey create one user with options
48+
// AdminCreateUserPublicKey adds a public key for the user
4349
func (c *Client) AdminCreateUserPublicKey(user string, opt structs.CreateKeyOption) (*PublicKey, error) {
4450
body, err := json.Marshal(&opt)
4551
if err != nil {
@@ -48,3 +54,9 @@ func (c *Client) AdminCreateUserPublicKey(user string, opt structs.CreateKeyOpti
4854
key := new(PublicKey)
4955
return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
5056
}
57+
58+
// AdminDeleteUserPublicKey deletes a user's public key
59+
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) error {
60+
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
61+
return err
62+
}

0 commit comments

Comments
 (0)