Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

get details working (and other cleanup) #5116

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cli/backup/teamschats.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ func runDetailsTeamsChatsCmd(cmd *cobra.Command) error {
opts := utils.MakeTeamsChatsOpts(cmd)

sel := utils.IncludeTeamsChatsRestoreDataSelectors(ctx, opts)
sel.Configure(selectors.Config{OnlyMatchItemNames: true})
utils.FilterTeamsChatsRestoreInfoSelectors(sel, opts)

ds, err := genericDetailsCommand(cmd, flags.BackupIDFV, sel.Selector)
Expand Down
5 changes: 4 additions & 1 deletion src/cli/utils/teamschats.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func IncludeTeamsChatsRestoreDataSelectors(ctx context.Context, opts TeamsChatsO
users = selectors.Any()
}

return selectors.NewTeamsChatsRestore(users)
sel := selectors.NewTeamsChatsRestore(users)
sel.Include(sel.Chats(selectors.Any()))

return sel
}

// FilterTeamsChatsRestoreInfoSelectors builds the common info-selector filters.
Expand Down
5 changes: 1 addition & 4 deletions src/internal/m365/collection/teamschats/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ func populateCollection[I chatsItemer](
)

ctx = clues.AddLabelCounter(ctx, cl.PlainAdder())
cc := api.CallConfig{
CanMakeDeltaQueries: false,
}

