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

Commit

Permalink
Updates to /connector/sharepoint/restore.go
Browse files Browse the repository at this point in the history
Issue #2169: Publish API added to restore of Page Item.
  • Loading branch information
dadams39 committed Jan 22, 2023
1 parent 607ca83 commit ca641e0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/internal/connector/sharepoint/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime/trace"

"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
"github.com/microsoftgraph/msgraph-beta-sdk-go/sites"
"github.com/pkg/errors"

"github.com/alcionai/corso/src/internal/connector/graph"
Expand Down Expand Up @@ -283,6 +284,7 @@ func restoreSitePage(
var (
dii = details.ItemInfo{}
pageName = itemData.UUID()
pageURL string
)

byteArray, err := io.ReadAll(itemData.ToReader())
Expand All @@ -296,6 +298,8 @@ func restoreSitePage(
return dii, errors.Wrapf(err, "failed to create Page object %s", pageName)
}

// POST the Publish
// https://learn.microsoft.com/en-us/graph/api/sitepage-create?view=graph-rest-beta
restoredPage, err := service.Client().SitesById(siteID).Pages().Post(ctx, page, nil)
if err != nil {
sendErr := support.ConnectorStackErrorTraceWrap(
Expand All @@ -306,6 +310,23 @@ func restoreSitePage(
return dii, sendErr
}

// Publish page to make visible
// See https://learn.microsoft.com/en-us/graph/api/sitepage-publish?view=graph-rest-beta
if restoredPage.GetWebUrl() == nil {
return dii, fmt.Errorf("created page %s did not return webURL from API", *restoredPage.GetId())
}

pageURL = *restoredPage.GetWebUrl()
publishRequest := sites.NewItemPagesItemPublishRequestBuilder(pageURL, service.Adapter())

err = publishRequest.Post(ctx, nil)
if err != nil {
return dii, support.ConnectorStackErrorTraceWrap(
err,
"unable to publish page ID: "+*restoredPage.GetId()+" API Error Details",
)
}

dii.SharePoint = sharePointPageInfo(restoredPage, int64(len(byteArray)))

return dii, nil
Expand Down

0 comments on commit ca641e0

Please sign in to comment.