Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confluence: Add function get_all_pages_by_space_ids_confluence_cloud #1460

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions atlassian/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,73 @@

return response.get("results")

def get_all_pages_by_space_ids_confluence_cloud(
self,
space_ids,
batch_size=250,
sort=None,
status=None,
title=None,
body_format=None,
):
"""
Get all pages from a set of space ids:
https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-get

:param space_ids: A Set of space IDs passed as a filter to Confluence
:param batch_size: OPTIONAL: The batch size of pages to retrieve from confluence per request MAX is 250.
Default: 250
:param sort: OPTIONAL: The order the pages are retrieved in.
Valid values: id, -id, created-date, -created-date, modified-date, -modified-date, title, -title
:param status: OPTIONAL: Filter pages based on their status.
Valid values: current, archived, deleted, trashed
Default: current,archived
:param title: OPTIONAL: Filter pages based on their title.
:param body-format: OPTIONAL: The format of the body in the response. Valid values: storage, atlas_doc_format
:return:
"""
path = "/api/v2/pages"
params = {}

Check warning on line 721 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L720-L721

Added lines #L720 - L721 were not covered by tests
if space_ids:
params["space-id"] = ",".join(space_ids)

Check warning on line 723 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L723

Added line #L723 was not covered by tests
if batch_size:
params["limit"] = batch_size

Check warning on line 725 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L725

Added line #L725 was not covered by tests
if sort:
params["sort"] = sort

Check warning on line 727 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L727

Added line #L727 was not covered by tests
if status:
params["status"] = status

Check warning on line 729 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L729

Added line #L729 was not covered by tests
if title:
params["title"] = title

Check warning on line 731 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L731

Added line #L731 was not covered by tests
if body_format:
params["body-format"] = body_format

Check warning on line 733 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L733

Added line #L733 was not covered by tests

_all_pages = []
try:
while True:
response = self.get(path, params=params)

Check warning on line 738 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L735-L738

Added lines #L735 - L738 were not covered by tests

pages = response.get("results")
_all_pages = _all_pages + pages

Check warning on line 741 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L740-L741

Added lines #L740 - L741 were not covered by tests

links = response.get("_links")

Check warning on line 743 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L743

Added line #L743 was not covered by tests
if links is not None and "next" in links:
path = response["_links"]["next"].removeprefix("/wiki/")
params = {}

Check warning on line 746 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L745-L746

Added lines #L745 - L746 were not covered by tests
else:
break
except HTTPError as e:

Check warning on line 749 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L748-L749

Added lines #L748 - L749 were not covered by tests
if e.response.status_code == 400:
raise ApiValueError(

Check warning on line 751 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L751

Added line #L751 was not covered by tests
"The configured params cannot be interpreted by Confluence"
"Check the api documentation for valid values for status, expand, and sort params",
reason=e,
)
if e.response.status_code == 401:
raise HTTPError("Unauthorized (401)", response=response)
raise

Check warning on line 758 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L757-L758

Added lines #L757 - L758 were not covered by tests

return _all_pages

Check warning on line 760 in atlassian/confluence.py

View check run for this annotation

Codecov / codecov/patch

atlassian/confluence.py#L760

Added line #L760 was not covered by tests

@deprecated(version="2.4.2", reason="Use get_all_restrictions_for_content()")
def get_all_restictions_for_content(self, content_id):
"""Let's use the get_all_restrictions_for_content()"""
Expand Down