Browse Source

add support for auditing 2FA of org members

This is a BREAKING CHANGE due to the change in the ListMembers method
signature.
Will Norris 12 years ago
parent
commit
eecebdec70
2 changed files with 24 additions and 5 deletions
  1. +18
    -2
      github/orgs_members.go
  2. +6
    -3
      github/orgs_members_test.go

+ 18
- 2
github/orgs_members.go View File

@ -7,18 +7,34 @@ package github
import "fmt" import "fmt"
// ListMembersOptions specifies optional parameters to the
// OrganizationsService.ListMembers method.
type ListMembersOptions struct {
// If true (or if the authenticated user is not an owner of the
// organization), list only publicly visible members.
PublicOnly bool `url:"-"`
// Filter members returned in the list. Possible values are:
// 2fa_disabled, all. Default is "all".
Filter string `url:"filter,omitempty"`
}
// ListMembers lists the members for an organization. If the authenticated // ListMembers lists the members for an organization. If the authenticated
// user is an owner of the organization, this will return both concealed and // user is an owner of the organization, this will return both concealed and
// public members, otherwise it will only return public members. // public members, otherwise it will only return public members.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#members-list // GitHub API docs: http://developer.github.com/v3/orgs/members/#members-list
func (s *OrganizationsService) ListMembers(org string, publicOnly bool) ([]User, *Response, error) {
func (s *OrganizationsService) ListMembers(org string, opt *ListMembersOptions) ([]User, *Response, error) {
var u string var u string
if publicOnly {
if opt != nil && opt.PublicOnly {
u = fmt.Sprintf("orgs/%v/public_members", org) u = fmt.Sprintf("orgs/%v/public_members", org)
} else { } else {
u = fmt.Sprintf("orgs/%v/members", org) u = fmt.Sprintf("orgs/%v/members", org)
} }
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {


+ 6
- 3
github/orgs_members_test.go View File

@ -18,10 +18,12 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"filter": "2fa_disabled"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, _, err := client.Organizations.ListMembers("o", false)
opt := &ListMembersOptions{PublicOnly: false, Filter: "2fa_disabled"}
members, _, err := client.Organizations.ListMembers("o", opt)
if err != nil { if err != nil {
t.Errorf("Organizations.ListMembers returned error: %v", err) t.Errorf("Organizations.ListMembers returned error: %v", err)
} }
@ -33,7 +35,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
} }
func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) { func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) {
_, _, err := client.Organizations.ListMembers("%", false)
_, _, err := client.Organizations.ListMembers("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -46,7 +48,8 @@ func TestOrganizationsService_ListMembers_public(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, _, err := client.Organizations.ListMembers("o", true)
opt := &ListMembersOptions{PublicOnly: true}
members, _, err := client.Organizations.ListMembers("o", opt)
if err != nil { if err != nil {
t.Errorf("Organizations.ListMembers returned error: %v", err) t.Errorf("Organizations.ListMembers returned error: %v", err)
} }


Loading…
Cancel
Save