feat(orgs): add public member endpoints
Some checks failed
Security Scan / security (push) Successful in 14s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:06:57 +00:00
parent d1c690ef3c
commit 02382d137d
2 changed files with 124 additions and 0 deletions

37
orgs.go
View file

@ -90,6 +90,43 @@ func (s *OrgService) IsBlocked(ctx context.Context, org, username string) (bool,
return resp.StatusCode == http.StatusNoContent, nil
}
// ListPublicMembers returns all public members of an organisation.
func (s *OrgService) ListPublicMembers(ctx context.Context, org string) ([]types.User, error) {
path := ResolvePath("/api/v1/orgs/{org}/public_members", pathParams("org", org))
return ListAll[types.User](ctx, s.client, path, nil)
}
// IterPublicMembers returns an iterator over all public members of an organisation.
func (s *OrgService) IterPublicMembers(ctx context.Context, org string) iter.Seq2[types.User, error] {
path := ResolvePath("/api/v1/orgs/{org}/public_members", pathParams("org", org))
return ListIter[types.User](ctx, s.client, path, nil)
}
// IsPublicMember reports whether a user is a public member of an organisation.
func (s *OrgService) IsPublicMember(ctx context.Context, org, username string) (bool, error) {
path := ResolvePath("/api/v1/orgs/{org}/public_members/{username}", pathParams("org", org, "username", username))
resp, err := s.client.doJSON(ctx, "GET", path, nil, nil)
if err != nil {
if IsNotFound(err) {
return false, nil
}
return false, err
}
return resp.StatusCode == http.StatusNoContent, nil
}
// PublicizeMember makes a user's membership public within an organisation.
func (s *OrgService) PublicizeMember(ctx context.Context, org, username string) error {
path := ResolvePath("/api/v1/orgs/{org}/public_members/{username}", pathParams("org", org, "username", username))
return s.client.Put(ctx, path, nil, nil)
}
// ConcealMember hides a user's public membership within an organisation.
func (s *OrgService) ConcealMember(ctx context.Context, org, username string) error {
path := ResolvePath("/api/v1/orgs/{org}/public_members/{username}", pathParams("org", org, "username", username))
return s.client.Delete(ctx, path)
}
// Block blocks a user within an organisation.
func (s *OrgService) Block(ctx context.Context, org, username string) error {
path := ResolvePath("/api/v1/orgs/{org}/blocks/{username}", pathParams("org", org, "username", username))

View file

@ -88,6 +88,35 @@ func TestOrgService_ListMembers_Good(t *testing.T) {
}
}
func TestOrgService_ListPublicMembers_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/orgs/core/public_members" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.Header().Set("X-Total-Count", "2")
json.NewEncoder(w).Encode([]types.User{
{ID: 1, UserName: "alice"},
{ID: 2, UserName: "bob"},
})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
members, err := f.Orgs.ListPublicMembers(context.Background(), "core")
if err != nil {
t.Fatal(err)
}
if len(members) != 2 {
t.Errorf("got %d members, want 2", len(members))
}
if members[0].UserName != "alice" {
t.Errorf("got username=%q, want %q", members[0].UserName, "alice")
}
}
func TestOrgService_ListBlockedUsers_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
@ -117,6 +146,42 @@ func TestOrgService_ListBlockedUsers_Good(t *testing.T) {
}
}
func TestOrgService_PublicizeMember_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut {
t.Errorf("expected PUT, got %s", r.Method)
}
if r.URL.Path != "/api/v1/orgs/core/public_members/alice" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Orgs.PublicizeMember(context.Background(), "core", "alice"); err != nil {
t.Fatal(err)
}
}
func TestOrgService_ConcealMember_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
t.Errorf("expected DELETE, got %s", r.Method)
}
if r.URL.Path != "/api/v1/orgs/core/public_members/alice" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Orgs.ConcealMember(context.Background(), "core", "alice"); err != nil {
t.Fatal(err)
}
}
func TestOrgService_Block_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut {
@ -240,3 +305,25 @@ func TestOrgService_IsBlocked_Good(t *testing.T) {
t.Fatal("got blocked=false, want true")
}
}
func TestOrgService_IsPublicMember_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/orgs/core/public_members/alice" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
public, err := f.Orgs.IsPublicMember(context.Background(), "core", "alice")
if err != nil {
t.Fatal(err)
}
if !public {
t.Fatal("got public=false, want true")
}
}