2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
2018-07-09 10:53:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
req "github.com/levigross/grequests"
|
2018-07-25 13:06:31 +00:00
|
|
|
"github.com/partitio/gonextcloud/types"
|
2018-07-09 10:53:53 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupList lists the Nextcloud groups
|
2018-07-09 10:53:53 +00:00
|
|
|
func (c *Client) GroupList() ([]string, error) {
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.groups, nil)
|
2018-07-09 10:53:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-24 18:26:12 +00:00
|
|
|
var r types.GroupListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Groups, nil
|
2018-07-09 10:53:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupUsers list the group's users
|
2018-07-09 11:36:07 +00:00
|
|
|
func (c *Client) GroupUsers(name string) ([]string, error) {
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.groups, nil, name)
|
2018-07-09 10:53:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.UserListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Users, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupSearch return the list of groups matching the search string
|
2018-07-09 11:36:07 +00:00
|
|
|
func (c *Client) GroupSearch(search string) ([]string, error) {
|
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Params: map[string]string{"search": search},
|
|
|
|
}
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.groups, ro)
|
2018-07-09 11:36:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.GroupListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Groups, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupCreate creates a group
|
2018-07-09 10:53:53 +00:00
|
|
|
func (c *Client) GroupCreate(name string) error {
|
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Data: map[string]string{
|
|
|
|
"groupid": name,
|
|
|
|
},
|
|
|
|
}
|
2018-09-03 10:17:02 +00:00
|
|
|
return c.groupBaseRequest(http.MethodPost, ro)
|
2018-07-09 10:53:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupDelete deletes the group
|
2018-07-09 10:53:53 +00:00
|
|
|
func (c *Client) GroupDelete(name string) error {
|
2018-09-03 10:17:02 +00:00
|
|
|
return c.groupBaseRequest(http.MethodDelete, nil, name)
|
2018-07-09 10:53:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//GroupSubAdminList lists the group's subadmins
|
2018-07-09 10:53:53 +00:00
|
|
|
func (c *Client) GroupSubAdminList(name string) ([]string, error) {
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.groups, nil, name, "subadmins")
|
2018-07-09 10:53:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.UserListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Users, nil
|
|
|
|
}
|
|
|
|
|
2018-09-03 10:17:02 +00:00
|
|
|
func (c *Client) groupBaseRequest(method string, ro *req.RequestOptions, subRoute ...string) error {
|
|
|
|
_, err := c.baseRequest(method, routes.groups, ro, subRoute...)
|
2018-07-25 13:06:31 +00:00
|
|
|
return err
|
2018-07-09 10:53:53 +00:00
|
|
|
}
|