items, err := bh.getItemIDs(ctx, cc)
items, err := bh.getItemIDs(ctx)
if err != nil {
errs.AddRecoverable(ctx, clues.Stack(err))
return collection, clues.Stack(errs.Failure()).OrNil()
Expand Down
9 changes: 0 additions & 9 deletions src/internal/m365/collection/teamschats/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ type mockBackupHandler struct {
doNotInclude bool
}

//lint:ignore U1000 false linter issue due to generics
func (bh mockBackupHandler) augmentItemInfo(
*details.TeamsChatsInfo,
models.Chatable,
) {
// no-op
}

func (bh mockBackupHandler) container() container[models.Chatable] {
return chatContainer()
}
Expand All @@ -71,7 +63,6 @@ func (bh mockBackupHandler) getContainer(

func (bh mockBackupHandler) getItemIDs(
_ context.Context,
_ api.CallConfig,
) ([]models.Chatable, error) {
return bh.chats, bh.chatsErr
}
Expand Down
24 changes: 11 additions & 13 deletions src/internal/m365/collection/teamschats/chat_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func (bh usersChatsBackupHandler) getContainer(
//lint:ignore U1000 required for interface compliance
func (bh usersChatsBackupHandler) getItemIDs(
ctx context.Context,
cc api.CallConfig,
) ([]models.Chatable, error) {
cc := api.CallConfig{
Expand: []string{"lastMessagePreview"},
}

return bh.ac.GetChats(
ctx,
bh.protectedResourceID,
Expand Down Expand Up @@ -89,28 +92,23 @@ func (bh usersChatsBackupHandler) getItem(

chatID := ptr.Val(chat.GetId())

cc := api.CallConfig{
Expand: []string{"lastMessagePreview"},
msgs, err := bh.ac.GetChatMessages(ctx, chatID, api.CallConfig{})
if err != nil {
return nil, nil, clues.Stack(err)
}

msgs, err := bh.ac.GetChatMessages(ctx, chatID, cc)
chat.SetMessages(msgs)

members, err := bh.ac.GetChatMembers(ctx, chatID, api.CallConfig{})
if err != nil {
return nil, nil, clues.Stack(err)
}

chat.SetMessages(msgs)
chat.SetMembers(members)

return chat, api.TeamsChatInfo(chat), nil
}

//lint:ignore U1000 false linter issue due to generics
func (bh usersChatsBackupHandler) augmentItemInfo(
dgi *details.TeamsChatsInfo,
c models.Chatable,
) {
// no-op
}

func chatContainer() container[models.Chatable] {
return container[models.Chatable]{
storageDirFolders: path.Elements{},
Expand Down
38 changes: 18 additions & 20 deletions src/internal/m365/collection/teamschats/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func updateStatus(
// or notMoved (if they match).
func NewCollection[I chatsItemer](
baseCol data.BaseCollection,
getAndAugment getItemAndAugmentInfoer[I],
getter getItemer[I],
protectedResource string,
items []I,
contains container[I],
Expand All @@ -76,7 +76,7 @@ func NewCollection[I chatsItemer](
BaseCollection: baseCol,
items: items,
contains: contains,
getAndAugment: getAndAugment,
getter: getter,
statusUpdater: statusUpdater,
stream: make(chan data.Item, collectionChannelBufferSize),
protectedResource: protectedResource,
Expand All @@ -96,7 +96,7 @@ type lazyFetchCollection[I chatsItemer] struct {

items []I

getAndAugment getItemAndAugmentInfoer[I]
getter getItemer[I]

statusUpdater support.StatusUpdater
}
Expand Down Expand Up @@ -167,13 +167,13 @@ func (col *lazyFetchCollection[I]) streamItems(ctx context.Context, errs *fault.
col.stream <- data.NewLazyItemWithInfo(
ictx,
&lazyItemGetter[I]{
modTime: modTime,
getAndAugment: col.getAndAugment,
resourceID: col.protectedResource,
item: item,
containerIDs: col.FullPath().Folders(),
contains: col.contains,
parentPath: col.LocationPath().String(),
modTime: modTime,
getter: col.getter,
resourceID: col.protectedResource,
item: item,
containerIDs: col.FullPath().Folders(),
contains: col.contains,
parentPath: col.LocationPath().String(),
},
itemID,
modTime,
Expand All @@ -192,13 +192,13 @@ func (col *lazyFetchCollection[I]) streamItems(ctx context.Context, errs *fault.
}

type lazyItemGetter[I chatsItemer] struct {
getAndAugment getItemAndAugmentInfoer[I]
resourceID string
item I
parentPath string
containerIDs path.Elements
modTime time.Time
contains container[I]
getter getItemer[I]
resourceID string
item I
parentPath string
containerIDs path.Elements
modTime time.Time
contains container[I]
}

func (lig *lazyItemGetter[I]) GetData(
Expand All @@ -208,7 +208,7 @@ func (lig *lazyItemGetter[I]) GetData(
writer := kjson.NewJsonSerializationWriter()
defer writer.Close()

item, info, err := lig.getAndAugment.getItem(
item, info, err := lig.getter.getItem(
ctx,
lig.resourceID,
lig.item)
Expand All @@ -229,8 +229,6 @@ func (lig *lazyItemGetter[I]) GetData(
return nil, nil, false, err
}

lig.getAndAugment.augmentItemInfo(info, lig.contains.container)

if err := writer.WriteObjectValue("", item); err != nil {
err = clues.WrapWC(ctx, err, "writing item to serializer").Label(fault.LabelForceNoBackupCreation)
errs.AddRecoverable(ctx, err)
Expand Down
37 changes: 16 additions & 21 deletions src/internal/m365/collection/teamschats/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ func (m getAndAugmentChat) getItem(
return chat, &details.TeamsChatsInfo{}, m.err
}

//lint:ignore U1000 false linter issue due to generics
func (getAndAugmentChat) augmentItemInfo(*details.TeamsChatsInfo, models.Chatable) {
// no-op
}

func (suite *CollectionUnitSuite) TestLazyFetchCollection_Items_LazyFetch() {
var (
t = suite.T()
Expand Down Expand Up @@ -225,7 +220,7 @@ func (suite *CollectionUnitSuite) TestLazyFetchCollection_Items_LazyFetch() {
count.New()),
items: test.items,
contains: container[models.Chatable]{},
getAndAugment: getterAugmenter,
getter: getterAugmenter,
stream: make(chan data.Item),
statusUpdater: statusUpdater,
}
Expand Down Expand Up @@ -285,11 +280,11 @@ func (suite *CollectionUnitSuite) TestLazyItem_GetDataErrors() {
li := data.NewLazyItemWithInfo(
ctx,
&lazyItemGetter[models.Chatable]{
resourceID: "resourceID",
item: chat,
getAndAugment: &m,
modTime: now,
parentPath: parentPath,
resourceID: "resourceID",
item: chat,
getter: &m,
modTime: now,
parentPath: parentPath,
},
ptr.Val(chat.GetId()),
now,
Expand Down Expand Up @@ -329,11 +324,11 @@ func (suite *CollectionUnitSuite) TestLazyItem_ReturnsEmptyReaderOnDeletedInFlig
li := data.NewLazyItemWithInfo(
ctx,
&lazyItemGetter[models.Chatable]{
resourceID: "resourceID",
item: chat,
getAndAugment: &m,
modTime: now,
parentPath: parentPath,
resourceID: "resourceID",
item: chat,
getter: &m,
modTime: now,
parentPath: parentPath,
},
ptr.Val(chat.GetId()),
now,
Expand Down Expand Up @@ -368,11 +363,11 @@ func (suite *CollectionUnitSuite) TestLazyItem() {
li := data.NewLazyItemWithInfo(
ctx,
&lazyItemGetter[models.Chatable]{
resourceID: "resourceID",
item: chat,
getAndAugment: &m,
modTime: now,
parentPath: parentPath,
resourceID: "resourceID",
item: chat,
getter: &m,
modTime: now,
parentPath: parentPath,
},
ptr.Val(chat.GetId()),
now,
Expand Down
14 changes: 1 addition & 13 deletions src/internal/m365/collection/teamschats/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

type backupHandler[I chatsItemer] interface {
getContainerer[I]
getItemAndAugmentInfoer[I]
getItemer[I]
getItemer[I]
getItemIDser[I]
includeItemer[I]
Expand All @@ -39,22 +39,10 @@
) (container[I], error)
}

type getItemAndAugmentInfoer[I chatsItemer] interface {
getItemer[I]
augmentItemInfoer[I]
}

type augmentItemInfoer[I chatsItemer] interface {
// augmentItemInfo completes the teamChatsInfo population with any data
// owned by the container and not accessible to the item.
augmentItemInfo(*details.TeamsChatsInfo, I)
}

// gets all item IDs in the container
type getItemIDser[I chatsItemer] interface {
getItemIDs(
ctx context.Context,
cc api.CallConfig,
) ([]I, error)
}

Expand Down Expand Up @@ -89,5 +77,5 @@
type container[I chatsItemer] struct {
storageDirFolders path.Elements
humanLocation path.Elements
container I

Check failure on line 80 in src/internal/m365/collection/teamschats/handlers.go

View workflow job for this annotation

GitHub Actions / Source-Code-Linting

field `container` is unused (unused)
}
56 changes: 28 additions & 28 deletions src/pkg/backup/details/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (de Entry) ToLocationIDer(backupVersion int) (LocationIDer, error) {
}

baseLoc = path.Builder{}.Append(p.Root).Append(p.Folders...)

case TeamsChat:
baseLoc = &path.Builder{}

default:
return nil, clues.New("undentified item type").With("item_type", de.ItemInfo.infoType())
}

if baseLoc == nil {
Expand Down Expand Up @@ -141,26 +147,23 @@ func (de Entry) MinimumPrintable() any {
// Headers returns the human-readable names of properties in a DetailsEntry
// for printing out to a terminal in a columnar display.
func (de Entry) Headers(skipID bool) []string {
hs := []string{}
var hs []string

if de.ItemInfo.Folder != nil {
switch {
case de.ItemInfo.Folder != nil:
hs = de.ItemInfo.Folder.Headers()
}

if de.ItemInfo.Exchange != nil {
case de.ItemInfo.Exchange != nil:
hs = de.ItemInfo.Exchange.Headers()
}

if de.ItemInfo.SharePoint != nil {
case de.ItemInfo.SharePoint != nil:
hs = de.ItemInfo.SharePoint.Headers()
}

if de.ItemInfo.OneDrive != nil {
case de.ItemInfo.OneDrive != nil:
hs = de.ItemInfo.OneDrive.Headers()
}

if de.ItemInfo.Groups != nil {
case de.ItemInfo.Groups != nil:
hs = de.ItemInfo.Groups.Headers()
case de.ItemInfo.TeamsChats != nil:
hs = de.ItemInfo.TeamsChats.Headers()
default:
hs = []string{"ERROR - Service not recognized"}
}

if skipID {
Expand All @@ -172,26 +175,23 @@ func (de Entry) Headers(skipID bool) []string {

// Values returns the values matching the Headers list.
func (de Entry) Values(skipID bool) []string {
vs := []string{}
var vs []string

if de.ItemInfo.Folder != nil {
switch {
case de.ItemInfo.Folder != nil:
vs = de.ItemInfo.Folder.Values()
}

if de.ItemInfo.Exchange != nil {
case de.ItemInfo.Exchange != nil:
vs = de.ItemInfo.Exchange.Values()
}

if de.ItemInfo.SharePoint != nil {
case de.ItemInfo.SharePoint != nil:
vs = de.ItemInfo.SharePoint.Values()
}

if de.ItemInfo.OneDrive != nil {
case de.ItemInfo.OneDrive != nil:
vs = de.ItemInfo.OneDrive.Values()
}

if de.ItemInfo.Groups != nil {
case de.ItemInfo.Groups != nil:
vs = de.ItemInfo.Groups.Values()
case de.ItemInfo.TeamsChats != nil:
vs = de.ItemInfo.TeamsChats.Values()
default:
vs = []string{"ERROR - Service not recognized"}
}

if skipID {
Expand Down
Loading
Loading