Skip to content

Commit 1226c15

Browse files
authored
For nested teams try extracting the org id from the resource profile (#28)
1 parent 7c1e327 commit 1226c15

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pkg/connector/team.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,25 @@ func (o *teamResourceType) Grant(ctx context.Context, principal *v2.Resource, en
271271
return nil, fmt.Errorf("github-connectorv2: parent resource is required to grant team membership")
272272
}
273273

274-
orgId, err := strconv.ParseInt(entitlement.Resource.ParentResourceId.Resource, 10, 64)
275-
if err != nil {
276-
return nil, err
274+
var orgId int64
275+
if entitlement.Resource.ParentResourceId.ResourceType == resourceTypeOrg.Id {
276+
var err error
277+
orgId, err = strconv.ParseInt(entitlement.Resource.ParentResourceId.Resource, 10, 64)
278+
if err != nil {
279+
return nil, err
280+
}
281+
} else if entitlement.Resource.ParentResourceId.ResourceType == resourceTypeTeam.Id {
282+
groupTrait, err := rType.GetGroupTrait(entitlement.Resource)
283+
if err != nil {
284+
return nil, err
285+
}
286+
287+
orgID, ok := rType.GetProfileInt64Value(groupTrait.Profile, "orgID")
288+
if !ok {
289+
return nil, fmt.Errorf("error fetching orgID from team profile")
290+
}
291+
292+
orgId = orgID
277293
}
278294

279295
userId, err := strconv.ParseInt(principal.Id.Resource, 10, 64)

0 commit comments

Comments
 (0)