Use type switch instead of strings of types (#5156)
Instead of relying on strings pulled from the graph SDK to identify the types of the items we're dealing with use the type of the interface in golang. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #5124 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
8a7a61f05d
commit
6ef2c2d494
@ -170,6 +170,7 @@ func insertStringToBody(body getContenter, newContent string) string {
|
|||||||
return newContent + content
|
return newContent + content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:lll
|
||||||
// ===============================================================================================
|
// ===============================================================================================
|
||||||
// Sanitization section
|
// Sanitization section
|
||||||
// Set of functions that support ItemAttachemtable object restoration.
|
// Set of functions that support ItemAttachemtable object restoration.
|
||||||
@ -187,14 +188,6 @@ func insertStringToBody(body getContenter, newContent string) string {
|
|||||||
// currently supported for Restore operations.
|
// currently supported for Restore operations.
|
||||||
// itemAttachments
|
// itemAttachments
|
||||||
// support ODataType values
|
// support ODataType values
|
||||||
//
|
|
||||||
//nolint:lll
|
|
||||||
const (
|
|
||||||
itemAttachment = "#microsoft.graph.itemAttachment"
|
|
||||||
eventItemType = "#microsoft.graph.event"
|
|
||||||
mailItemType = "#microsoft.graph.message"
|
|
||||||
contactItemType = "#microsoft.graph.contact"
|
|
||||||
)
|
|
||||||
|
|
||||||
// toItemAttachment transforms internal item, OutlookItemables, into
|
// toItemAttachment transforms internal item, OutlookItemables, into
|
||||||
// objects that are able to be uploaded into M365.
|
// objects that are able to be uploaded into M365.
|
||||||
@ -205,20 +198,16 @@ func toItemAttachment(orig models.Attachmentable) (models.Attachmentable, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
item := transform.GetItem()
|
item := transform.GetItem()
|
||||||
itemType := ptr.Val(item.GetOdataType())
|
|
||||||
|
|
||||||
switch itemType {
|
|
||||||
case contactItemType:
|
|
||||||
contact := item.(models.Contactable)
|
|
||||||
revised := sanitizeContact(contact)
|
|
||||||
|
|
||||||
|
switch val := item.(type) {
|
||||||
|
case models.Contactable:
|
||||||
|
revised := sanitizeContact(val)
|
||||||
transform.SetItem(revised)
|
transform.SetItem(revised)
|
||||||
|
|
||||||
return transform, nil
|
return transform, nil
|
||||||
case eventItemType:
|
|
||||||
event := item.(models.Eventable)
|
|
||||||
|
|
||||||
newEvent, err := sanitizeEvent(event)
|
case models.Eventable:
|
||||||
|
newEvent, err := sanitizeEvent(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -226,10 +215,9 @@ func toItemAttachment(orig models.Attachmentable) (models.Attachmentable, error)
|
|||||||
transform.SetItem(newEvent)
|
transform.SetItem(newEvent)
|
||||||
|
|
||||||
return transform, nil
|
return transform, nil
|
||||||
case mailItemType:
|
|
||||||
message := item.(models.Messageable)
|
|
||||||
|
|
||||||
newMessage, err := sanitizeMessage(message)
|
case models.Messageable:
|
||||||
|
newMessage, err := sanitizeMessage(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -237,8 +225,12 @@ func toItemAttachment(orig models.Attachmentable) (models.Attachmentable, error)
|
|||||||
transform.SetItem(newMessage)
|
transform.SetItem(newMessage)
|
||||||
|
|
||||||
return transform, nil
|
return transform, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, clues.New(fmt.Sprintf("unsupported attachment type: %T", itemType))
|
return nil, clues.New(fmt.Sprintf(
|
||||||
|
"unsupported attachment type: (%T) %s",
|
||||||
|
val,
|
||||||
|
ptr.Val(item.GetOdataType())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user