2020-02-09 18:01:13 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
// DeleteOrgMembership remove a member from an organization
|
|
|
|
func (c *Client) DeleteOrgMembership(org, user string) error {}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
func TestOrgMembership(t *testing.T) {
|
|
|
|
log.Println("== TestOrgMembership ==")
|
|
|
|
c := newTestClient()
|
|
|
|
|
|
|
|
user := createTestUser(t, "org_mem_user", c)
|
|
|
|
c.SetSudo(user.UserName)
|
2020-09-14 03:37:09 +01:00
|
|
|
newOrg, _, err := c.CreateOrg(CreateOrgOption{Name: "MemberOrg"})
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, newOrg)
|
|
|
|
|
|
|
|
// Check func
|
2020-09-14 03:37:09 +01:00
|
|
|
check, _, err := c.CheckPublicOrgMembership(newOrg.UserName, user.UserName)
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, check)
|
2020-09-14 03:37:09 +01:00
|
|
|
check, _, err = c.CheckOrgMembership(newOrg.UserName, user.UserName)
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, check)
|
|
|
|
|
2022-07-20 03:57:09 +01:00
|
|
|
perm, _, err := c.GetOrgPermissions(newOrg.UserName, user.UserName)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, perm)
|
|
|
|
assert.True(t, perm.IsOwner)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.SetPublicOrgMembership(newOrg.UserName, user.UserName, true)
|
2020-05-27 14:04:51 +01:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
check, _, err = c.CheckPublicOrgMembership(newOrg.UserName, user.UserName)
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, check)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
u, _, err := c.ListOrgMembership(newOrg.UserName, ListOrgMembershipOption{})
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, u, 1)
|
|
|
|
assert.EqualValues(t, user.UserName, u[0].UserName)
|
2020-09-14 03:37:09 +01:00
|
|
|
u, _, err = c.ListPublicOrgMembership(newOrg.UserName, ListOrgMembershipOption{})
|
2020-02-09 18:01:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, u, 1)
|
|
|
|
assert.EqualValues(t, user.UserName, u[0].UserName)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteOrgMembership(newOrg.UserName, user.UserName)
|
|
|
|
assert.Error(t, err)
|
2020-02-09 18:01:13 +00:00
|
|
|
|
|
|
|
c.sudo = ""
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.AdminDeleteUser(user.UserName)
|
|
|
|
assert.Error(t, err)
|
|
|
|
_, err = c.DeleteOrg(newOrg.UserName)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = c.AdminDeleteUser(user.UserName)
|
|
|
|
assert.NoError(t, err)
|
2020-02-09 18:01:13 +00:00
|
|
|
}
|