Skip to content

Commit ca5ba15

Browse files
authored
Merge pull request #1142 from sphinx-contrib/support-v1-api-trample-detection
support documentation trample detection on data center
2 parents 0e186e4 + e686310 commit ca5ba15

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

sphinxcontrib/confluencebuilder/publisher.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,16 +1575,30 @@ def _check_allowed_page_update(self, page, parent_id):
15751575
# the new parent id is part of our documentation tree
15761576
detected_trample = False
15771577
while not self.trample and parent_id:
1578-
# if no parent, it lives on it's own
1579-
current_parent_id_str = page['parentId']
1580-
if not current_parent_id_str:
1581-
logger.verbose('(trample) detected no parent page')
1582-
detected_trample = True
1583-
break
1578+
page_ancestors = []
1579+
1580+
# if no parent, it lives on it's own; flag as trampling space
1581+
if self.api_mode == 'v2':
1582+
current_parent_id_str = page.get('parentId')
1583+
if not current_parent_id_str:
1584+
logger.verbose('(trample) detected no parent page')
1585+
detected_trample = True
1586+
break
1587+
1588+
current_parent_id = int(current_parent_id_str)
1589+
else:
1590+
if 'ancestors' in page:
1591+
page_ancestors = [int(x['id']) for x in page['ancestors']]
1592+
1593+
if not page_ancestors:
1594+
logger.verbose('(trample) detected no parent page')
1595+
detected_trample = True
1596+
break
1597+
1598+
current_parent_id = page_ancestors[0]
15841599

15851600
# check if the parent page has been uploaded, indicating it is
15861601
# part of our current hierarchy
1587-
current_parent_id = int(current_parent_id_str)
15881602
if ConfluenceState.has_upload_id(current_parent_id):
15891603
break
15901604

@@ -1602,7 +1616,8 @@ def _check_allowed_page_update(self, page, parent_id):
16021616

16031617
# if the current page is under our base page, this is a contained
16041618
# page update
1605-
page_ancestors = self.get_ancestors(int(page['id']))
1619+
if not page_ancestors:
1620+
page_ancestors = self.get_ancestors(int(page['id']))
16061621
if int(base_page_id) in page_ancestors:
16071622
break
16081623

0 commit comments

Comments
 (0)