This commit is contained in:
Erik Kristensen 2015-08-03 15:47:30 -06:00
parent 850f46ed82
commit f9c49f4a57

View file

@ -47,12 +47,25 @@ func (b *backend) pathLogin(
// Verify that the user is part of the organization
var org *github.Organization
orgs, _, err := client.Organizations.List("", nil)
if err != nil {
return nil, err
orgOpt := &github.ListOptions{
PerPage: 100,
}
for _, o := range orgs {
var allOrgs []github.Organization
for {
orgs, resp, err := client.Organizations.List("", orgOpt)
if err != nil {
return nil, err
}
allOrgs = append(allOrgs, orgs...)
if resp.NextPage == 0 {
break
}
orgOpt.Page = resp.NextPage
}
for _, o := range allOrgs {
if *o.Login == config.Org {
org = &o
break
@ -64,24 +77,35 @@ func (b *backend) pathLogin(
// Get the teams that this user is part of to determine the policies
var teamNames []string
teams, _, err := client.Organizations.ListUserTeams(nil)
if err != nil {
return nil, err
teamOpt := &github.ListOptions{
PerPage: 100,
}
for _, t := range teams {
var allTeams []github.Team
for {
teams, resp, err := client.Organizations.ListUserTeams(teamOpt)
if err != nil {
return nil, err
}
allTeams = append(allTeams, teams...)
if resp.NextPage == 0 {
break
}
teamOpt.Page = resp.NextPage
}
for _, t := range allTeams {
// We only care about teams that are part of the organization we use
if *t.Organization.ID != *org.ID {
continue
}
// Append the names AND slug so we can get the policies
// Slug is needed for teamnames with whitespaces
// Append the names so we can get the policies
teamNames = append(teamNames, *t.Name)
if *t.Name != *t.Slug {
teamNames = append(teamNames, *t.Slug)
}
}
policiesList, err := b.Map.Policies(req.Storage, teamNames...)
if err != nil {
return nil, err
@ -98,3 +122,5 @@ func (b *backend) pathLogin(
},
}, nil
}