diff --git a/src/internal/m365/collection/site/collection.go b/src/internal/m365/collection/site/collection.go index c0bceafea..95d77acb2 100644 --- a/src/internal/m365/collection/site/collection.go +++ b/src/internal/m365/collection/site/collection.go @@ -290,7 +290,7 @@ func (sc *Collection) retrievePages( return metrics, clues.New("beta service required").WithClues(ctx) } - parent, err := as.GetByID(ctx, sc.fullPath.ProtectedResource()) + parent, err := as.GetByID(ctx, sc.fullPath.ProtectedResource(), api.CallConfig{}) if err != nil { return metrics, err } diff --git a/src/internal/m365/controller.go b/src/internal/m365/controller.go index e9e8b2228..0bd15ee17 100644 --- a/src/internal/m365/controller.go +++ b/src/internal/m365/controller.go @@ -205,7 +205,11 @@ type resourceClient struct { } type getIDAndNamer interface { - GetIDAndName(ctx context.Context, owner string) ( + GetIDAndName( + ctx context.Context, + owner string, + cc api.CallConfig, + ) ( ownerID string, ownerName string, err error, @@ -254,7 +258,7 @@ func (r resourceClient) getOwnerIDAndNameFrom( err error ) - id, name, err = r.getter.GetIDAndName(ctx, owner) + id, name, err = r.getter.GetIDAndName(ctx, owner, api.CallConfig{}) if err != nil { if graph.IsErrUserNotFound(err) { return "", "", clues.Stack(graph.ErrResourceOwnerNotFound, err) diff --git a/src/internal/m365/mock/id_name_getter.go b/src/internal/m365/mock/id_name_getter.go index 443f84d8f..5be96a5b6 100644 --- a/src/internal/m365/mock/id_name_getter.go +++ b/src/internal/m365/mock/id_name_getter.go @@ -1,6 +1,10 @@ package mock -import "context" +import ( + "context" + + "github.com/alcionai/corso/src/pkg/services/m365/api" +) type IDNameGetter struct { ID, Name string @@ -10,6 +14,7 @@ type IDNameGetter struct { func (ing IDNameGetter) GetIDAndName( _ context.Context, _ string, + _ api.CallConfig, ) (string, string, error) { return ing.ID, ing.Name, ing.Err } diff --git a/src/pkg/services/m365/api/client.go b/src/pkg/services/m365/api/client.go index c74bf215b..64b00f3dd 100644 --- a/src/pkg/services/m365/api/client.go +++ b/src/pkg/services/m365/api/client.go @@ -118,3 +118,11 @@ func (c Client) Get( ) (*http.Response, error) { return c.Requester.Request(ctx, http.MethodGet, url, nil, headers) } + +// --------------------------------------------------------------------------- +// per-call config +// --------------------------------------------------------------------------- + +type CallConfig struct { + Expand []string +} diff --git a/src/pkg/services/m365/api/groups.go b/src/pkg/services/m365/api/groups.go index e69876233..73beb3d2b 100644 --- a/src/pkg/services/m365/api/groups.go +++ b/src/pkg/services/m365/api/groups.go @@ -231,7 +231,11 @@ func IsTeam(ctx context.Context, mg models.Groupable) bool { // GetIDAndName looks up the group matching the given ID, and returns // its canonical ID and the name. -func (c Groups) GetIDAndName(ctx context.Context, groupID string) (string, string, error) { +func (c Groups) GetIDAndName( + ctx context.Context, + groupID string, + _ CallConfig, // not currently supported +) (string, string, error) { s, err := c.GetByID(ctx, groupID) if err != nil { return "", "", err diff --git a/src/pkg/services/m365/api/sites.go b/src/pkg/services/m365/api/sites.go index 303d97344..2ad3751f1 100644 --- a/src/pkg/services/m365/api/sites.go +++ b/src/pkg/services/m365/api/sites.go @@ -111,12 +111,16 @@ var uuidRE = regexp.MustCompile(uuidRETmpl) // deadbeef-0000-0000-0000-000000000000,beefdead-0000-0000-0000-000000000000 var siteIDRE = regexp.MustCompile(`(.+,)?` + uuidRETmpl + "," + uuidRETmpl) -const sitesWebURLGetTemplate = "https://graph.microsoft.com/v1.0/sites/%s:/%s?$expand=drive" +const sitesWebURLGetTemplate = "https://graph.microsoft.com/v1.0/sites/%s:/%s%s" // GetByID looks up the site matching the given identifier. The identifier can be either a // canonical site id or a webURL. Assumes the webURL is complete and well formed; // eg: https://10rqc2.sharepoint.com/sites/Example -func (c Sites) GetByID(ctx context.Context, identifier string) (models.Siteable, error) { +func (c Sites) GetByID( + ctx context.Context, + identifier string, + cc CallConfig, +) (models.Siteable, error) { var ( resp models.Siteable err error @@ -126,9 +130,11 @@ func (c Sites) GetByID(ctx context.Context, identifier string) (models.Siteable, if siteIDRE.MatchString(identifier) { options := &sites.SiteItemRequestBuilderGetRequestConfiguration{ - QueryParameters: &sites.SiteItemRequestBuilderGetQueryParameters{ - Expand: []string{"drive"}, - }, + QueryParameters: &sites.SiteItemRequestBuilderGetQueryParameters{}, + } + + if len(cc.Expand) > 0 { + options.QueryParameters.Expand = cc.Expand } resp, err = c.Stable. @@ -167,7 +173,13 @@ func (c Sites) GetByID(ctx context.Context, identifier string) (models.Siteable, // don't construct a path with double leading slashes path := strings.TrimPrefix(u.Path, "/") - rawURL := fmt.Sprintf(sitesWebURLGetTemplate, u.Host, path) + + qp := "" + if len(cc.Expand) > 0 { + qp = "?expand=" + strings.Join(cc.Expand, ",") + } + + rawURL := fmt.Sprintf(sitesWebURLGetTemplate, u.Host, path, qp) resp, err = sites. NewItemSitesSiteItemRequestBuilder(rawURL, c.Stable.Adapter()). @@ -190,8 +202,12 @@ func (c Sites) GetByID(ctx context.Context, identifier string) (models.Siteable, // GetIDAndName looks up the site matching the given ID, and returns // its canonical ID and the webURL as the name. Accepts an ID or a // WebURL as an ID. -func (c Sites) GetIDAndName(ctx context.Context, siteID string) (string, string, error) { - s, err := c.GetByID(ctx, siteID) +func (c Sites) GetIDAndName( + ctx context.Context, + siteID string, + cc CallConfig, +) (string, string, error) { + s, err := c.GetByID(ctx, siteID, cc) if err != nil { return "", "", err } diff --git a/src/pkg/services/m365/api/sites_test.go b/src/pkg/services/m365/api/sites_test.go index 969a1eec8..64b0387f6 100644 --- a/src/pkg/services/m365/api/sites_test.go +++ b/src/pkg/services/m365/api/sites_test.go @@ -232,7 +232,11 @@ func (suite *SitesIntgSuite) TestSites_GetByID() { ctx, flush := tester.NewContext(t) defer flush() - site, err := sitesAPI.GetByID(ctx, test.id) + cc := api.CallConfig{ + Expand: []string{"drive"}, + } + + site, err := sitesAPI.GetByID(ctx, test.id, cc) expectedErr := test.expectErr(t, err) if expectedErr { diff --git a/src/pkg/services/m365/api/users.go b/src/pkg/services/m365/api/users.go index a3cff2dfc..15c3a46da 100644 --- a/src/pkg/services/m365/api/users.go +++ b/src/pkg/services/m365/api/users.go @@ -131,7 +131,11 @@ func (c Users) GetByID(ctx context.Context, identifier string) (models.Userable, // GetIDAndName looks up the user matching the given ID, and returns // its canonical ID and the PrincipalName as the name. -func (c Users) GetIDAndName(ctx context.Context, userID string) (string, string, error) { +func (c Users) GetIDAndName( + ctx context.Context, + userID string, + _ CallConfig, // not currently supported +) (string, string, error) { u, err := c.GetByID(ctx, userID) if err != nil { return "", "", err diff --git a/src/pkg/services/m365/sites.go b/src/pkg/services/m365/sites.go index 7f849c818..439f53616 100644 --- a/src/pkg/services/m365/sites.go +++ b/src/pkg/services/m365/sites.go @@ -14,6 +14,7 @@ import ( "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" + "github.com/alcionai/corso/src/pkg/services/m365/api" ) type SiteOwnerType string @@ -58,7 +59,11 @@ func SiteByID( return nil, clues.Stack(err).WithClues(ctx) } - s, err := ac.Sites().GetByID(ctx, id) + cc := api.CallConfig{ + Expand: []string{"drive"}, + } + + s, err := ac.Sites().GetByID(ctx, id, cc) if err != nil { return nil, clues.Stack(err) }