Compare commits
6 Commits
main
...
attachment
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57666ec6b4 | ||
|
|
55d2d6c9ad | ||
|
|
88e494987a | ||
|
|
eb129a4fe2 | ||
|
|
0196e3b953 | ||
|
|
57d37c70ce |
@ -55,9 +55,15 @@ func uploadAttachment(
|
||||
|
||||
// item Attachments to be skipped until the completion of Issue #2353
|
||||
if attachmentType == models.ITEM_ATTACHMENTTYPE {
|
||||
name := ""
|
||||
if attachment.GetName() != nil {
|
||||
name = *attachment.GetName()
|
||||
}
|
||||
|
||||
logger.Ctx(ctx).Infow("item attachment uploads are not supported ",
|
||||
"attachment_name", *attachment.GetName(), // TODO: Update to support PII protection
|
||||
"attachment_name", name, // TODO: Update to support PII protection
|
||||
"attachment_type", attachmentType,
|
||||
"internal_item_type", getItemAttachmentItemType(attachment),
|
||||
"attachment_id", *attachment.GetId(),
|
||||
)
|
||||
|
||||
@ -101,3 +107,19 @@ func uploadLargeAttachment(ctx context.Context, uploader attachmentUploadable,
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getItemAttachmentItemType(query models.Attachmentable) string {
|
||||
empty := ""
|
||||
attachment, ok := query.(models.ItemAttachmentable)
|
||||
|
||||
if !ok {
|
||||
return empty
|
||||
}
|
||||
|
||||
item := attachment.GetItem()
|
||||
if item.GetOdataType() == nil {
|
||||
return empty
|
||||
}
|
||||
|
||||
return *item.GetOdataType()
|
||||
}
|
||||
|
||||
@ -38,6 +38,16 @@ func (mau *mailAttachmentUploader) getItemID() string {
|
||||
}
|
||||
|
||||
func (mau *mailAttachmentUploader) uploadSmallAttachment(ctx context.Context, attach models.Attachmentable) error {
|
||||
wtr := js.NewJsonSerializationWriter()
|
||||
err := wtr.WriteObjectValue(attach)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
byteArray, err := wtr.GetSerializedContent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := mau.service.Client().
|
||||
UsersById(mau.userID).
|
||||
MailFoldersById(mau.folderID).
|
||||
|
||||
110
src/internal/connector/exchange/attachment_uploadable_test.go
Normal file
110
src/internal/connector/exchange/attachment_uploadable_test.go
Normal file
@ -0,0 +1,110 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common"
|
||||
"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"
|
||||
"github.com/alcionai/corso/src/internal/connector/support"
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
"github.com/alcionai/corso/src/pkg/account"
|
||||
"github.com/alcionai/corso/src/pkg/control"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type ExchangeRestoreAttachmentSuite struct {
|
||||
suite.Suite
|
||||
gs graph.Servicer
|
||||
credentials account.M365Config
|
||||
ac api.Client
|
||||
}
|
||||
|
||||
func TestExchangeRestoreAttachmentSuite(t *testing.T) {
|
||||
tester.RunOnAny(
|
||||
t,
|
||||
tester.CorsoCITests,
|
||||
tester.CorsoConnectorRestoreExchangeCollectionTests,
|
||||
)
|
||||
|
||||
suite.Run(t, new(ExchangeRestoreAttachmentSuite))
|
||||
}
|
||||
|
||||
func (suite *ExchangeRestoreAttachmentSuite) SetupSuite() {
|
||||
t := suite.T()
|
||||
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
|
||||
|
||||
a := tester.NewM365Account(t)
|
||||
m365, err := a.M365Config()
|
||||
require.NoError(t, err)
|
||||
|
||||
suite.credentials = m365
|
||||
suite.ac, err = api.NewClient(m365)
|
||||
require.NoError(t, err)
|
||||
|
||||
adpt, err := graph.CreateAdapter(m365.AzureTenantID, m365.AzureClientID, m365.AzureClientSecret)
|
||||
require.NoError(t, err)
|
||||
|
||||
suite.gs = graph.NewService(adpt)
|
||||
|
||||
require.NoError(suite.T(), err)
|
||||
}
|
||||
|
||||
// TestAttachmentUploads verifies that various attachnments can be uploaded
|
||||
// to certain base objects.
|
||||
func (suite *ExchangeRestoreAttachmentSuite) TestAttachmentUploadsMail() {
|
||||
ctx, flush := tester.NewContext()
|
||||
defer flush()
|
||||
|
||||
// base message --> outlookable ??
|
||||
// attachment -->
|
||||
t := suite.T()
|
||||
//userID := tester.M365UserID(suite.T())
|
||||
|
||||
userID := "dustina@8qzvrj.onmicrosoft.com"
|
||||
service, err := createService(suite.ac.Credentials)
|
||||
require.NoError(t, err)
|
||||
|
||||
now := time.Now()
|
||||
folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now)
|
||||
folder, err := suite.ac.Mail().CreateMailFolder(ctx, userID, folderName)
|
||||
require.NoError(t, err)
|
||||
|
||||
folderID := *folder.GetId()
|
||||
byteArray := mockconnector.GetMockMessageBytes("Base Message")
|
||||
|
||||
deets, err := RestoreExchangeObject(ctx, byteArray, path.EmailCategory, control.Copy, service, folderID, userID)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, deets)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
getAttachment func(t *testing.T) models.Attachmentable
|
||||
}{
|
||||
{
|
||||
name: "Reference Attachment",
|
||||
getAttachment: func(t *testing.T) models.Attachmentable {
|
||||
byteArray := mockconnector.GetMockAttachmentReference()
|
||||
|
||||
attach, err := support.CreateAttachmentFromBytes(byteArray)
|
||||
require.NoError(t, err)
|
||||
|
||||
return attach
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Log("Test compiled fine")
|
||||
})
|
||||
}
|
||||
// attach to upload
|
||||
|
||||
}
|
||||
9
src/internal/connector/mockconnector/mock_attachment.go
Normal file
9
src/internal/connector/mockconnector/mock_attachment.go
Normal file
@ -0,0 +1,9 @@
|
||||
package mockconnector
|
||||
|
||||
func GetMockAttachmentReference() []byte {
|
||||
//nolint:lll
|
||||
attachment := "\"@odata.type\":\"#microsoft.graph.referenceAttachment\",\"id\":\"AAMkAGQ1NzViZTdhLTEwMTMtNGJjNi05YWI2LTg4NWRlZDA2Y2UxOABGAAAAAAAPvVwUramXT7jlSGpVU8_7BwB8wYc0thTTTYl3RpEYIUq_AAAAAAEJAAB8wYc0thTTTYl3RpEYIUq_AAB0tLkCAAABEgAQALqePWc7rIJHp_oQ7U_XyOI=\"," +
|
||||
"\"lastModifiedDateTime\":\"2022-09-30T19:33:26Z\",\"name\":\"sample.txt\",\"contentType\":\"text/plain\",\"size\":1042,\"isInline\":true}"
|
||||
|
||||
return []byte(attachment)
|
||||
}
|
||||
@ -71,3 +71,14 @@ func CreateListFromBytes(bytes []byte) (models.Listable, error) {
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func CreateAttachmentFromBytes(bytes []byte) (models.Attachmentable, error) {
|
||||
parsable, err := CreateFromBytes(bytes, models.CreateAttachmentFromDiscriminatorValue)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating m365 attachment object from provided bytes")
|
||||
}
|
||||
|
||||
attach := parsable.(models.Attachmentable)
|
||||
|
||||
return attach, nil
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package support
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
js "github.com/microsoft/kiota-serialization-json-go"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -32,6 +34,19 @@ func (suite *SupportTestSuite) TestToMessage() {
|
||||
suite.NotEqual(message.GetId(), clone.GetId())
|
||||
}
|
||||
|
||||
func (suite *SupportTestSuite) TestToM() {
|
||||
bytes := mockconnector.GetMockMessageBytes("m365 mail support test")
|
||||
message, err := CreateMessageFromBytes(bytes)
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
clone := ToMessage(message)
|
||||
suite.Equal(message.GetBccRecipients(), clone.GetBccRecipients())
|
||||
suite.Equal(message.GetSubject(), clone.GetSubject())
|
||||
suite.Equal(message.GetSender(), clone.GetSender())
|
||||
suite.Equal(message.GetSentDateTime(), clone.GetSentDateTime())
|
||||
suite.NotEqual(message.GetId(), clone.GetId())
|
||||
}
|
||||
|
||||
func (suite *SupportTestSuite) TestToEventSimplified() {
|
||||
t := suite.T()
|
||||
bytes := mockconnector.GetMockEventWithAttendeesBytes("M365 Event Support Test")
|
||||
@ -40,6 +55,13 @@ func (suite *SupportTestSuite) TestToEventSimplified() {
|
||||
|
||||
attendees := event.GetAttendees()
|
||||
newEvent := ToEventSimplified(event)
|
||||
newEvent.SetIsOrganizer(nil)
|
||||
wtr := js.NewJsonSerializationWriter()
|
||||
err = wtr.WriteObjectValue("", newEvent)
|
||||
require.NoError(t, err)
|
||||
byteArray, err := wtr.GetSerializedContent()
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("newEvent %+v\n", string(byteArray))
|
||||
|
||||
assert.Empty(t, newEvent.GetHideAttendees())
|
||||
assert.Equal(t, *event.GetBody().GetContentType(), *newEvent.GetBody().GetContentType())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user