Add created and modified time to all (#1452)
## Description Adds Created and Modified time to all objects. Need to go after https://github.com/alcionai/corso/pull/1446 as it is built on top of that. Keeping in draft until then. ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🐹 Trivial/Minor ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * https://github.com/alcionai/corso/issues/1366 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E Co-authored-by: aviator-app[bot] <48659329+aviator-app[bot]@users.noreply.github.com>
This commit is contained in:
parent
43a07261da
commit
825cd6f21b
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -2,7 +2,6 @@ name: Build/Release Corso
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*.*.*"]
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
@ -9,13 +11,25 @@ import (
|
||||
// ContactInfo translate models.Contactable metadata into searchable content
|
||||
func ContactInfo(contact models.Contactable) *details.ExchangeInfo {
|
||||
name := ""
|
||||
created := time.Time{}
|
||||
modified := time.Time{}
|
||||
|
||||
if contact.GetDisplayName() != nil {
|
||||
name = *contact.GetDisplayName()
|
||||
}
|
||||
|
||||
if contact.GetCreatedDateTime() != nil {
|
||||
created = *contact.GetCreatedDateTime()
|
||||
}
|
||||
|
||||
if contact.GetLastModifiedDateTime() != nil {
|
||||
modified = *contact.GetLastModifiedDateTime()
|
||||
}
|
||||
|
||||
return &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeContact,
|
||||
ContactName: name,
|
||||
Created: created,
|
||||
Modified: modified,
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package exchange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -19,6 +20,8 @@ func TestContactSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *ContactSuite) TestContactInfo() {
|
||||
initial := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
contactAndRP func() (models.Contactable, *details.ExchangeInfo)
|
||||
@ -26,18 +29,30 @@ func (suite *ContactSuite) TestContactInfo() {
|
||||
{
|
||||
name: "Empty Contact",
|
||||
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
||||
i := &details.ExchangeInfo{ItemType: details.ExchangeContact}
|
||||
return models.NewContact(), i
|
||||
contact := models.NewContact()
|
||||
contact.SetCreatedDateTime(&initial)
|
||||
contact.SetLastModifiedDateTime(&initial)
|
||||
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeContact,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return contact, i
|
||||
},
|
||||
}, {
|
||||
name: "Only Name",
|
||||
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
||||
aPerson := "Whole Person"
|
||||
contact := models.NewContact()
|
||||
contact.SetCreatedDateTime(&initial)
|
||||
contact.SetLastModifiedDateTime(&initial)
|
||||
contact.SetDisplayName(&aPerson)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeContact,
|
||||
ContactName: aPerson,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return contact, i
|
||||
},
|
||||
|
||||
@ -16,6 +16,8 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
|
||||
recurs bool
|
||||
start = time.Time{}
|
||||
end = time.Time{}
|
||||
created = time.Time{}
|
||||
modified = time.Time{}
|
||||
)
|
||||
|
||||
if evt.GetOrganizer() != nil &&
|
||||
@ -58,6 +60,14 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
if evt.GetCreatedDateTime() != nil {
|
||||
created = *evt.GetCreatedDateTime()
|
||||
}
|
||||
|
||||
if evt.GetLastModifiedDateTime() != nil {
|
||||
modified = *evt.GetLastModifiedDateTime()
|
||||
}
|
||||
|
||||
return &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeEvent,
|
||||
Organizer: organizer,
|
||||
@ -65,5 +75,7 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
|
||||
EventStart: start,
|
||||
EventEnd: end,
|
||||
EventRecurs: recurs,
|
||||
Created: created,
|
||||
Modified: modified,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,13 @@ func (suite *EventSuite) TestEventInfo() {
|
||||
{
|
||||
name: "Empty event",
|
||||
evtAndRP: func() (models.Eventable, *details.ExchangeInfo) {
|
||||
return models.NewEvent(), &details.ExchangeInfo{
|
||||
event := models.NewEvent()
|
||||
|
||||
// Start and Modified will always be available in API
|
||||
event.SetCreatedDateTime(&initial)
|
||||
event.SetLastModifiedDateTime(&initial)
|
||||
|
||||
return event, &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeEvent,
|
||||
}
|
||||
},
|
||||
@ -51,6 +57,8 @@ func (suite *EventSuite) TestEventInfo() {
|
||||
dateTime = models.NewDateTimeTimeZone()
|
||||
)
|
||||
|
||||
event.SetCreatedDateTime(&initial)
|
||||
event.SetLastModifiedDateTime(&initial)
|
||||
dateTime.SetDateTime(&now)
|
||||
event.SetStart(dateTime)
|
||||
|
||||
@ -70,6 +78,8 @@ func (suite *EventSuite) TestEventInfo() {
|
||||
endTime = models.NewDateTimeTimeZone()
|
||||
)
|
||||
|
||||
event.SetCreatedDateTime(&initial)
|
||||
event.SetLastModifiedDateTime(&initial)
|
||||
startTime.SetDateTime(&now)
|
||||
event.SetStart(startTime)
|
||||
|
||||
@ -93,6 +103,8 @@ func (suite *EventSuite) TestEventInfo() {
|
||||
event = models.NewEvent()
|
||||
)
|
||||
|
||||
event.SetCreatedDateTime(&initial)
|
||||
event.SetLastModifiedDateTime(&initial)
|
||||
event.SetSubject(&subject)
|
||||
|
||||
return event, &details.ExchangeInfo{
|
||||
|
||||
@ -12,6 +12,8 @@ func MessageInfo(msg models.Messageable) *details.ExchangeInfo {
|
||||
sender := ""
|
||||
subject := ""
|
||||
received := time.Time{}
|
||||
created := time.Time{}
|
||||
modified := time.Time{}
|
||||
|
||||
if msg.GetSender() != nil &&
|
||||
msg.GetSender().GetEmailAddress() != nil &&
|
||||
@ -27,10 +29,20 @@ func MessageInfo(msg models.Messageable) *details.ExchangeInfo {
|
||||
received = *msg.GetReceivedDateTime()
|
||||
}
|
||||
|
||||
if msg.GetCreatedDateTime() != nil {
|
||||
created = *msg.GetCreatedDateTime()
|
||||
}
|
||||
|
||||
if msg.GetLastModifiedDateTime() != nil {
|
||||
modified = *msg.GetLastModifiedDateTime()
|
||||
}
|
||||
|
||||
return &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Sender: sender,
|
||||
Subject: subject,
|
||||
Received: received,
|
||||
Created: created,
|
||||
Modified: modified,
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ func TestMessageSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *MessageSuite) TestMessageInfo() {
|
||||
initial := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
msgAndRP func() (models.Messageable, *details.ExchangeInfo)
|
||||
@ -26,8 +28,16 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
{
|
||||
name: "Empty message",
|
||||
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
||||
i := &details.ExchangeInfo{ItemType: details.ExchangeMail}
|
||||
return models.NewMessage(), i
|
||||
msg := models.NewMessage()
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -39,10 +49,14 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
msg := models.NewMessage()
|
||||
sea.SetAddress(&sender)
|
||||
sr.SetEmailAddress(sea)
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
msg.SetSender(sr)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Sender: sender,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -53,9 +67,13 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
subject := "Hello world"
|
||||
msg := models.NewMessage()
|
||||
msg.SetSubject(&subject)
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Subject: subject,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -65,10 +83,14 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
||||
now := time.Now()
|
||||
msg := models.NewMessage()
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
msg.SetReceivedDateTime(&now)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -82,6 +104,8 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
sr := models.NewRecipient()
|
||||
sea := models.NewEmailAddress()
|
||||
msg := models.NewMessage()
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
sea.SetAddress(&sender)
|
||||
sr.SetEmailAddress(sea)
|
||||
msg.SetSender(sr)
|
||||
@ -92,6 +116,8 @@ func (suite *MessageSuite) TestMessageInfo() {
|
||||
Sender: sender,
|
||||
Subject: subject,
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
|
||||
@ -302,6 +302,8 @@ type ExchangeInfo struct {
|
||||
Organizer string `json:"organizer,omitempty"`
|
||||
ContactName string `json:"contactName,omitempty"`
|
||||
EventRecurs bool `json:"eventRecurs,omitempty"`
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
Modified time.Time `json:"modified,omitempty"`
|
||||
}
|
||||
|
||||
// Headers returns the human-readable names of properties in an ExchangeInfo
|
||||
@ -338,7 +340,10 @@ func (i ExchangeInfo) Values() []string {
|
||||
return []string{i.ContactName}
|
||||
|
||||
case ExchangeMail:
|
||||
return []string{i.Sender, i.Subject, common.FormatTabularDisplayTime(i.Received)}
|
||||
return []string{
|
||||
i.Sender, i.Subject,
|
||||
common.FormatTabularDisplayTime(i.Received),
|
||||
}
|
||||
}
|
||||
|
||||
return []string{}
|
||||
|
||||
@ -2,6 +2,7 @@ package details_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -24,7 +25,8 @@ func TestDetailsUnitSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||
nowStr := common.FormatNow(common.TabularOutput)
|
||||
initial := time.Now()
|
||||
nowStr := common.FormatTimeWith(initial, common.TabularOutput)
|
||||
now, err := common.ParseTime(nowStr)
|
||||
require.NoError(suite.T(), err)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user