diff --git a/src/internal/connector/exchange/api/api.go b/src/internal/connector/exchange/api/api.go index 1b4ebe2b4..0d05e25b0 100644 --- a/src/internal/connector/exchange/api/api.go +++ b/src/internal/connector/exchange/api/api.go @@ -135,8 +135,11 @@ func checkIDAndName(c graph.Container) error { } func HasAttachments(body models.ItemBodyable) bool { - if body.GetContent() == nil || body.GetContentType() == nil || - *body.GetContentType() == models.TEXT_BODYTYPE || len(*body.GetContent()) == 0 { + if ct, ok := ptr.ValOK(body.GetContentType()); !ok || ct == models.TEXT_BODYTYPE { + return false + } + + if body, ok := ptr.ValOK(body.GetContent()); !ok || len(body) == 0 { return false } diff --git a/src/internal/connector/exchange/api/events.go b/src/internal/connector/exchange/api/events.go index 49dd66041..e8ce617ce 100644 --- a/src/internal/connector/exchange/api/events.go +++ b/src/internal/connector/exchange/api/events.go @@ -108,7 +108,7 @@ func (c Events) GetItem( return nil, nil, graph.Stack(ctx, err) } - if *event.GetHasAttachments() || HasAttachments(event.GetBody()) { + if ptr.Val(event.GetHasAttachments()) || HasAttachments(event.GetBody()) { options := &users.ItemEventsItemAttachmentsRequestBuilderGetRequestConfiguration{ QueryParameters: &users.ItemEventsItemAttachmentsRequestBuilderGetQueryParameters{ Expand: []string{"microsoft.graph.itemattachment/item"}, diff --git a/src/internal/connector/exchange/api/mail.go b/src/internal/connector/exchange/api/mail.go index b03fff837..0ac23ce41 100644 --- a/src/internal/connector/exchange/api/mail.go +++ b/src/internal/connector/exchange/api/mail.go @@ -131,7 +131,7 @@ func (c Mail) GetItem( return nil, nil, graph.Stack(ctx, err) } - if *mail.GetHasAttachments() || HasAttachments(mail.GetBody()) { + if ptr.Val(mail.GetHasAttachments()) || HasAttachments(mail.GetBody()) { options := &users.ItemMessagesItemAttachmentsRequestBuilderGetRequestConfiguration{ QueryParameters: &users.ItemMessagesItemAttachmentsRequestBuilderGetQueryParameters{ Expand: []string{"microsoft.graph.itemattachment/item"}, diff --git a/src/internal/connector/exchange/attachment.go b/src/internal/connector/exchange/attachment.go index 9a293c7a0..38501fe72 100644 --- a/src/internal/connector/exchange/attachment.go +++ b/src/internal/connector/exchange/attachment.go @@ -126,6 +126,9 @@ func getItemAttachmentItemType(query models.Attachmentable) string { } item := attachment.GetItem() + if item == nil { + return empty + } return ptr.Val(item.GetOdataType()) } diff --git a/src/internal/connector/exchange/container_resolver.go b/src/internal/connector/exchange/container_resolver.go index 93c0a156d..7adf84a4a 100644 --- a/src/internal/connector/exchange/container_resolver.go +++ b/src/internal/connector/exchange/container_resolver.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/pkg/errors" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" @@ -81,14 +82,18 @@ func (cr *containerResolver) idToPath( return p, c.Location(), nil } - parentPath, parentLoc, err := cr.idToPath(ctx, *c.GetParentFolderId(), depth+1, useIDInPath) + parentPath, parentLoc, err := cr.idToPath( + ctx, + ptr.Val(c.GetParentFolderId()), + depth+1, + useIDInPath) if err != nil { return nil, nil, errors.Wrap(err, "retrieving parent folder") } - toAppend := *c.GetDisplayName() + toAppend := ptr.Val(c.GetDisplayName()) if useIDInPath { - toAppend = *c.GetId() + toAppend = ptr.Val(c.GetId()) } fullPath := parentPath.Append(toAppend) @@ -97,7 +102,7 @@ func (cr *containerResolver) idToPath( var locPath *path.Builder if parentLoc != nil { - locPath = parentLoc.Append(*c.GetDisplayName()) + locPath = parentLoc.Append(ptr.Val(c.GetDisplayName())) c.SetLocation(locPath) } @@ -118,7 +123,7 @@ func (cr *containerResolver) PathInCache(pathString string) (string, bool) { } if cc.Path().String() == pathString { - return *cc.GetId(), true + return ptr.Val(cc.GetId()), true } } @@ -139,11 +144,11 @@ func (cr *containerResolver) addFolder(cf graph.CacheFolder) error { } } - if _, ok := cr.cache[*cf.GetId()]; ok { + if _, ok := cr.cache[ptr.Val(cf.GetId())]; ok { return nil } - cr.cache[*cf.GetId()] = &cf + cr.cache[ptr.Val(cf.GetId())] = &cf return nil } @@ -174,7 +179,7 @@ func (cr *containerResolver) AddToCache( // Populate the path for this entry so calls to PathInCache succeed no matter // when they're made. - _, _, err := cr.IDToPath(ctx, *f.GetId(), useIDInPath) + _, _, err := cr.IDToPath(ctx, ptr.Val(f.GetId()), useIDInPath) if err != nil { return errors.Wrap(err, "adding cache entry") } @@ -193,7 +198,7 @@ func (cr *containerResolver) populatePaths(ctx context.Context, useIDInPath bool // Populate all folder paths. for _, f := range cr.Items() { - _, _, err := cr.IDToPath(ctx, *f.GetId(), useIDInPath) + _, _, err := cr.IDToPath(ctx, ptr.Val(f.GetId()), useIDInPath) if err != nil { errs = multierror.Append(errs, errors.Wrap(err, "populating path")) } diff --git a/src/internal/connector/exchange/container_resolver_test.go b/src/internal/connector/exchange/container_resolver_test.go index cc88296e4..04e82c087 100644 --- a/src/internal/connector/exchange/container_resolver_test.go +++ b/src/internal/connector/exchange/container_resolver_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" @@ -387,7 +388,7 @@ func (suite *ConfiguredFolderCacheUnitSuite) TestLookupCachedFolderNoPathsCached defer flush() for _, c := range suite.allContainers { - suite.Run(*c.GetDisplayName(), func() { + suite.Run(ptr.Val(c.GetDisplayName()), func() { t := suite.T() p, l, err := suite.fc.IDToPath(ctx, c.id, false) @@ -403,7 +404,7 @@ func (suite *ConfiguredFolderCacheUnitSuite) TestLookupCachedFolderNoPathsCached defer flush() for _, c := range suite.containersWithID { - suite.Run(*c.GetDisplayName(), func() { + suite.Run(ptr.Val(c.GetDisplayName()), func() { t := suite.T() p, l, err := suite.fcWithID.IDToPath(ctx, c.id, true) diff --git a/src/internal/connector/exchange/data_collections_test.go b/src/internal/connector/exchange/data_collections_test.go index d6ee2d36e..c03232796 100644 --- a/src/internal/connector/exchange/data_collections_test.go +++ b/src/internal/connector/exchange/data_collections_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" @@ -553,12 +554,12 @@ func (suite *DataCollectionsIntegrationSuite) TestEventsSerializationRegression( ) fn := func(gcf graph.CacheFolder) error { - if *gcf.GetDisplayName() == DefaultCalendar { - calID = *gcf.GetId() + if ptr.Val(gcf.GetDisplayName()) == DefaultCalendar { + calID = ptr.Val(gcf.GetId()) } - if *gcf.GetDisplayName() == "Birthdays" { - bdayID = *gcf.GetId() + if ptr.Val(gcf.GetDisplayName()) == "Birthdays" { + bdayID = ptr.Val(gcf.GetId()) } return nil diff --git a/src/internal/connector/exchange/event_calendar_cache.go b/src/internal/connector/exchange/event_calendar_cache.go index 236406755..72d9a93f9 100644 --- a/src/internal/connector/exchange/event_calendar_cache.go +++ b/src/internal/connector/exchange/event_calendar_cache.go @@ -6,6 +6,7 @@ import ( "github.com/alcionai/clues" "github.com/pkg/errors" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" @@ -48,8 +49,8 @@ func (ecc *eventCalendarCache) populateEventRoot(ctx context.Context) error { temp := graph.NewCacheFolder( f, - path.Builder{}.Append(*f.GetId()), // storage path - path.Builder{}.Append(*f.GetDisplayName())) // display location + path.Builder{}.Append(ptr.Val(f.GetId())), // storage path + path.Builder{}.Append(ptr.Val(f.GetDisplayName()))) // display location if err := ecc.addFolder(temp); err != nil { return clues.Wrap(err, "initializing calendar resolver").WithClues(ctx) } @@ -96,25 +97,25 @@ func (ecc *eventCalendarCache) AddToCache(ctx context.Context, f graph.Container temp := graph.NewCacheFolder( f, - path.Builder{}.Append(*f.GetId()), // storage path - path.Builder{}.Append(*f.GetDisplayName())) // display location + path.Builder{}.Append(ptr.Val(f.GetId())), // storage path + path.Builder{}.Append(ptr.Val(f.GetDisplayName()))) // display location if len(ecc.newAdditions) == 0 { ecc.newAdditions = map[string]string{} } - ecc.newAdditions[*f.GetDisplayName()] = *f.GetId() + ecc.newAdditions[ptr.Val(f.GetDisplayName())] = ptr.Val(f.GetId()) if err := ecc.addFolder(temp); err != nil { - delete(ecc.newAdditions, *f.GetDisplayName()) + delete(ecc.newAdditions, ptr.Val(f.GetDisplayName())) return clues.Wrap(err, "adding container").WithClues(ctx) } // Populate the path for this entry so calls to PathInCache succeed no matter // when they're made. - _, _, err := ecc.IDToPath(ctx, *f.GetId(), true) + _, _, err := ecc.IDToPath(ctx, ptr.Val(f.GetId()), true) if err != nil { - delete(ecc.newAdditions, *f.GetDisplayName()) + delete(ecc.newAdditions, ptr.Val(f.GetDisplayName())) return errors.Wrap(err, "setting path to container id") } diff --git a/src/internal/connector/exchange/folder_resolver_test.go b/src/internal/connector/exchange/folder_resolver_test.go index c65b1d545..8b704c79d 100644 --- a/src/internal/connector/exchange/folder_resolver_test.go +++ b/src/internal/connector/exchange/folder_resolver_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/tester" @@ -72,7 +73,7 @@ func (suite *CacheResolverSuite) TestPopulate() { }{ { name: "Default Event Cache", - folderInCache: *cal.GetId(), + folderInCache: ptr.Val(cal.GetId()), root: DefaultCalendar, basePath: DefaultCalendar, resolverFunc: eventFunc, diff --git a/src/internal/connector/exchange/restore_test.go b/src/internal/connector/exchange/restore_test.go index 0591bb870..45c9c9bc3 100644 --- a/src/internal/connector/exchange/restore_test.go +++ b/src/internal/connector/exchange/restore_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/mockconnector" @@ -73,7 +74,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreContact() { aFolder, err := suite.ac.Contacts().CreateContactFolder(ctx, userID, folderName) require.NoError(t, err) - folderID := *aFolder.GetId() + folderID := ptr.Val(aFolder.GetId()) defer func() { // Remove the folder containing contact prior to exiting test @@ -107,7 +108,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreEvent() { calendar, err := suite.ac.Events().CreateCalendar(ctx, userID, name) require.NoError(t, err) - calendarID := *calendar.GetId() + calendarID := ptr.Val(calendar.GetId()) defer func() { // Removes calendar containing events created during the test @@ -163,7 +164,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -175,7 +176,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -187,7 +188,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -199,7 +200,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -214,7 +215,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -229,7 +230,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -244,7 +245,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { // Restore will upload the Message without uploading the attachment @@ -256,7 +257,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -268,7 +269,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -280,7 +281,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -292,7 +293,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, // TODO: #884 - reinstate when able to specify root folder by name @@ -305,7 +306,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { folder, err := suite.ac.Contacts().CreateContactFolder(ctx, userID, folderName) require.NoError(t, err) - return *folder.GetId() + return ptr.Val(folder.GetId()) }, }, { @@ -317,7 +318,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { calendar, err := suite.ac.Events().CreateCalendar(ctx, userID, calendarName) require.NoError(t, err) - return *calendar.GetId() + return ptr.Val(calendar.GetId()) }, }, { @@ -329,7 +330,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { calendar, err := suite.ac.Events().CreateCalendar(ctx, userID, calendarName) require.NoError(t, err) - return *calendar.GetId() + return ptr.Val(calendar.GetId()) }, }, } diff --git a/src/internal/connector/exchange/service_functions.go b/src/internal/connector/exchange/service_functions.go index 07467a59e..d976607af 100644 --- a/src/internal/connector/exchange/service_functions.go +++ b/src/internal/connector/exchange/service_functions.go @@ -6,6 +6,7 @@ import ( "github.com/alcionai/clues" "github.com/pkg/errors" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/account" @@ -106,7 +107,7 @@ func includeContainer( ) // Clause ensures that DefaultContactFolder is inspected properly - if category == path.ContactsCategory && *c.GetDisplayName() == DefaultContactFolder { + if category == path.ContactsCategory && ptr.Val(c.GetDisplayName()) == DefaultContactFolder { pb = pb.Append(DefaultContactFolder) if loc != nil { diff --git a/src/internal/connector/exchange/service_iterators.go b/src/internal/connector/exchange/service_iterators.go index fb5fc5b79..12ef679bc 100644 --- a/src/internal/connector/exchange/service_iterators.go +++ b/src/internal/connector/exchange/service_iterators.go @@ -6,6 +6,7 @@ import ( "github.com/alcionai/clues" "github.com/pkg/errors" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" @@ -75,7 +76,7 @@ func filterContainersAndFillCollections( return el.Failure() } - cID := *c.GetId() + cID := ptr.Val(c.GetId()) delete(tombstones, cID) currPath, locPath, ok := includeContainer(qp, c, scope) diff --git a/src/internal/connector/exchange/service_iterators_test.go b/src/internal/connector/exchange/service_iterators_test.go index 704a1ab36..31130d6ce 100644 --- a/src/internal/connector/exchange/service_iterators_test.go +++ b/src/internal/connector/exchange/service_iterators_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" @@ -82,7 +83,7 @@ func (m mockResolver) AddToCache(ctx context.Context, gc graph.Container, b bool m.added = map[string]string{} } - m.added[*gc.GetDisplayName()] = *gc.GetId() + m.added[ptr.Val(gc.GetDisplayName())] = ptr.Val(gc.GetId()) return nil } diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index 8fd17122c..c832c012b 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -117,7 +117,7 @@ func RestoreExchangeEvent( attached []models.Attachmentable ) - if *event.GetHasAttachments() { + if ptr.Val(event.GetHasAttachments()) { attached = event.GetAttachments() transformedEvent.SetAttachments([]models.Attachmentable{}) @@ -136,7 +136,7 @@ func RestoreExchangeEvent( calendarID: destination, userID: user, service: service, - itemID: *response.GetId(), + itemID: ptr.Val(response.GetId()), } for _, attach := range attached { @@ -195,7 +195,7 @@ func RestoreMailMessage( if clone.GetSentDateTime() != nil { sv2 := models.NewSingleValueLegacyExtendedProperty() - sendPropertyValue := common.FormatLegacyTime(*clone.GetSentDateTime()) + sendPropertyValue := common.FormatLegacyTime(ptr.Val(clone.GetSentDateTime())) sendPropertyTag := MailSendDateTimeOverrideProperty sv2.SetId(&sendPropertyTag) sv2.SetValue(&sendPropertyValue) @@ -205,7 +205,7 @@ func RestoreMailMessage( if clone.GetReceivedDateTime() != nil { sv3 := models.NewSingleValueLegacyExtendedProperty() - recvPropertyValue := common.FormatLegacyTime(*clone.GetReceivedDateTime()) + recvPropertyValue := common.FormatLegacyTime(ptr.Val(clone.GetReceivedDateTime())) recvPropertyTag := MailReceiveDateTimeOverriveProperty sv3.SetId(&recvPropertyTag) sv3.SetValue(&recvPropertyValue) @@ -612,7 +612,7 @@ func establishMailRestoreLocation( return "", err } - folderID = *temp.GetId() + folderID = ptr.Val(temp.GetId()) // Only populate the cache if we actually had to create it. Since we set // newCache to false in this we'll only try to populate it once per function @@ -661,7 +661,7 @@ func establishContactsRestoreLocation( return "", err } - folderID := *temp.GetId() + folderID := ptr.Val(temp.GetId()) if isNewCache { if err := cfc.Populate(ctx, errs, folderID, folders[0]); err != nil { @@ -698,7 +698,7 @@ func establishEventsRestoreLocation( return "", err } - folderID := *temp.GetId() + folderID := ptr.Val(temp.GetId()) if isNewCache { if err = ecc.Populate(ctx, errs, folderID, folders[0]); err != nil { diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 02475e5a2..2f726dad3 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -17,6 +17,7 @@ import ( "github.com/pkg/errors" "golang.org/x/exp/maps" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/sharepoint" @@ -151,23 +152,25 @@ func identifySite(item any) (string, string, error) { return "", "", clues.New("non-Siteable item").With("item_type", fmt.Sprintf("%T", item)) } + id := ptr.Val(m.GetId()) + url, ok := ptr.ValOK(m.GetWebUrl()) + if m.GetName() == nil { // the built-in site at "https://{tenant-domain}/search" never has a name. - if m.GetWebUrl() != nil && strings.HasSuffix(*m.GetWebUrl(), "/search") { + if ok && strings.HasSuffix(url, "/search") { // TODO: pii siteID, on this and all following cases - return "", "", clues.Stack(errKnownSkippableCase).With("site_id", *m.GetId()) + return "", "", clues.Stack(errKnownSkippableCase).With("site_id", id) } - return "", "", clues.New("site has no name").With("site_id", *m.GetId()) + return "", "", clues.New("site has no name").With("site_id", id) } // personal (ie: oneDrive) sites have to be filtered out server-side. - url := m.GetWebUrl() - if url != nil && strings.Contains(*url, personalSitePath) { - return "", "", clues.Stack(errKnownSkippableCase).With("site_id", *m.GetId()) + if ok && strings.Contains(url, personalSitePath) { + return "", "", clues.Stack(errKnownSkippableCase).With("site_id", id) } - return *m.GetWebUrl(), *m.GetId(), nil + return url, id, nil } // GetSiteWebURLs returns the WebURLs of sharepoint sites within the tenant. diff --git a/src/internal/connector/graph_connector_helper_test.go b/src/internal/connector/graph_connector_helper_test.go index 405129b5c..c1b0e62b4 100644 --- a/src/internal/connector/graph_connector_helper_test.go +++ b/src/internal/connector/graph_connector_helper_test.go @@ -626,8 +626,8 @@ func compareExchangeEmail( return } - expectedBytes, ok := expected[*itemMessage.GetSubject()] - if !assert.True(t, ok, "unexpected item with Subject %q", *itemMessage.GetSubject()) { + expectedBytes, ok := expected[ptr.Val(itemMessage.GetSubject())] + if !assert.True(t, ok, "unexpected item with Subject %q", ptr.Val(itemMessage.GetSubject())) { return } @@ -653,8 +653,8 @@ func compareExchangeContact( return } - expectedBytes, ok := expected[*itemContact.GetMiddleName()] - if !assert.True(t, ok, "unexpected item with middle name %q", *itemContact.GetMiddleName()) { + expectedBytes, ok := expected[ptr.Val(itemContact.GetMiddleName())] + if !assert.True(t, ok, "unexpected item with middle name %q", ptr.Val(itemContact.GetMiddleName())) { return } @@ -681,8 +681,8 @@ func compareExchangeEvent( return } - expectedBytes, ok := expected[*itemEvent.GetSubject()] - if !assert.True(t, ok, "unexpected item with subject %q", *itemEvent.GetSubject()) { + expectedBytes, ok := expected[ptr.Val(itemEvent.GetSubject())] + if !assert.True(t, ok, "unexpected item with subject %q", ptr.Val(itemEvent.GetSubject())) { return } @@ -704,7 +704,7 @@ func permissionEqual(expected onedrive.UserPermission, got onedrive.UserPermissi if expected.Expiration != nil && got.Expiration != nil && - !expected.Expiration.Equal(*got.Expiration) { + !expected.Expiration.Equal(ptr.Val(got.Expiration)) { return false } diff --git a/src/internal/connector/graph_connector_onedrive_test.go b/src/internal/connector/graph_connector_onedrive_test.go index 4d3ec0024..feba7759d 100644 --- a/src/internal/connector/graph_connector_onedrive_test.go +++ b/src/internal/connector/graph_connector_onedrive_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/tester" @@ -128,11 +129,11 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) SetupSuite() { user, err := suite.connector.Owners.Users().GetByID(ctx, suite.user) require.NoErrorf(suite.T(), err, "fetching user %s", suite.user) - suite.userID = *user.GetId() + suite.userID = ptr.Val(user.GetId()) secondaryUser, err := suite.connector.Owners.Users().GetByID(ctx, suite.secondaryUser) require.NoErrorf(suite.T(), err, "fetching user %s", suite.secondaryUser) - suite.secondaryUserID = *secondaryUser.GetId() + suite.secondaryUserID = ptr.Val(secondaryUser.GetId()) tester.LogTimeOfTest(suite.T()) } diff --git a/src/internal/connector/onedrive/collection.go b/src/internal/connector/onedrive/collection.go index bd9ab3e2d..e9886809c 100644 --- a/src/internal/connector/onedrive/collection.go +++ b/src/internal/connector/onedrive/collection.go @@ -156,20 +156,20 @@ func NewCollection( // populated. The return values denotes if the item was previously // present or is new one. func (oc *Collection) Add(item models.DriveItemable) bool { - _, found := oc.driveItems[*item.GetId()] - oc.driveItems[*item.GetId()] = item + _, found := oc.driveItems[ptr.Val(item.GetId())] + oc.driveItems[ptr.Val(item.GetId())] = item return !found // !found = new } // Remove removes a item from the collection func (oc *Collection) Remove(item models.DriveItemable) bool { - _, found := oc.driveItems[*item.GetId()] + _, found := oc.driveItems[ptr.Val(item.GetId())] if !found { return false } - delete(oc.driveItems, *item.GetId()) + delete(oc.driveItems, ptr.Val(item.GetId())) return true } diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index 0727cee68..4e249dd7e 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -403,7 +403,7 @@ func GetAllFolders( continue } - if !strings.HasPrefix(*item.GetName(), prefix) { + if !strings.HasPrefix(ptr.Val(item.GetName()), prefix) { continue } diff --git a/src/internal/connector/onedrive/drive_test.go b/src/internal/connector/onedrive/drive_test.go index 3023e9390..a20c8e254 100644 --- a/src/internal/connector/onedrive/drive_test.go +++ b/src/internal/connector/onedrive/drive_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" @@ -12,8 +13,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph/api" "github.com/alcionai/corso/src/internal/tester" @@ -358,7 +359,7 @@ func (suite *OneDriveSuite) TestCreateGetDeleteFolder() { require.NotEmpty(t, drives) // TODO: Verify the intended drive - driveID := *drives[0].GetId() + driveID := ptr.Val(drives[0].GetId()) defer func() { for _, id := range folderIDs { @@ -410,11 +411,11 @@ func (suite *OneDriveSuite) TestCreateGetDeleteFolder() { for _, f := range allFolders { - if *f.GetName() == folderName1 || *f.GetName() == folderName2 { - foundFolderIDs = append(foundFolderIDs, *f.GetId()) + if ptr.Val(f.GetName()) == folderName1 || ptr.Val(f.GetName()) == folderName2 { + foundFolderIDs = append(foundFolderIDs, ptr.Val(f.GetId())) } - assert.True(t, strings.HasPrefix(*f.GetName(), test.prefix), "folder prefix") + assert.True(t, strings.HasPrefix(ptr.Val(f.GetName()), test.prefix), "folder prefix") } assert.ElementsMatch(t, folderIDs, foundFolderIDs) diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index f345d482f..096f125d9 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -56,7 +56,7 @@ func sharePointItemReader( } dii := details.ItemInfo{ - SharePoint: sharePointItemInfo(item, *item.GetSize()), + SharePoint: sharePointItemInfo(item, ptr.Val(item.GetSize())), } return dii, resp.Body, nil @@ -70,7 +70,7 @@ func oneDriveItemMetaReader( fetchPermissions bool, ) (io.ReadCloser, int, error) { meta := Metadata{ - FileName: *item.GetName(), + FileName: ptr.Val(item.GetName()), } if item.GetShared() == nil { @@ -139,7 +139,7 @@ func oneDriveItemReader( } dii := details.ItemInfo{ - OneDrive: oneDriveItemInfo(item, *item.GetSize()), + OneDrive: oneDriveItemInfo(item, ptr.Val(item.GetSize())), } return dii, rc, nil @@ -271,18 +271,18 @@ func filterUserPermissions(ctx context.Context, perms []models.Permissionable) [ entityID := "" if gv2.GetUser() != nil { - entityID = *gv2.GetUser().GetId() + entityID = ptr.Val(gv2.GetUser().GetId()) } else if gv2.GetGroup() != nil { - entityID = *gv2.GetGroup().GetId() + entityID = ptr.Val(gv2.GetGroup().GetId()) } else { // TODO Add appliction permissions when adding permissions for SharePoint // https://devblogs.microsoft.com/microsoft365dev/controlling-app-access-on-specific-sharepoint-site-collections/ logm := logger.Ctx(ctx) if gv2.GetApplication() != nil { - logm.With("application_id", *gv2.GetApplication().GetId()) + logm.With("application_id", ptr.Val(gv2.GetApplication().GetId())) } if gv2.GetDevice() != nil { - logm.With("application_id", *gv2.GetDevice().GetId()) + logm.With("application_id", ptr.Val(gv2.GetDevice().GetId())) } logm.Warn("untracked permission") } diff --git a/src/internal/connector/onedrive/item_test.go b/src/internal/connector/onedrive/item_test.go index 462fe8e30..6ae48a8af 100644 --- a/src/internal/connector/onedrive/item_test.go +++ b/src/internal/connector/onedrive/item_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" @@ -52,7 +53,7 @@ func (suite *ItemIntegrationSuite) SetupSuite() { require.Greaterf(t, len(odDrives), 0, "user %s does not have a drive", suite.user) // Pick the first drive - suite.userDriveID = *odDrives[0].GetId() + suite.userDriveID = ptr.Val(odDrives[0].GetId()) } // TestItemReader is an integration test that makes a few assumptions @@ -152,32 +153,42 @@ func (suite *ItemIntegrationSuite) TestItemWriter() { require.NoError(t, err) // Test Requirement 2: "Test Folder" should exist - folder, err := getFolder(ctx, srv, test.driveID, *root.GetId(), "Test Folder") + folder, err := getFolder(ctx, srv, test.driveID, ptr.Val(root.GetId()), "Test Folder") require.NoError(t, err) newFolderName := "testfolder_" + common.FormatNow(common.SimpleTimeTesting) t.Logf("Test will create folder %s", newFolderName) - newFolder, err := CreateItem(ctx, srv, test.driveID, *folder.GetId(), newItem(newFolderName, true)) + newFolder, err := CreateItem( + ctx, + srv, + test.driveID, + ptr.Val(folder.GetId()), + newItem(newFolderName, true)) require.NoError(t, err) require.NotNil(t, newFolder.GetId()) newItemName := "testItem_" + common.FormatNow(common.SimpleTimeTesting) t.Logf("Test will create item %s", newItemName) - newItem, err := CreateItem(ctx, srv, test.driveID, *newFolder.GetId(), newItem(newItemName, false)) + newItem, err := CreateItem( + ctx, + srv, + test.driveID, + ptr.Val(newFolder.GetId()), + newItem(newItemName, false)) require.NoError(t, err) require.NotNil(t, newItem.GetId()) // HACK: Leveraging this to test getFolder behavior for a file. `getFolder()` on the // newly created item should fail because it's a file not a folder - _, err = getFolder(ctx, srv, test.driveID, *newFolder.GetId(), newItemName) + _, err = getFolder(ctx, srv, test.driveID, ptr.Val(newFolder.GetId()), newItemName) require.ErrorIs(t, err, errFolderNotFound) // Initialize a 100KB mockDataProvider td, writeSize := mockDataReader(int64(100 * 1024)) - w, err := driveItemWriter(ctx, srv, test.driveID, *newItem.GetId(), writeSize) + w, err := driveItemWriter(ctx, srv, test.driveID, ptr.Val(newItem.GetId()), writeSize) require.NoError(t, err) // Using a 32 KB buffer for the copy allows us to validate the @@ -224,11 +235,11 @@ func (suite *ItemIntegrationSuite) TestDriveGetFolder() { require.NoError(t, err) // Lookup a folder that doesn't exist - _, err = getFolder(ctx, srv, test.driveID, *root.GetId(), "FolderDoesNotExist") + _, err = getFolder(ctx, srv, test.driveID, ptr.Val(root.GetId()), "FolderDoesNotExist") require.ErrorIs(t, err, errFolderNotFound) // Lookup a folder that does exist - _, err = getFolder(ctx, srv, test.driveID, *root.GetId(), "") + _, err = getFolder(ctx, srv, test.driveID, ptr.Val(root.GetId()), "") require.NoError(t, err) }) } diff --git a/src/internal/connector/onedrive/permission.go b/src/internal/connector/onedrive/permission.go index 1ea9cf2c0..2fafc1460 100644 --- a/src/internal/connector/onedrive/permission.go +++ b/src/internal/connector/onedrive/permission.go @@ -8,6 +8,7 @@ import ( "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/pkg/errors" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/version" @@ -219,7 +220,7 @@ func restorePermissions( return graph.Wrap(ctx, err, "setting permissions") } - permissionIDMappings[p.ID] = *np.GetValue()[0].GetId() + permissionIDMappings[p.ID] = ptr.Val(np.GetValue()[0].GetId()) } return nil diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 870a72f9c..f4cf25193 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -530,7 +530,7 @@ func restoreData( } // Get a drive item writer - w, err := driveItemWriter(ctx, service, driveID, *newItem.GetId(), ss.Size()) + w, err := driveItemWriter(ctx, service, driveID, ptr.Val(newItem.GetId()), ss.Size()) if err != nil { return "", details.ItemInfo{}, clues.Wrap(err, "creating item writer") } @@ -555,7 +555,7 @@ func restoreData( dii.OneDrive = oneDriveItemInfo(newItem, written) } - return *newItem.GetId(), dii, nil + return ptr.Val(newItem.GetId()), dii, nil } func fetchAndReadMetadata( diff --git a/src/internal/connector/sharepoint/api/pages.go b/src/internal/connector/sharepoint/api/pages.go index dcffa1dcf..a06a25ad8 100644 --- a/src/internal/connector/sharepoint/api/pages.go +++ b/src/internal/connector/sharepoint/api/pages.go @@ -118,7 +118,7 @@ func FetchPages(ctx context.Context, bs *discover.BetaService, siteID string) ([ for _, entry := range resp.GetValue() { var ( - pid = *entry.GetId() + pid = ptr.Val(entry.GetId()) temp = NameID{pid, pid} ) @@ -130,11 +130,12 @@ func FetchPages(ctx context.Context, bs *discover.BetaService, siteID string) ([ pages = append(pages, temp) } - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = sites.NewItemPagesRequestBuilder(*resp.GetOdataNextLink(), bs.Client().Adapter()) + builder = sites.NewItemPagesRequestBuilder(link, bs.Client().Adapter()) } return pages, nil diff --git a/src/internal/connector/sharepoint/collection.go b/src/internal/connector/sharepoint/collection.go index 3c9401341..53e0c9f5e 100644 --- a/src/internal/connector/sharepoint/collection.go +++ b/src/internal/connector/sharepoint/collection.go @@ -249,7 +249,7 @@ func (sc *Collection) retrieveLists( metrics.Successes++ sc.data <- &Item{ - id: *lst.GetId(), + id: ptr.Val(lst.GetId()), data: io.NopCloser(bytes.NewReader(byteArray)), info: sharePointListInfo(lst, size), modTime: t, @@ -311,7 +311,7 @@ func (sc *Collection) retrievePages( metrics.Bytes += size metrics.Successes++ sc.data <- &Item{ - id: *pg.GetId(), + id: ptr.Val(pg.GetId()), data: io.NopCloser(bytes.NewReader(byteArray)), info: sharePointPageInfo(pg, root, size), modTime: ptr.OrNow(pg.GetLastModifiedDateTime()), diff --git a/src/internal/connector/sharepoint/collection_test.go b/src/internal/connector/sharepoint/collection_test.go index 8e4985163..9116eb0dc 100644 --- a/src/internal/connector/sharepoint/collection_test.go +++ b/src/internal/connector/sharepoint/collection_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/sharepoint/api" @@ -211,20 +212,20 @@ func (suite *SharePointCollectionSuite) TestListCollection_Restore() { assert.NoError(t, err, "getting site lists") for _, temp := range resp.GetValue() { - if *temp.GetDisplayName() == deets.SharePoint.ItemName { + if ptr.Val(temp.GetDisplayName()) == deets.SharePoint.ItemName { isFound = true - deleteID = *temp.GetId() + deleteID = ptr.Val(temp.GetId()) break } } // Get Next Link - link := resp.GetOdataNextLink() - if link == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = sites.NewItemListsRequestBuilder(*link, service.Adapter()) + builder = sites.NewItemListsRequestBuilder(link, service.Adapter()) } if isFound { @@ -254,7 +255,7 @@ func (suite *SharePointCollectionSuite) TestRestoreLocation() { siteDrive, err := service.Client().SitesById(suite.siteID).Drive().Get(ctx, nil) require.NoError(t, err) - driveID := *siteDrive.GetId() + driveID := ptr.Val(siteDrive.GetId()) err = onedrive.DeleteItem(ctx, service, driveID, folderID) assert.NoError(t, err) } diff --git a/src/internal/connector/sharepoint/list.go b/src/internal/connector/sharepoint/list.go index 41316f140..eb36e5ba2 100644 --- a/src/internal/connector/sharepoint/list.go +++ b/src/internal/connector/sharepoint/list.go @@ -61,11 +61,12 @@ func preFetchLists( listTuples = append(listTuples, temp) } - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite.NewItemListsRequestBuilder(ptr.Val(resp.GetOdataNextLink()), gs.Adapter()) + builder = mssite.NewItemListsRequestBuilder(link, gs.Adapter()) } return listTuples, nil @@ -215,7 +216,7 @@ func fetchListItems( break } - newPrefix := prefix.ItemsById(*itm.GetId()) + newPrefix := prefix.ItemsById(ptr.Val(itm.GetId())) fields, err := newPrefix.Fields().Get(ctx, nil) if err != nil { @@ -228,11 +229,12 @@ func fetchListItems( itms = append(itms, itm) } - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite.NewItemListsItemItemsRequestBuilder(*resp.GetOdataNextLink(), gs.Adapter()) + builder = mssite.NewItemListsItemItemsRequestBuilder(link, gs.Adapter()) } return itms, el.Failure() @@ -260,11 +262,12 @@ func fetchColumns( cs = append(cs, resp.GetValue()...) - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite.NewItemListsItemColumnsRequestBuilder(*resp.GetOdataNextLink(), gs.Adapter()) + builder = mssite.NewItemListsItemColumnsRequestBuilder(link, gs.Adapter()) } } else { builder := gs.Client().SitesById(siteID).ListsById(listID).ContentTypesById(cTypeID).Columns() @@ -277,11 +280,12 @@ func fetchColumns( cs = append(cs, resp.GetValue()...) - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite.NewItemListsItemContentTypesItemColumnsRequestBuilder(*resp.GetOdataNextLink(), gs.Adapter()) + builder = mssite.NewItemListsItemContentTypesItemColumnsRequestBuilder(link, gs.Adapter()) } } @@ -342,11 +346,12 @@ func fetchContentTypes( cTypes = append(cTypes, cont) } - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite.NewItemListsItemContentTypesRequestBuilder(*resp.GetOdataNextLink(), gs.Adapter()) + builder = mssite.NewItemListsItemContentTypesRequestBuilder(link, gs.Adapter()) } return cTypes, el.Failure() @@ -370,15 +375,14 @@ func fetchColumnLinks( links = append(links, resp.GetValue()...) - if resp.GetOdataNextLink() == nil { + link, ok := ptr.ValOK(resp.GetOdataNextLink()) + if !ok { break } - builder = mssite. - NewItemListsItemContentTypesItemColumnLinksRequestBuilder( - *resp.GetOdataNextLink(), - gs.Adapter(), - ) + builder = mssite.NewItemListsItemContentTypesItemColumnLinksRequestBuilder( + link, + gs.Adapter()) } return links, nil diff --git a/src/internal/connector/sharepoint/pageInfo.go b/src/internal/connector/sharepoint/pageInfo.go index 81e2221bf..97dc618ae 100644 --- a/src/internal/connector/sharepoint/pageInfo.go +++ b/src/internal/connector/sharepoint/pageInfo.go @@ -3,6 +3,7 @@ package sharepoint import ( "time" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" "github.com/alcionai/corso/src/pkg/backup/details" ) @@ -16,8 +17,8 @@ func sharePointPageInfo(page models.SitePageable, root string, size int64) *deta created, modified time.Time ) - if page.GetTitle() != nil { - name = *page.GetTitle() + if title, ok := ptr.ValOK(page.GetTitle()); ok { + name = title } if page.GetWebUrl() != nil { @@ -25,16 +26,14 @@ func sharePointPageInfo(page models.SitePageable, root string, size int64) *deta prefix = root + "/" } - webURL = prefix + *page.GetWebUrl() + webURL = prefix + ptr.Val(page.GetWebUrl()) } if page.GetCreatedDateTime() != nil { - created = *page.GetCreatedDateTime() + created = ptr.Val(page.GetCreatedDateTime()) } - if page.GetLastModifiedDateTime() != nil { - modified = *page.GetLastModifiedDateTime() - } + modified = ptr.OrNow(page.GetLastModifiedDateTime()) return &details.SharePointInfo{ ItemType: details.SharePointPage, diff --git a/src/internal/connector/sharepoint/restore.go b/src/internal/connector/sharepoint/restore.go index 30535bed1..b349dd9c7 100644 --- a/src/internal/connector/sharepoint/restore.go +++ b/src/internal/connector/sharepoint/restore.go @@ -129,7 +129,7 @@ func createRestoreFolders( return "", graph.Wrap(ctx, err, "getting site drive root") } - return onedrive.CreateRestoreFolders(ctx, service, *mainDrive.GetId(), restoreFolders) + return onedrive.CreateRestoreFolders(ctx, service, ptr.Val(mainDrive.GetId()), restoreFolders) } // restoreListItem utility function restores a List to the siteID. @@ -162,8 +162,8 @@ func restoreListItem( return dii, clues.Wrap(err, "creating item").WithClues(ctx) } - if oldList.GetDisplayName() != nil { - listName = *oldList.GetDisplayName() + if name, ok := ptr.ValOK(oldList.GetDisplayName()); ok { + listName = name } var ( @@ -191,7 +191,7 @@ func restoreListItem( for _, lItem := range contents { _, err := service.Client(). SitesById(siteID). - ListsById(*restoredList.GetId()). + ListsById(ptr.Val(restoredList.GetId())). Items(). Post(ctx, lItem, nil) if err != nil { diff --git a/src/internal/connector/support/attendee.go b/src/internal/connector/support/attendee.go index 9c55d9890..3fac24920 100644 --- a/src/internal/connector/support/attendee.go +++ b/src/internal/connector/support/attendee.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/microsoftgraph/msgraph-sdk-go/models" + + "github.com/alcionai/corso/src/internal/common/ptr" ) type attendee struct { @@ -30,12 +32,12 @@ func FormatAttendees(event models.Eventable, isHTML bool) string { } temp := attendee{ - name: *entry.GetEmailAddress().GetName(), - email: *entry.GetEmailAddress().GetAddress(), + name: ptr.Val(entry.GetEmailAddress().GetName()), + email: ptr.Val(entry.GetEmailAddress().GetAddress()), response: entry.GetStatus().GetResponse().String(), } - switch *entry.GetType() { + switch ptr.Val(entry.GetType()) { case models.REQUIRED_ATTENDEETYPE: required = append(required, temp) diff --git a/src/internal/connector/support/m365Support.go b/src/internal/connector/support/m365Support.go index c3aacef7f..aff494dad 100644 --- a/src/internal/connector/support/m365Support.go +++ b/src/internal/connector/support/m365Support.go @@ -1,8 +1,6 @@ package support import ( - "strings" - absser "github.com/microsoft/kiota-abstractions-go/serialization" js "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" @@ -87,14 +85,3 @@ func CreatePageFromBytes(bytes []byte) (bmodels.SitePageable, error) { return page, nil } - -func HasAttachments(body models.ItemBodyable) bool { - if body.GetContent() == nil || body.GetContentType() == nil || - *body.GetContentType() == models.TEXT_BODYTYPE || len(*body.GetContent()) == 0 { - return false - } - - content := *body.GetContent() - - return strings.Contains(content, "src=\"cid:") -} diff --git a/src/internal/connector/support/m365Support_test.go b/src/internal/connector/support/m365Support_test.go index d26b61462..d44c7b5a8 100644 --- a/src/internal/connector/support/m365Support_test.go +++ b/src/internal/connector/support/m365Support_test.go @@ -4,7 +4,6 @@ import ( "testing" kioser "github.com/microsoft/kiota-serialization-json-go" - "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -233,58 +232,3 @@ func (suite *DataSupportSuite) TestCreatePageFromBytes() { }) } } - -func (suite *DataSupportSuite) TestHasAttachments() { - tests := []struct { - name string - hasAttachment assert.BoolAssertionFunc - getBodyable func(t *testing.T) models.ItemBodyable - }{ - { - name: "Mock w/out attachment", - hasAttachment: assert.False, - getBodyable: func(t *testing.T) models.ItemBodyable { - byteArray := mockconnector.GetMockMessageWithBodyBytes( - "Test", - "This is testing", - "This is testing", - ) - message, err := CreateMessageFromBytes(byteArray) - require.NoError(t, err) - return message.GetBody() - }, - }, - { - name: "Mock w/ inline attachment", - hasAttachment: assert.True, - getBodyable: func(t *testing.T) models.ItemBodyable { - byteArray := mockconnector.GetMessageWithOneDriveAttachment("Test legacy") - message, err := CreateMessageFromBytes(byteArray) - require.NoError(t, err) - return message.GetBody() - }, - }, - { - name: "Edge Case", - hasAttachment: assert.True, - getBodyable: func(t *testing.T) models.ItemBodyable { - //nolint:lll - content := "
\r\n