feat(orgs): add organisation membership check
Some checks failed
Security Scan / security (push) Successful in 13s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:12:48 +00:00
parent 9f263a77ec
commit 204696915f
2 changed files with 35 additions and 0 deletions

13
orgs.go
View file

@ -65,6 +65,19 @@ func (s *OrgService) RemoveMember(ctx context.Context, org, username string) err
return s.client.Delete(ctx, path)
}
// IsMember reports whether a user is a member of an organisation.
func (s *OrgService) IsMember(ctx context.Context, org, username string) (bool, error) {
path := ResolvePath("/api/v1/orgs/{org}/members/{username}", pathParams("org", org, "username", username))
resp, err := s.client.doJSON(ctx, http.MethodGet, path, nil, nil)
if err != nil {
if IsNotFound(err) {
return false, nil
}
return false, err
}
return resp.StatusCode == http.StatusNoContent, nil
}
// ListBlockedUsers returns all users blocked by an organisation.
func (s *OrgService) ListBlockedUsers(ctx context.Context, org string) ([]types.User, error) {
path := ResolvePath("/api/v1/orgs/{org}/blocks", pathParams("org", org))

View file

@ -88,6 +88,28 @@ func TestOrgService_ListMembers_Good(t *testing.T) {
}
}
func TestOrgService_IsMember_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/members/alice" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
member, err := f.Orgs.IsMember(context.Background(), "core", "alice")
if err != nil {
t.Fatal(err)
}
if !member {
t.Fatal("got member=false, want true")
}
}
func TestOrgService_ListPublicMembers_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {