Compare commits
110 Commits
main
...
sanitize-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f25447b3e | ||
|
|
c1b1d4bc2d | ||
|
|
3b2e1ecdc2 | ||
|
|
72ff596d2a | ||
|
|
4b001a20a1 | ||
|
|
8d5ee37c53 | ||
|
|
aafc9c73f9 | ||
|
|
341878b6e3 | ||
|
|
aca2fd2bfb | ||
|
|
57ce0be82a | ||
|
|
b3aec1b40f | ||
|
|
f8d65d66de | ||
|
|
817a7a2bc6 | ||
|
|
2839d8d6e3 | ||
|
|
05c3216f08 | ||
|
|
8a474af189 | ||
|
|
b7b2de096b | ||
|
|
03ec1dd2e9 | ||
|
|
7bc080305d | ||
|
|
28ddbca41e | ||
|
|
263197bbab | ||
|
|
4e3f15f357 | ||
|
|
68f7ac9cff | ||
|
|
bcd379f596 | ||
|
|
aca2eb5d65 | ||
|
|
2f02efe489 | ||
|
|
3e4fae6a56 | ||
|
|
775f5ce4e3 | ||
|
|
a31fe596af | ||
|
|
f33167d765 | ||
|
|
8f22c4f776 | ||
|
|
9dc487b39f | ||
|
|
9bbb479fa3 | ||
|
|
dc09508821 | ||
|
|
918fd835ad | ||
|
|
42a9499b71 | ||
|
|
740c8dc3e2 | ||
|
|
d2fb427146 | ||
|
|
4fdd165afd | ||
|
|
76cc59348a | ||
|
|
9a0dd673c6 | ||
|
|
b4118627a6 | ||
|
|
a51b6e8444 | ||
|
|
1acc6b9e18 | ||
|
|
9a6d58b18c | ||
|
|
b27ce3d0e2 | ||
|
|
f5d514470d | ||
|
|
0a1e0d249f | ||
|
|
b1f7ab51e9 | ||
|
|
b13f5b6fb6 | ||
|
|
e51f654e46 | ||
|
|
50da437421 | ||
|
|
1d13f7d2df | ||
|
|
e9371379a6 | ||
|
|
ae69293fa6 | ||
|
|
66e560987e | ||
|
|
c3fd313a82 | ||
|
|
2d73ed3a6b | ||
|
|
988962c06e | ||
|
|
5368cd38cf | ||
|
|
2a93dc9caf | ||
|
|
ea70fa6eee | ||
|
|
c7828db7d6 | ||
|
|
a090bed081 | ||
|
|
702ec7f234 | ||
|
|
c221d388b1 | ||
|
|
4853d6c0ce | ||
|
|
2f9f61b4a6 | ||
|
|
a22803e077 | ||
|
|
10c605d02b | ||
|
|
63d2d7f4d8 | ||
|
|
2fc8b36070 | ||
|
|
ec87d58078 | ||
|
|
5414c71581 | ||
|
|
156e01b8dd | ||
|
|
0b7d22581b | ||
|
|
d22d943bef | ||
|
|
8f556c59a4 | ||
|
|
f44607ca73 | ||
|
|
898191f9a9 | ||
|
|
c0112d917e | ||
|
|
f425d24364 | ||
|
|
2f125d44a6 | ||
|
|
2cd64c4775 | ||
|
|
b4eae746c4 | ||
|
|
9b30a03c31 | ||
|
|
77c3b3b7d7 | ||
|
|
4009a5c2d4 | ||
|
|
4687b134ef | ||
|
|
2929c9f25e | ||
|
|
7404c4c8b0 | ||
|
|
135c07a41a | ||
|
|
3ccdda8ef0 | ||
|
|
4952b81333 | ||
|
|
b82a6349f4 | ||
|
|
519a449b2f | ||
|
|
97ca692168 | ||
|
|
7ef73b866a | ||
|
|
613de30664 | ||
|
|
0802e97d56 | ||
|
|
d661d45671 | ||
|
|
0cf21f6b2c | ||
|
|
4c000c816d | ||
|
|
29bb06e779 | ||
|
|
6b1e84732e | ||
|
|
39155c68fa | ||
|
|
287dcd6930 | ||
|
|
a9421d7195 | ||
|
|
0a111cd9df | ||
|
|
58ad917d4c |
@ -7,8 +7,12 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
msmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
kioser "github.com/microsoft/kiota-serialization-json-go"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||
discover "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||
"github.com/alcionai/corso/src/internal/connector/graph/betasdk/models"
|
||||
@ -19,6 +23,11 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
)
|
||||
|
||||
const (
|
||||
textWebPartType = "#microsoft.graph.textWebPart"
|
||||
standardWebPartType = "#microsoft.graph.standardWebPart"
|
||||
)
|
||||
|
||||
// GetSitePages retrieves a collection of Pages related to the give Site.
|
||||
// Returns error if error experienced during the call
|
||||
func GetSitePages(
|
||||
@ -171,9 +180,8 @@ func RestoreSitePage(
|
||||
defer end()
|
||||
|
||||
var (
|
||||
dii = details.ItemInfo{}
|
||||
pageID = itemData.UUID()
|
||||
pageName = pageID
|
||||
dii = details.ItemInfo{}
|
||||
pageID = itemData.UUID()
|
||||
)
|
||||
|
||||
byteArray, err := io.ReadAll(itemData.ToReader())
|
||||
@ -187,23 +195,35 @@ func RestoreSitePage(
|
||||
return dii, errors.Wrapf(err, "creating Page object %s", pageID)
|
||||
}
|
||||
|
||||
pageNamePtr := page.GetName()
|
||||
if pageNamePtr != nil {
|
||||
pageName = *pageNamePtr
|
||||
pageName := ptr.Val(page.GetName())
|
||||
if len(pageName) == 0 {
|
||||
pageName = pageID
|
||||
}
|
||||
|
||||
newName := fmt.Sprintf("%s_%s", destName, pageName)
|
||||
page.SetName(&newName)
|
||||
pg := sanitize(page, newName)
|
||||
|
||||
wtr := kioser.NewJsonSerializationWriter()
|
||||
err = wtr.WriteObjectValue("", pg)
|
||||
byteArray, err = wtr.GetSerializedContent()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("What happened")
|
||||
}
|
||||
fmt.Printf("Page\n %+v\n", string(byteArray))
|
||||
|
||||
fmt.Printf("Layout: %+v\n", pg.GetCanvasLayout())
|
||||
|
||||
// Restore is a 2-Step Process in Graph API
|
||||
// 1. Create the Page on the site
|
||||
// 2. Publish the site
|
||||
// See: 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)
|
||||
restoredPage, err := service.Client().SitesById(siteID).Pages().Post(ctx, pg, nil)
|
||||
if err != nil {
|
||||
sendErr := support.ConnectorStackErrorTraceWrap(
|
||||
err,
|
||||
"creating page from ID: %s"+pageName+" API Error Details",
|
||||
"creating page: "+pageName+" API Error Details",
|
||||
)
|
||||
|
||||
return dii, sendErr
|
||||
@ -235,6 +255,182 @@ func RestoreSitePage(
|
||||
return dii, nil
|
||||
}
|
||||
|
||||
// sanitize removes all unique M365IDs from the SitePage data type.
|
||||
func sanitize(orig models.SitePageable, newName string) *models.SitePage {
|
||||
newPage := models.NewSitePage()
|
||||
|
||||
layout := sanitizeCanvasLayout(orig.GetCanvasLayout())
|
||||
newPage.SetCanvasLayout(layout)
|
||||
|
||||
ct := sanitizeContentType(orig.GetContentType())
|
||||
newPage.SetContentType(ct)
|
||||
newPage.SetContentType(ct)
|
||||
// Skip CreatedBy.., ..ByUser, ..DateTime
|
||||
newPage.SetDescription(orig.GetDescription())
|
||||
// skip Etag, ID, lastModified
|
||||
// skip ID
|
||||
// skip lastModified -> it will be the app
|
||||
newPage.SetName(orig.GetName())
|
||||
newPage.SetPageLayout(orig.GetPageLayout())
|
||||
// Parent skipped
|
||||
newPage.SetPromotionKind(nil)
|
||||
// Skip publishing state. Page will attempt to be published during restore
|
||||
newPage.SetReactions(orig.GetReactions())
|
||||
newPage.SetShowComments(nil)
|
||||
newPage.SetShowRecommendedPages(nil)
|
||||
newPage.SetThumbnailWebUrl(nil)
|
||||
newPage.SetTitle(orig.GetTitle())
|
||||
// Skip TitleArea due to Upstream Failure
|
||||
// https://github.com/microsoftgraph/msgraph-metadata/issues/258
|
||||
newPage.SetTitleArea(nil)
|
||||
|
||||
wp := make([]models.WebPartable, 0)
|
||||
for _, entry := range orig.GetWebParts() {
|
||||
temp := sanitizeWebPart(entry)
|
||||
wp = append(wp, temp)
|
||||
}
|
||||
|
||||
newPage.SetWebParts(wp)
|
||||
// webURL intentionally left
|
||||
|
||||
return newPage
|
||||
}
|
||||
|
||||
func sanitizeContentType(orig msmodels.ContentTypeInfoable) msmodels.ContentTypeInfoable {
|
||||
if orig == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ct := msmodels.NewContentTypeInfo()
|
||||
ct.SetName(orig.GetName())
|
||||
ct.SetOdataType(orig.GetOdataType())
|
||||
|
||||
return ct
|
||||
}
|
||||
|
||||
func sanitizeCanvasLayout(orig models.CanvasLayoutable) models.CanvasLayoutable {
|
||||
canvas := models.NewCanvasLayout()
|
||||
vert := sanitizeVertical(orig.GetVerticalSection())
|
||||
|
||||
canvas.SetVerticalSection(vert)
|
||||
hzLayouts := make([]models.HorizontalSectionable, 0)
|
||||
sections := orig.GetHorizontalSections()
|
||||
|
||||
for _, entry := range sections {
|
||||
temp := sanitizeHorizontal(entry)
|
||||
|
||||
hzLayouts = append(hzLayouts, temp)
|
||||
}
|
||||
|
||||
canvas.SetHorizontalSections(hzLayouts)
|
||||
canvas.SetHorizontalSections(nil)
|
||||
|
||||
return canvas
|
||||
}
|
||||
|
||||
func sanitizeVertical(orig models.VerticalSectionable) models.VerticalSectionable {
|
||||
if orig == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
section := models.NewVerticalSection()
|
||||
wps := make([]models.WebPartable, 0)
|
||||
|
||||
for _, item := range orig.GetWebparts() {
|
||||
temp := sanitizeWebPart(item)
|
||||
wps = append(wps, temp)
|
||||
}
|
||||
|
||||
section.SetWebparts(wps)
|
||||
section.SetEmphasis(orig.GetEmphasis())
|
||||
section.SetOdataType(orig.GetOdataType())
|
||||
|
||||
return section
|
||||
}
|
||||
|
||||
func sanitizeHorizontal(orig models.HorizontalSectionable) models.HorizontalSectionable {
|
||||
newColumns := make([]models.HorizontalSectionColumnable, 0)
|
||||
temp := models.NewHorizontalSection()
|
||||
temp.SetEmphasis(orig.GetEmphasis())
|
||||
temp.SetLayout(orig.GetLayout())
|
||||
|
||||
for _, entry := range orig.GetColumns() {
|
||||
column := sanitizeColumn(entry)
|
||||
newColumns = append(newColumns, column)
|
||||
}
|
||||
|
||||
temp.SetColumns(newColumns)
|
||||
|
||||
return temp
|
||||
}
|
||||
|
||||
func sanitizeColumn(orig models.HorizontalSectionColumnable) models.HorizontalSectionColumnable {
|
||||
webparts := make([]models.WebPartable, 0)
|
||||
temp := models.NewHorizontalSectionColumn()
|
||||
temp.SetWidth(orig.GetWidth())
|
||||
|
||||
parts := orig.GetWebparts()
|
||||
for _, entry := range parts {
|
||||
wp := sanitizeWebPart(entry)
|
||||
webparts = append(webparts, wp)
|
||||
}
|
||||
|
||||
temp.SetWebparts(webparts)
|
||||
|
||||
return temp
|
||||
}
|
||||
|
||||
func sanitizeWebPart(orig models.WebPartable) models.WebPartable {
|
||||
fmt.Println(ptr.Val(orig.GetOdataType()))
|
||||
|
||||
category := ptr.Val(orig.GetOdataType())
|
||||
switch category {
|
||||
case textWebPartType:
|
||||
temp := models.NewTextWebPart()
|
||||
cast := orig.(models.TextWebPartable)
|
||||
temp.SetInnerHtml(cast.GetInnerHtml())
|
||||
temp.SetOdataType(cast.GetOdataType())
|
||||
|
||||
fmt.Println("Print Text Additional")
|
||||
printAdditional(cast.GetAdditionalData())
|
||||
fmt.Printf("WP: %+v\n", cast)
|
||||
|
||||
return temp
|
||||
|
||||
case standardWebPartType:
|
||||
temp := models.NewStandardWebPart()
|
||||
cast := orig.(models.StandardWebPartable)
|
||||
adtl := cast.GetAdditionalData()
|
||||
|
||||
fmt.Println("Print Standard Additional")
|
||||
printAdditional(adtl)
|
||||
temp.SetData(cast.GetData())
|
||||
temp.SetOdataType(cast.GetOdataType())
|
||||
temp.SetWebPartType(cast.GetWebPartType())
|
||||
fmt.Printf("TP: %+v\n", cast)
|
||||
|
||||
return temp
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func printAdditional(mapped map[string]any) {
|
||||
if mapped == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Length: %d\n", len(mapped))
|
||||
for key, value := range mapped {
|
||||
switch category := value.(type) {
|
||||
case int, string, bool:
|
||||
fmt.Printf("Key: %s Value: %+v", key, value)
|
||||
default:
|
||||
fmt.Printf("Key: %s Value Type: %v\n", key, category)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Helpers
|
||||
// ==============================
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user