Merge pull request #489 from ekristen/github-fix

Fixes GitHub Authentication Bug #488
This commit is contained in:
Armon Dadgar 2015-08-04 10:05:07 -07:00
commit b380090c47

View File

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