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:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
tags: ["v*.*.*"]
|
tags: ["v*.*.*"]
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package exchange
|
package exchange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
@ -9,13 +11,25 @@ import (
|
|||||||
// ContactInfo translate models.Contactable metadata into searchable content
|
// ContactInfo translate models.Contactable metadata into searchable content
|
||||||
func ContactInfo(contact models.Contactable) *details.ExchangeInfo {
|
func ContactInfo(contact models.Contactable) *details.ExchangeInfo {
|
||||||
name := ""
|
name := ""
|
||||||
|
created := time.Time{}
|
||||||
|
modified := time.Time{}
|
||||||
|
|
||||||
if contact.GetDisplayName() != nil {
|
if contact.GetDisplayName() != nil {
|
||||||
name = *contact.GetDisplayName()
|
name = *contact.GetDisplayName()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if contact.GetCreatedDateTime() != nil {
|
||||||
|
created = *contact.GetCreatedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
if contact.GetLastModifiedDateTime() != nil {
|
||||||
|
modified = *contact.GetLastModifiedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
return &details.ExchangeInfo{
|
return &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeContact,
|
ItemType: details.ExchangeContact,
|
||||||
ContactName: name,
|
ContactName: name,
|
||||||
|
Created: created,
|
||||||
|
Modified: modified,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package exchange
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -19,6 +20,8 @@ func TestContactSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ContactSuite) TestContactInfo() {
|
func (suite *ContactSuite) TestContactInfo() {
|
||||||
|
initial := time.Now()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
contactAndRP func() (models.Contactable, *details.ExchangeInfo)
|
contactAndRP func() (models.Contactable, *details.ExchangeInfo)
|
||||||
@ -26,18 +29,30 @@ func (suite *ContactSuite) TestContactInfo() {
|
|||||||
{
|
{
|
||||||
name: "Empty Contact",
|
name: "Empty Contact",
|
||||||
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
||||||
i := &details.ExchangeInfo{ItemType: details.ExchangeContact}
|
contact := models.NewContact()
|
||||||
return models.NewContact(), i
|
contact.SetCreatedDateTime(&initial)
|
||||||
|
contact.SetLastModifiedDateTime(&initial)
|
||||||
|
|
||||||
|
i := &details.ExchangeInfo{
|
||||||
|
ItemType: details.ExchangeContact,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
|
}
|
||||||
|
return contact, i
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
name: "Only Name",
|
name: "Only Name",
|
||||||
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
contactAndRP: func() (models.Contactable, *details.ExchangeInfo) {
|
||||||
aPerson := "Whole Person"
|
aPerson := "Whole Person"
|
||||||
contact := models.NewContact()
|
contact := models.NewContact()
|
||||||
|
contact.SetCreatedDateTime(&initial)
|
||||||
|
contact.SetLastModifiedDateTime(&initial)
|
||||||
contact.SetDisplayName(&aPerson)
|
contact.SetDisplayName(&aPerson)
|
||||||
i := &details.ExchangeInfo{
|
i := &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeContact,
|
ItemType: details.ExchangeContact,
|
||||||
ContactName: aPerson,
|
ContactName: aPerson,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
}
|
}
|
||||||
return contact, i
|
return contact, i
|
||||||
},
|
},
|
||||||
|
|||||||
@ -16,6 +16,8 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
|
|||||||
recurs bool
|
recurs bool
|
||||||
start = time.Time{}
|
start = time.Time{}
|
||||||
end = time.Time{}
|
end = time.Time{}
|
||||||
|
created = time.Time{}
|
||||||
|
modified = time.Time{}
|
||||||
)
|
)
|
||||||
|
|
||||||
if evt.GetOrganizer() != nil &&
|
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{
|
return &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeEvent,
|
ItemType: details.ExchangeEvent,
|
||||||
Organizer: organizer,
|
Organizer: organizer,
|
||||||
@ -65,5 +75,7 @@ func EventInfo(evt models.Eventable) *details.ExchangeInfo {
|
|||||||
EventStart: start,
|
EventStart: start,
|
||||||
EventEnd: end,
|
EventEnd: end,
|
||||||
EventRecurs: recurs,
|
EventRecurs: recurs,
|
||||||
|
Created: created,
|
||||||
|
Modified: modified,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,13 @@ func (suite *EventSuite) TestEventInfo() {
|
|||||||
{
|
{
|
||||||
name: "Empty event",
|
name: "Empty event",
|
||||||
evtAndRP: func() (models.Eventable, *details.ExchangeInfo) {
|
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,
|
ItemType: details.ExchangeEvent,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -51,6 +57,8 @@ func (suite *EventSuite) TestEventInfo() {
|
|||||||
dateTime = models.NewDateTimeTimeZone()
|
dateTime = models.NewDateTimeTimeZone()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
event.SetCreatedDateTime(&initial)
|
||||||
|
event.SetLastModifiedDateTime(&initial)
|
||||||
dateTime.SetDateTime(&now)
|
dateTime.SetDateTime(&now)
|
||||||
event.SetStart(dateTime)
|
event.SetStart(dateTime)
|
||||||
|
|
||||||
@ -70,6 +78,8 @@ func (suite *EventSuite) TestEventInfo() {
|
|||||||
endTime = models.NewDateTimeTimeZone()
|
endTime = models.NewDateTimeTimeZone()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
event.SetCreatedDateTime(&initial)
|
||||||
|
event.SetLastModifiedDateTime(&initial)
|
||||||
startTime.SetDateTime(&now)
|
startTime.SetDateTime(&now)
|
||||||
event.SetStart(startTime)
|
event.SetStart(startTime)
|
||||||
|
|
||||||
@ -93,6 +103,8 @@ func (suite *EventSuite) TestEventInfo() {
|
|||||||
event = models.NewEvent()
|
event = models.NewEvent()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
event.SetCreatedDateTime(&initial)
|
||||||
|
event.SetLastModifiedDateTime(&initial)
|
||||||
event.SetSubject(&subject)
|
event.SetSubject(&subject)
|
||||||
|
|
||||||
return event, &details.ExchangeInfo{
|
return event, &details.ExchangeInfo{
|
||||||
|
|||||||
@ -12,6 +12,8 @@ func MessageInfo(msg models.Messageable) *details.ExchangeInfo {
|
|||||||
sender := ""
|
sender := ""
|
||||||
subject := ""
|
subject := ""
|
||||||
received := time.Time{}
|
received := time.Time{}
|
||||||
|
created := time.Time{}
|
||||||
|
modified := time.Time{}
|
||||||
|
|
||||||
if msg.GetSender() != nil &&
|
if msg.GetSender() != nil &&
|
||||||
msg.GetSender().GetEmailAddress() != nil &&
|
msg.GetSender().GetEmailAddress() != nil &&
|
||||||
@ -27,10 +29,20 @@ func MessageInfo(msg models.Messageable) *details.ExchangeInfo {
|
|||||||
received = *msg.GetReceivedDateTime()
|
received = *msg.GetReceivedDateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if msg.GetCreatedDateTime() != nil {
|
||||||
|
created = *msg.GetCreatedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.GetLastModifiedDateTime() != nil {
|
||||||
|
modified = *msg.GetLastModifiedDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
return &details.ExchangeInfo{
|
return &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeMail,
|
ItemType: details.ExchangeMail,
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Received: received,
|
Received: received,
|
||||||
|
Created: created,
|
||||||
|
Modified: modified,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,8 @@ func TestMessageSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MessageSuite) TestMessageInfo() {
|
func (suite *MessageSuite) TestMessageInfo() {
|
||||||
|
initial := time.Now()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
msgAndRP func() (models.Messageable, *details.ExchangeInfo)
|
msgAndRP func() (models.Messageable, *details.ExchangeInfo)
|
||||||
@ -26,8 +28,16 @@ func (suite *MessageSuite) TestMessageInfo() {
|
|||||||
{
|
{
|
||||||
name: "Empty message",
|
name: "Empty message",
|
||||||
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
||||||
i := &details.ExchangeInfo{ItemType: details.ExchangeMail}
|
msg := models.NewMessage()
|
||||||
return models.NewMessage(), i
|
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()
|
msg := models.NewMessage()
|
||||||
sea.SetAddress(&sender)
|
sea.SetAddress(&sender)
|
||||||
sr.SetEmailAddress(sea)
|
sr.SetEmailAddress(sea)
|
||||||
|
msg.SetCreatedDateTime(&initial)
|
||||||
|
msg.SetLastModifiedDateTime(&initial)
|
||||||
msg.SetSender(sr)
|
msg.SetSender(sr)
|
||||||
i := &details.ExchangeInfo{
|
i := &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeMail,
|
ItemType: details.ExchangeMail,
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
}
|
}
|
||||||
return msg, i
|
return msg, i
|
||||||
},
|
},
|
||||||
@ -53,9 +67,13 @@ func (suite *MessageSuite) TestMessageInfo() {
|
|||||||
subject := "Hello world"
|
subject := "Hello world"
|
||||||
msg := models.NewMessage()
|
msg := models.NewMessage()
|
||||||
msg.SetSubject(&subject)
|
msg.SetSubject(&subject)
|
||||||
|
msg.SetCreatedDateTime(&initial)
|
||||||
|
msg.SetLastModifiedDateTime(&initial)
|
||||||
i := &details.ExchangeInfo{
|
i := &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeMail,
|
ItemType: details.ExchangeMail,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
}
|
}
|
||||||
return msg, i
|
return msg, i
|
||||||
},
|
},
|
||||||
@ -65,10 +83,14 @@ func (suite *MessageSuite) TestMessageInfo() {
|
|||||||
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
msg := models.NewMessage()
|
msg := models.NewMessage()
|
||||||
|
msg.SetCreatedDateTime(&initial)
|
||||||
|
msg.SetLastModifiedDateTime(&initial)
|
||||||
msg.SetReceivedDateTime(&now)
|
msg.SetReceivedDateTime(&now)
|
||||||
i := &details.ExchangeInfo{
|
i := &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeMail,
|
ItemType: details.ExchangeMail,
|
||||||
Received: now,
|
Received: now,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
}
|
}
|
||||||
return msg, i
|
return msg, i
|
||||||
},
|
},
|
||||||
@ -82,6 +104,8 @@ func (suite *MessageSuite) TestMessageInfo() {
|
|||||||
sr := models.NewRecipient()
|
sr := models.NewRecipient()
|
||||||
sea := models.NewEmailAddress()
|
sea := models.NewEmailAddress()
|
||||||
msg := models.NewMessage()
|
msg := models.NewMessage()
|
||||||
|
msg.SetCreatedDateTime(&initial)
|
||||||
|
msg.SetLastModifiedDateTime(&initial)
|
||||||
sea.SetAddress(&sender)
|
sea.SetAddress(&sender)
|
||||||
sr.SetEmailAddress(sea)
|
sr.SetEmailAddress(sea)
|
||||||
msg.SetSender(sr)
|
msg.SetSender(sr)
|
||||||
@ -92,6 +116,8 @@ func (suite *MessageSuite) TestMessageInfo() {
|
|||||||
Sender: sender,
|
Sender: sender,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Received: now,
|
Received: now,
|
||||||
|
Created: initial,
|
||||||
|
Modified: initial,
|
||||||
}
|
}
|
||||||
return msg, i
|
return msg, i
|
||||||
},
|
},
|
||||||
|
|||||||
@ -302,6 +302,8 @@ type ExchangeInfo struct {
|
|||||||
Organizer string `json:"organizer,omitempty"`
|
Organizer string `json:"organizer,omitempty"`
|
||||||
ContactName string `json:"contactName,omitempty"`
|
ContactName string `json:"contactName,omitempty"`
|
||||||
EventRecurs bool `json:"eventRecurs,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
|
// Headers returns the human-readable names of properties in an ExchangeInfo
|
||||||
@ -338,7 +340,10 @@ func (i ExchangeInfo) Values() []string {
|
|||||||
return []string{i.ContactName}
|
return []string{i.ContactName}
|
||||||
|
|
||||||
case ExchangeMail:
|
case ExchangeMail:
|
||||||
return []string{i.Sender, i.Subject, common.FormatTabularDisplayTime(i.Received)}
|
return []string{
|
||||||
|
i.Sender, i.Subject,
|
||||||
|
common.FormatTabularDisplayTime(i.Received),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{}
|
return []string{}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package details_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -24,7 +25,8 @@ func TestDetailsUnitSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||||
nowStr := common.FormatNow(common.TabularOutput)
|
initial := time.Now()
|
||||||
|
nowStr := common.FormatTimeWith(initial, common.TabularOutput)
|
||||||
now, err := common.ParseTime(nowStr)
|
now, err := common.ParseTime(nowStr)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user