mirror of
https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
synced 2024-12-22 19:20:45 +00:00
Added User's group actions
This commit is contained in:
parent
ca7b998c76
commit
7ec5c2ee79
35
README.md
35
README.md
@ -15,12 +15,12 @@ A simple Client for Nextcloud's API in Go.
|
||||
- ~~delete~~
|
||||
- ~~enable~~
|
||||
- ~~disable~~
|
||||
- get groups
|
||||
- add to group
|
||||
- remove from group
|
||||
- get subadmin group
|
||||
- promote subadmin
|
||||
- demote subadmin
|
||||
- ~~get groups~~
|
||||
- ~~add to group~~
|
||||
- ~~remove from group~~
|
||||
- ~~get subadmin group~~
|
||||
- ~~promote subadmin~~
|
||||
- ~~demote subadmin~~
|
||||
- ~~send welcome mail~~
|
||||
- [Groups](#groups)
|
||||
- create
|
||||
@ -104,6 +104,29 @@ func (c *Client) UserUpdatePassword(name string, password string) error
|
||||
|
||||
func (c *Client) UserUpdateQuota(name string, quota string) error
|
||||
```
|
||||
Groups
|
||||
```go
|
||||
func (c *Client) UserGroupList(name string) ([]string, error)
|
||||
```
|
||||
```go
|
||||
func (c *Client) UserGroupAdd(name string, group string) error
|
||||
```
|
||||
```go
|
||||
func (c *Client) UserGroupRemove(name string, group string) error
|
||||
```
|
||||
```go
|
||||
func (c *Client) UserGroupPromote(name string, group string) error
|
||||
```
|
||||
```go
|
||||
func (c *Client) UserGroupDemote(name string, group string) error
|
||||
```
|
||||
```go
|
||||
func (c *Client) UserGroupSubAdminList(name string) ([]string, error)
|
||||
```
|
||||
Welcome Mail
|
||||
```go
|
||||
func (c *Client) UserSendWelcomeEmail(name string) error
|
||||
```
|
||||
## Groups
|
||||
TODO
|
||||
|
||||
|
@ -41,6 +41,19 @@ type UserResponse struct {
|
||||
} `json:"ocs"`
|
||||
}
|
||||
|
||||
type SubAdminResponse struct {
|
||||
Ocs struct {
|
||||
Meta struct {
|
||||
Status string `json:"status"`
|
||||
Statuscode int `json:"statuscode"`
|
||||
Message string `json:"message"`
|
||||
Totalitems string `json:"totalitems"`
|
||||
Itemsperpage string `json:"itemsperpage"`
|
||||
} `json:"meta"`
|
||||
Data []string `json:"data"`
|
||||
} `json:"ocs"`
|
||||
}
|
||||
|
||||
type GroupListResponse struct {
|
||||
Ocs struct {
|
||||
Meta struct {
|
||||
|
@ -124,6 +124,78 @@ func (c *Client) UserUpdateQuota(name string, quota string) error {
|
||||
return c.userUpdateAttribute(name, "quota", quota)
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupList(name string) ([]string, error) {
|
||||
if !c.loggedIn() {
|
||||
return nil, unauthorized
|
||||
}
|
||||
u := c.baseURL.ResolveReference(routes.users)
|
||||
u.Path = path.Join(u.Path, name, "groups")
|
||||
res, err := c.session.Get(u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var r types.GroupListResponse
|
||||
res.JSON(&r)
|
||||
if r.Ocs.Meta.Statuscode != 100 {
|
||||
return nil, fmt.Errorf(r.Ocs.Meta.Message)
|
||||
}
|
||||
return r.Ocs.Data.Groups, nil
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupAdd(name string, group string) error {
|
||||
ro := &req.RequestOptions{
|
||||
Data: map[string]string{
|
||||
"groupid": group,
|
||||
},
|
||||
}
|
||||
return c.userBaseRequest(name, "groups", ro, http.MethodPost)
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupRemove(name string, group string) error {
|
||||
ro := &req.RequestOptions{
|
||||
Data: map[string]string{
|
||||
"groupid": group,
|
||||
},
|
||||
}
|
||||
return c.userBaseRequest(name, "groups", ro, http.MethodDelete)
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupPromote(name string, group string) error {
|
||||
ro := &req.RequestOptions{
|
||||
Data: map[string]string{
|
||||
"groupid": group,
|
||||
},
|
||||
}
|
||||
return c.userBaseRequest(name, "subadmins", ro, http.MethodPost)
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupDemote(name string, group string) error {
|
||||
ro := &req.RequestOptions{
|
||||
Data: map[string]string{
|
||||
"groupid": group,
|
||||
},
|
||||
}
|
||||
return c.userBaseRequest(name, "subadmins", ro, http.MethodDelete)
|
||||
}
|
||||
|
||||
func (c *Client) UserGroupSubAdminList(name string) ([]string, error) {
|
||||
if !c.loggedIn() {
|
||||
return nil, unauthorized
|
||||
}
|
||||
u := c.baseURL.ResolveReference(routes.users)
|
||||
u.Path = path.Join(u.Path, name, "subadmins")
|
||||
res, err := c.session.Get(u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var r types.SubAdminResponse
|
||||
res.JSON(&r)
|
||||
if r.Ocs.Meta.Statuscode != 100 {
|
||||
return nil, fmt.Errorf(r.Ocs.Meta.Message)
|
||||
}
|
||||
return r.Ocs.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) userUpdateAttribute(name string, key string, value string) error {
|
||||
ro := &req.RequestOptions{
|
||||
Data: map[string]string{
|
||||
|
Loading…
Reference in New Issue
Block a user