Adds missing methods in the admin user API (#173)

* add AdminListUsers to list all users

* add AdminDeleteUserPublicKey
This commit is contained in:
ngourdon 2019-06-02 13:00:23 +02:00 committed by Lauris BH
parent 82f69ae35a
commit 78721a4220

View file

@ -13,6 +13,12 @@ import (
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
) )
// AdminListUsers lists all users
func (c *Client) AdminListUsers() ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", "/admin/users", nil, nil, &users)
}
// AdminCreateUser create a user // AdminCreateUser create a user
func (c *Client) AdminCreateUser(opt structs.CreateUserOption) (*User, error) { func (c *Client) AdminCreateUser(opt structs.CreateUserOption) (*User, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
@ -39,7 +45,7 @@ func (c *Client) AdminDeleteUser(user string) error {
return err return err
} }
// AdminCreateUserPublicKey create one user with options // AdminCreateUserPublicKey adds a public key for the user
func (c *Client) AdminCreateUserPublicKey(user string, opt structs.CreateKeyOption) (*PublicKey, error) { func (c *Client) AdminCreateUserPublicKey(user string, opt structs.CreateKeyOption) (*PublicKey, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
if err != nil { if err != nil {
@ -48,3 +54,9 @@ func (c *Client) AdminCreateUserPublicKey(user string, opt structs.CreateKeyOpti
key := new(PublicKey) key := new(PublicKey)
return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key) return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
} }
// AdminDeleteUserPublicKey deletes a user's public key
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
return err
}