allow space home update and its children pages (#101)

* allow space home update and its children pages

* fix coding styling

* fix coding styling

* codestyle: fix checking isHomepage

* codestyle: fix checking skipHomeAncestry

Co-authored-by: Hugo Cisneiros (Eitch) <hugo.cisneiros@ifood.com.br>
Co-authored-by: Egor Kovetskiy <e.kovetskiy@gmail.com>
This commit is contained in:
Hugo Cisneiros
2021-08-23 03:42:31 -03:00
committed by GitHub
parent 11e7e82671
commit 97313e59e1
3 changed files with 68 additions and 11 deletions

View File

@@ -104,11 +104,26 @@ func ValidateAncestry(
return nil, nil
}
isHomepage := false
if len(page.Ancestors) < 1 {
return nil, fmt.Errorf(`page %q has no parents`, page.Title)
homepage, err := api.FindHomePage(space)
if err != nil {
return nil, karma.Format(
err,
"can't obtain home page from space %q",
space,
)
}
if page.ID == homepage.ID {
log.Debugf(nil, "page is homepage for space %q", space)
isHomepage = true
} else {
return nil, fmt.Errorf(`page %q has no parents`, page.Title)
}
}
if len(page.Ancestors) < len(ancestry) {
if !isHomepage && len(page.Ancestors) < len(ancestry) {
actual := []string{}
for _, ancestor := range page.Ancestors {
actual = append(actual, ancestor.Title)

View File

@@ -32,8 +32,25 @@ func ResolvePage(
return nil, page, nil
}
// check to see if home page is in Parents
homepage, err := api.FindHomePage(meta.Space)
if err != nil {
return nil, nil, karma.Format(
err,
"can't obtain home page from space %q",
meta.Space,
)
}
skipHomeAncestry := false
if len(meta.Parents) > 0 {
if homepage.Title == meta.Parents[0] {
skipHomeAncestry = true
}
}
ancestry := meta.Parents
if page != nil {
if page != nil && !skipHomeAncestry {
ancestry = append(ancestry, page.Title)
}