Skip to content

Commit fc18646

Browse files
authored
Confluence: page_exists method update (#949)
page_exists() updated to make its own request and handle the response to return a True or False rather than utilising "self.get_page_by_title(space, title)" which outputs messages to the log if it cannot find a page.
1 parent 56d1d1f commit fc18646

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

atlassian/confluence.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,33 @@ def _get_paged(self, url, params=None, data=None, flags=None, trailing=None, abs
8686
return
8787

8888
def page_exists(self, space, title):
89+
"""
90+
Check if title exists as page.
91+
:param space: Space key
92+
:param title: Title of the page
93+
:return:
94+
"""
95+
url = "rest/api/content"
96+
params = {}
97+
if space is not None:
98+
params["spaceKey"] = str(space)
99+
if title is not None:
100+
params["title"] = str(title)
101+
89102
try:
90-
if self.get_page_by_title(space, title):
91-
log.info('Page "{title}" already exists in space "{space}"'.format(space=space, title=title))
92-
return True
93-
else:
94-
log.info("Page does not exist because did not find by title search")
95-
return False
96-
except (HTTPError, KeyError, IndexError):
97-
log.info('Page "{title}" does not exist in space "{space}"'.format(space=space, title=title))
103+
response = self.get(url, params=params)
104+
except HTTPError as e:
105+
if e.response.status_code == 404:
106+
raise ApiPermissionError(
107+
"The calling user does not have permission to view the content",
108+
reason=e,
109+
)
110+
111+
raise
112+
113+
if response.get("results"):
114+
return True
115+
else:
98116
return False
99117

100118
def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):

0 commit comments

Comments
 (0)