Skip to content

Commit

Permalink
add CreateGroup function to AdministrativeUnitsClient receiver
Browse files Browse the repository at this point in the history
With c.CreateGroup it is now possible to create a group directly into an
AdministrativeUnit. This enables service principals to manage groups
inside an AdministrativeUnit without the need for global directory
permissions.
  • Loading branch information
SwissGipfel committed Jan 12, 2023
1 parent c634a95 commit 81fb89b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions msgraph/administrative_units.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,29 @@ func (c *AdministrativeUnitsClient) GetMember(ctx context.Context, administrativ
return &data.Id, status, nil
}

func (c *AdministrativeUnitsClient) CreateGroup(ctx context.Context, administrativeUnitId string, group *Group) (int, error) {
var status int
odataTypeGroup := odata.TypeGroup
group.ODataType = &odataTypeGroup
body, err := json.Marshal(group)
if err != nil {
return status, fmt.Errorf("json.Marshal(): %v", err)
}
_, status, _, err = c.BaseClient.Post(ctx, PostHttpRequestInput{
Body: body,
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
ValidStatusCodes: []int{http.StatusCreated},
Uri: Uri{
Entity: fmt.Sprintf("/administrativeUnits/%s/members", administrativeUnitId),
HasTenantId: true,
},
})
if err != nil {
return status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Post(): %v", err)
}
return status, nil
}

// AddMembers adds new members to a AdministrativeUnit.
func (c *AdministrativeUnitsClient) AddMembers(ctx context.Context, administrativeUnitId string, members *Members) (int, error) {
var status int
Expand Down

0 comments on commit 81fb89b

Please sign in to comment.