mirror of
https://github.com/kovetskiy/mark.git
synced 2025-06-08 23:42:40 +08:00
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:
parent
11e7e82671
commit
97313e59e1
@ -30,6 +30,18 @@ type API struct {
|
|||||||
BaseURL string
|
BaseURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SpaceInfo struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
Homepage PageInfo `json:"homepage"`
|
||||||
|
|
||||||
|
Links struct {
|
||||||
|
Full string `json:"webui"`
|
||||||
|
} `json:"_links"`
|
||||||
|
}
|
||||||
|
|
||||||
type PageInfo struct {
|
type PageInfo struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@ -122,6 +134,26 @@ func (api *API) FindRootPage(space string) (*PageInfo, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) FindHomePage(space string) (*PageInfo, error) {
|
||||||
|
payload := map[string]string{
|
||||||
|
"expand": "homepage",
|
||||||
|
}
|
||||||
|
|
||||||
|
request, err := api.rest.Res(
|
||||||
|
"space/"+space, &SpaceInfo{},
|
||||||
|
).Get(payload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if request.Raw.StatusCode == 404 || request.Raw.StatusCode != 200 {
|
||||||
|
return nil, newErrorStatusNotOK(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &request.Response.(*SpaceInfo).Homepage, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) FindPage(space string, title string, pageType string) (*PageInfo, error) {
|
func (api *API) FindPage(space string, title string, pageType string) (*PageInfo, error) {
|
||||||
result := struct {
|
result := struct {
|
||||||
Results []PageInfo `json:"results"`
|
Results []PageInfo `json:"results"`
|
||||||
@ -442,14 +474,7 @@ func (api *API) UpdatePage(
|
|||||||
nextPageVersion := page.Version.Number + 1
|
nextPageVersion := page.Version.Number + 1
|
||||||
oldAncestors := []map[string]interface{}{}
|
oldAncestors := []map[string]interface{}{}
|
||||||
|
|
||||||
if page.Type != "blogpost" {
|
if page.Type != "blogpost" && len(page.Ancestors) > 0 {
|
||||||
if len(page.Ancestors) == 0 {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"page %q info does not contain any information about parents",
|
|
||||||
page.ID,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// picking only the last one, which is required by confluence
|
// picking only the last one, which is required by confluence
|
||||||
oldAncestors = []map[string]interface{}{
|
oldAncestors = []map[string]interface{}{
|
||||||
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
||||||
|
@ -104,11 +104,26 @@ func ValidateAncestry(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isHomepage := false
|
||||||
if len(page.Ancestors) < 1 {
|
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{}
|
actual := []string{}
|
||||||
for _, ancestor := range page.Ancestors {
|
for _, ancestor := range page.Ancestors {
|
||||||
actual = append(actual, ancestor.Title)
|
actual = append(actual, ancestor.Title)
|
||||||
|
@ -32,8 +32,25 @@ func ResolvePage(
|
|||||||
return nil, page, nil
|
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
|
ancestry := meta.Parents
|
||||||
if page != nil {
|
if page != nil && !skipHomeAncestry {
|
||||||
ancestry = append(ancestry, page.Title)
|
ancestry = append(ancestry, page.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user