Add method to get user organization permissions (#594)
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/594 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: lafriks <lafriks@noreply.gitea.io> Co-committed-by: lafriks <lafriks@noreply.gitea.io>
This commit is contained in:
parent
e5f0c189f2
commit
de34275bb6
2 changed files with 28 additions and 0 deletions
|
@ -117,3 +117,26 @@ func (c *Client) SetPublicOrgMembership(org, user string, visible bool) (*Respon
|
||||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrgPermissions represents the permissions for an user in an organization
|
||||||
|
type OrgPermissions struct {
|
||||||
|
CanCreateRepository bool `json:"can_create_repository"`
|
||||||
|
CanRead bool `json:"can_read"`
|
||||||
|
CanWrite bool `json:"can_write"`
|
||||||
|
IsAdmin bool `json:"is_admin"`
|
||||||
|
IsOwner bool `json:"is_owner"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrgPermissions returns user permissions for specific organization.
|
||||||
|
func (c *Client) GetOrgPermissions(org, user string) (*OrgPermissions, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org, &user); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
perm := &OrgPermissions{}
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs/%s/permissions", user, org), jsonHeader, nil, &perm)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return perm, resp, nil
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,11 @@ func TestOrgMembership(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, check)
|
assert.True(t, check)
|
||||||
|
|
||||||
|
perm, _, err := c.GetOrgPermissions(newOrg.UserName, user.UserName)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, perm)
|
||||||
|
assert.True(t, perm.IsOwner)
|
||||||
|
|
||||||
_, err = c.SetPublicOrgMembership(newOrg.UserName, user.UserName, true)
|
_, err = c.SetPublicOrgMembership(newOrg.UserName, user.UserName, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
check, _, err = c.CheckPublicOrgMembership(newOrg.UserName, user.UserName)
|
check, _, err = c.CheckPublicOrgMembership(newOrg.UserName, user.UserName)
|
||||||
|
|
Loading…
Reference in a new issue