atlassian-python-api 5.0.1__py3-none-any.whl → 5.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atlassian/VERSION +1 -1
- atlassian/__init__.py +13 -2
- atlassian/assets.py +10 -3
- atlassian/bamboo.py +178 -2
- atlassian/bitbucket/__init__.py +87 -1
- atlassian/bitbucket/base.py +9 -2
- atlassian/bitbucket/server/__init__.py +11 -0
- atlassian/cloud_admin.py +418 -0
- atlassian/confluence/__init__.py +9 -0
- atlassian/confluence/base.py +32 -10
- atlassian/confluence/cloud/__init__.py +19 -0
- atlassian/confluence/cloud/classification_levels.py +77 -0
- atlassian/confluence/cloud/cloud.py +43 -5
- atlassian/confluence/cloud/content_properties.py +71 -0
- atlassian/confluence/cloud/graphql.py +99 -0
- atlassian/confluence/server/__init__.py +274 -74
- atlassian/crowd.py +78 -0
- atlassian/jira/__init__.py +21 -0
- atlassian/jira/core_methods.py +11698 -0
- atlassian/jira/jira_cloud.py +160 -0
- atlassian/{jira.py → jira/jira_server.py} +333 -6
- atlassian/jira/service_management_methods.py +1381 -0
- atlassian/jira/software_methods.py +2114 -0
- atlassian/rest_client.py +26 -1
- atlassian/service_desk.py +10 -3
- atlassian/yogi/__init__.py +17 -0
- atlassian/yogi/base.py +11 -0
- atlassian/yogi/cloud.py +2367 -0
- atlassian/yogi/yogi_confluence_cloud.py +10 -0
- atlassian/yogi/yogi_confluence_dc.py +94 -0
- atlassian/yogi/yogi_jira_cloud.py +10 -0
- atlassian/yogi/yogi_jira_dc.py +64 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/METADATA +80 -10
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/RECORD +37 -22
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/WHEEL +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/top_level.txt +0 -0
|
@@ -8,6 +8,7 @@ import sys
|
|
|
8
8
|
import time
|
|
9
9
|
import warnings
|
|
10
10
|
from typing import cast
|
|
11
|
+
from urllib.parse import urljoin
|
|
11
12
|
|
|
12
13
|
import requests
|
|
13
14
|
from bs4 import BeautifulSoup
|
|
@@ -462,16 +463,23 @@ class Server(ConfluenceServerBase):
|
|
|
462
463
|
location=None,
|
|
463
464
|
depth=None,
|
|
464
465
|
):
|
|
465
|
-
"""
|
|
466
|
-
|
|
467
|
-
:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
:param
|
|
473
|
-
:param
|
|
474
|
-
|
|
466
|
+
"""Return a page's comments through the separate comments endpoint.
|
|
467
|
+
|
|
468
|
+
Comments are not included in :meth:`get_page_by_id`. To retrieve a
|
|
469
|
+
rendered comment body and author metadata, use
|
|
470
|
+
``expand='body.view,history,version'``. The initial author is available
|
|
471
|
+
in ``history.createdBy`` and the latest editor in ``version.by``.
|
|
472
|
+
|
|
473
|
+
:param content_id: Page/content ID
|
|
474
|
+
:param expand: Content expansions, for example
|
|
475
|
+
``body.view,history,version``. Inline-comment metadata can use
|
|
476
|
+
``extensions.inlineProperties,extensions.resolution``.
|
|
477
|
+
:param parent_version: Filter comments for a parent version
|
|
478
|
+
:param start: Page offset
|
|
479
|
+
:param limit: Number of comments per response page
|
|
480
|
+
:param location: ``inline`` to request inline comments
|
|
481
|
+
:param depth: Nested comment depth
|
|
482
|
+
:return: Paginated Confluence comment response
|
|
475
483
|
"""
|
|
476
484
|
params = {"id": content_id, "start": start, "limit": limit}
|
|
477
485
|
if expand:
|
|
@@ -622,6 +630,28 @@ class Server(ConfluenceServerBase):
|
|
|
622
630
|
url = f"rest/api/content/{content_id}/restriction/byOperation"
|
|
623
631
|
return self.get(url)
|
|
624
632
|
|
|
633
|
+
def set_restrictions_for_content(self, content_id, restrictions):
|
|
634
|
+
"""Set page or blog-post restrictions using the REST API.
|
|
635
|
+
|
|
636
|
+
``restrictions`` is a list of ContentRestriction objects. Each
|
|
637
|
+
supplied operation replaces its existing restrictions; operations not
|
|
638
|
+
present in the list are unchanged. Supplying an empty ``user`` or
|
|
639
|
+
``group`` list clears that subject type for the operation.
|
|
640
|
+
|
|
641
|
+
Example::
|
|
642
|
+
|
|
643
|
+
[{
|
|
644
|
+
"operation": "read",
|
|
645
|
+
"restrictions": {
|
|
646
|
+
"user": [{"type": "known", "username": "alice"}],
|
|
647
|
+
"group": [{"type": "group", "name": "engineering"}],
|
|
648
|
+
},
|
|
649
|
+
}]
|
|
650
|
+
"""
|
|
651
|
+
if not isinstance(restrictions, list):
|
|
652
|
+
raise ApiValueError("restrictions must be a list of ContentRestriction objects")
|
|
653
|
+
return self.put(f"rest/api/content/{content_id}/restriction", data=restrictions)
|
|
654
|
+
|
|
625
655
|
def get_all_restrictions_from_page_json_rpc(self, page_id):
|
|
626
656
|
"""
|
|
627
657
|
The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
|
|
@@ -830,6 +860,11 @@ class Server(ConfluenceServerBase):
|
|
|
830
860
|
try:
|
|
831
861
|
response = self.delete(f"rest/api/content/{content_id}")
|
|
832
862
|
except HTTPError as e:
|
|
863
|
+
if e.response.status_code == 403:
|
|
864
|
+
raise ApiPermissionError(
|
|
865
|
+
"The calling user does not have permission to trash or purge the content",
|
|
866
|
+
reason=e,
|
|
867
|
+
)
|
|
833
868
|
if e.response.status_code == 404:
|
|
834
869
|
# Raise ApiError as the documented reason is ambiguous
|
|
835
870
|
raise ApiError(
|
|
@@ -849,15 +884,21 @@ class Server(ConfluenceServerBase):
|
|
|
849
884
|
|
|
850
885
|
def remove_page(self, page_id, status=None, recursive=False):
|
|
851
886
|
"""
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
:param
|
|
855
|
-
:param
|
|
856
|
-
:
|
|
887
|
+
Remove a page and optionally its child pages.
|
|
888
|
+
|
|
889
|
+
:param page_id: page ID
|
|
890
|
+
:param status: optional content status (for example ``"trashed"``)
|
|
891
|
+
:param recursive: if True, remove child pages before this page
|
|
892
|
+
:return: the successful HTTP status code (normally ``204``). When the
|
|
893
|
+
client has ``advanced_mode=True``, return the raw response instead.
|
|
857
894
|
"""
|
|
858
895
|
url = f"rest/api/content/{page_id}"
|
|
859
896
|
if recursive:
|
|
860
|
-
|
|
897
|
+
# Fetch every child before deleting any of them. Confluence uses
|
|
898
|
+
# offset pagination for this resource; deleting a child while
|
|
899
|
+
# consuming the generator changes the collection and can make a
|
|
900
|
+
# subsequent offset skip pages shifted earlier in the collection.
|
|
901
|
+
children_pages = list(self.get_page_child_by_type(page_id))
|
|
861
902
|
for children_page in children_pages:
|
|
862
903
|
self.remove_page(children_page.get("id"), status, recursive)
|
|
863
904
|
params = {}
|
|
@@ -865,8 +906,13 @@ class Server(ConfluenceServerBase):
|
|
|
865
906
|
params["status"] = status
|
|
866
907
|
|
|
867
908
|
try:
|
|
868
|
-
response = self.delete(url, params=params)
|
|
909
|
+
response = self.delete(url, params=params, advanced_mode=True)
|
|
869
910
|
except HTTPError as e:
|
|
911
|
+
if e.response.status_code == 403:
|
|
912
|
+
raise ApiPermissionError(
|
|
913
|
+
"The calling user does not have permission to trash or purge the content",
|
|
914
|
+
reason=e,
|
|
915
|
+
)
|
|
870
916
|
if e.response.status_code == 404:
|
|
871
917
|
# Raise ApiError as the documented reason is ambiguous
|
|
872
918
|
raise ApiError(
|
|
@@ -882,7 +928,9 @@ class Server(ConfluenceServerBase):
|
|
|
882
928
|
|
|
883
929
|
raise
|
|
884
930
|
|
|
885
|
-
|
|
931
|
+
if self.advanced_mode:
|
|
932
|
+
return response
|
|
933
|
+
return response.status_code
|
|
886
934
|
|
|
887
935
|
def create_page(
|
|
888
936
|
self,
|
|
@@ -895,6 +943,7 @@ class Server(ConfluenceServerBase):
|
|
|
895
943
|
editor=None,
|
|
896
944
|
full_width=False,
|
|
897
945
|
status="current",
|
|
946
|
+
version_comment=None,
|
|
898
947
|
):
|
|
899
948
|
"""
|
|
900
949
|
Create page from scratch
|
|
@@ -908,6 +957,7 @@ class Server(ConfluenceServerBase):
|
|
|
908
957
|
:param editor: OPTIONAL: v2 to be created in the new editor
|
|
909
958
|
:param full_width: DEFAULT: False
|
|
910
959
|
:param status: either 'current' or 'draft'
|
|
960
|
+
:param version_comment: optional message recorded with the first page version
|
|
911
961
|
:return:
|
|
912
962
|
"""
|
|
913
963
|
log.info('Creating %s "%s" -> "%s"', type, space, title)
|
|
@@ -922,6 +972,8 @@ class Server(ConfluenceServerBase):
|
|
|
922
972
|
}
|
|
923
973
|
if parent_id:
|
|
924
974
|
data["ancestors"] = [{"type": type, "id": parent_id}]
|
|
975
|
+
if version_comment is not None:
|
|
976
|
+
data["version"] = {"message": version_comment}
|
|
925
977
|
if editor is not None and editor in ["v1", "v2"]:
|
|
926
978
|
data["metadata"]["properties"]["editor"] = {"value": editor}
|
|
927
979
|
if full_width is True:
|
|
@@ -1009,6 +1061,12 @@ class Server(ConfluenceServerBase):
|
|
|
1009
1061
|
:raises ApiNotFoundError: If no page ID is supplied and the title cannot
|
|
1010
1062
|
be resolved in the requested space.
|
|
1011
1063
|
"""
|
|
1064
|
+
# Confluence attachment names are filenames, not paths. Normalize both
|
|
1065
|
+
# POSIX and Windows separators before Confluence can silently collapse
|
|
1066
|
+
# them into an existing basename.
|
|
1067
|
+
name = str(name).replace("\\", "/").rsplit("/", 1)[-1]
|
|
1068
|
+
if not name:
|
|
1069
|
+
raise ApiValueError("Attachment name must contain a filename")
|
|
1012
1070
|
page_id = self.get_page_id(space=space, title=title) if page_id is None else page_id
|
|
1013
1071
|
type = "attachment"
|
|
1014
1072
|
if page_id is not None:
|
|
@@ -1025,13 +1083,13 @@ class Server(ConfluenceServerBase):
|
|
|
1025
1083
|
"Accept": "application/json",
|
|
1026
1084
|
}
|
|
1027
1085
|
path = f"rest/api/content/{page_id}/child/attachment"
|
|
1028
|
-
# Check if there is already a file with the same name
|
|
1029
|
-
attachments = self.get(path=path, headers=headers, params={"filename": name})
|
|
1030
|
-
if attachments.get("size"):
|
|
1031
|
-
path = path + "/" + attachments["results"][0]["id"] + "/data"
|
|
1032
1086
|
|
|
1033
1087
|
try:
|
|
1034
|
-
|
|
1088
|
+
# Confluence's multipart PUT endpoint atomically creates an
|
|
1089
|
+
# attachment or adds a revision when the filename already
|
|
1090
|
+
# exists. A GET followed by POST is racy and Cloud may reject
|
|
1091
|
+
# the attachment-data endpoint for a same-name upload.
|
|
1092
|
+
response = self.put(
|
|
1035
1093
|
path=path,
|
|
1036
1094
|
data=data,
|
|
1037
1095
|
headers=headers,
|
|
@@ -1108,7 +1166,9 @@ class Server(ConfluenceServerBase):
|
|
|
1108
1166
|
comment=comment,
|
|
1109
1167
|
)
|
|
1110
1168
|
|
|
1111
|
-
def download_attachments_from_page(
|
|
1169
|
+
def download_attachments_from_page(
|
|
1170
|
+
self, page_id, path=None, start=0, limit=50, filename=None, to_memory=False, download_path=None
|
|
1171
|
+
):
|
|
1112
1172
|
"""
|
|
1113
1173
|
Downloads attachments from a Confluence page. Supports downloading all files or a specific file.
|
|
1114
1174
|
Files can either be saved to disk or returned as BytesIO objects for in-memory handling.
|
|
@@ -1118,6 +1178,9 @@ class Server(ConfluenceServerBase):
|
|
|
1118
1178
|
:param path: str, optional
|
|
1119
1179
|
Directory where attachments will be saved. If None, defaults to the current working directory.
|
|
1120
1180
|
Ignored if `to_memory` is True.
|
|
1181
|
+
:param download_path: str, optional
|
|
1182
|
+
Deprecated alias for ``path`` retained for callers of older
|
|
1183
|
+
documentation. Do not pass both names with different values.
|
|
1121
1184
|
:param start: int, optional
|
|
1122
1185
|
The start point for paginated attachment fetching. Default is 0. Ignored if `filename` is specified.
|
|
1123
1186
|
:param limit: int, optional
|
|
@@ -1136,6 +1199,11 @@ class Server(ConfluenceServerBase):
|
|
|
1136
1199
|
- requests.HTTPError: If the HTTP request to fetch an attachment fails.
|
|
1137
1200
|
- Exception: For any unexpected errors.
|
|
1138
1201
|
"""
|
|
1202
|
+
if download_path is not None:
|
|
1203
|
+
if path is not None and path != download_path:
|
|
1204
|
+
raise ApiValueError("Specify only one of path or download_path")
|
|
1205
|
+
path = download_path
|
|
1206
|
+
|
|
1139
1207
|
# Default path to current working directory if not provided
|
|
1140
1208
|
if not to_memory and path is None:
|
|
1141
1209
|
path = os.getcwd()
|
|
@@ -1394,6 +1462,21 @@ class Server(ConfluenceServerBase):
|
|
|
1394
1462
|
def get_content_history(self, content_id):
|
|
1395
1463
|
return self.history(content_id)
|
|
1396
1464
|
|
|
1465
|
+
def iter_page_versions(self, page_id, limit=200, expand=None):
|
|
1466
|
+
"""Yield every version of a Server/Data Center page.
|
|
1467
|
+
|
|
1468
|
+
The dedicated ``content/{id}/version`` endpoint is paginated. This
|
|
1469
|
+
method follows its links lazily, avoiding one request per version.
|
|
1470
|
+
"""
|
|
1471
|
+
params = {"limit": int(limit)}
|
|
1472
|
+
if expand is not None:
|
|
1473
|
+
params["expand"] = expand
|
|
1474
|
+
return self._get_paged(f"content/{page_id}/version", params=params)
|
|
1475
|
+
|
|
1476
|
+
def get_all_page_versions(self, page_id, limit=200, expand=None):
|
|
1477
|
+
"""Return every version of a Server/Data Center page as a list."""
|
|
1478
|
+
return list(self.iter_page_versions(page_id, limit=limit, expand=expand))
|
|
1479
|
+
|
|
1397
1480
|
def get_content_history_by_version_number(self, content_id, version_number, expand=None):
|
|
1398
1481
|
"""
|
|
1399
1482
|
Get content history by version number
|
|
@@ -1749,23 +1832,27 @@ class Server(ConfluenceServerBase):
|
|
|
1749
1832
|
minor_edit=False,
|
|
1750
1833
|
):
|
|
1751
1834
|
"""
|
|
1752
|
-
Append
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
:param
|
|
1759
|
-
:param
|
|
1760
|
-
|
|
1761
|
-
:
|
|
1835
|
+
Append content to an existing page.
|
|
1836
|
+
|
|
1837
|
+
``append_body`` is normally a string of Confluence storage XHTML. A
|
|
1838
|
+
``list`` or ``dict`` is supported with ``representation="storage"``
|
|
1839
|
+
and is appended as pretty-printed JSON in a Confluence code block.
|
|
1840
|
+
|
|
1841
|
+
:param parent_id: optional parent page ID
|
|
1842
|
+
:param page_id: page ID
|
|
1843
|
+
:param title: page title
|
|
1844
|
+
:param append_body: storage XHTML, or a list/dict to render as JSON
|
|
1845
|
+
:param type: content type; normally ``"page"``
|
|
1846
|
+
:param representation: ``"storage"`` or legacy ``"wiki"`` markup
|
|
1847
|
+
:param minor_edit: whether to suppress watcher notifications
|
|
1848
|
+
:return: the updated page response
|
|
1762
1849
|
"""
|
|
1763
1850
|
log.info('Updating %s "%s"', type, title)
|
|
1764
1851
|
|
|
1765
1852
|
return self._insert_to_existing_page(
|
|
1766
1853
|
page_id,
|
|
1767
1854
|
title,
|
|
1768
|
-
append_body,
|
|
1855
|
+
self._coerce_structured_storage_body(append_body, representation),
|
|
1769
1856
|
parent_id=parent_id,
|
|
1770
1857
|
type=type,
|
|
1771
1858
|
representation=representation,
|
|
@@ -1800,7 +1887,7 @@ class Server(ConfluenceServerBase):
|
|
|
1800
1887
|
return self._insert_to_existing_page(
|
|
1801
1888
|
page_id,
|
|
1802
1889
|
title,
|
|
1803
|
-
prepend_body,
|
|
1890
|
+
self._coerce_structured_storage_body(prepend_body, representation),
|
|
1804
1891
|
parent_id=parent_id,
|
|
1805
1892
|
type=type,
|
|
1806
1893
|
representation=representation,
|
|
@@ -1808,6 +1895,28 @@ class Server(ConfluenceServerBase):
|
|
|
1808
1895
|
top_of_page=True,
|
|
1809
1896
|
)
|
|
1810
1897
|
|
|
1898
|
+
@staticmethod
|
|
1899
|
+
def _coerce_structured_storage_body(body, representation):
|
|
1900
|
+
"""Render structured input as a safe JSON code block for storage pages."""
|
|
1901
|
+
if isinstance(body, str):
|
|
1902
|
+
return body
|
|
1903
|
+
if not isinstance(body, (list, dict)):
|
|
1904
|
+
raise ApiValueError("Page content must be a string, list, or dictionary")
|
|
1905
|
+
if representation != "storage":
|
|
1906
|
+
raise ApiValueError("Lists and dictionaries require representation='storage'")
|
|
1907
|
+
|
|
1908
|
+
# Split a CDATA terminator so arbitrary JSON cannot close the storage
|
|
1909
|
+
# macro's plain-text body.
|
|
1910
|
+
cdata_end = "]]" + ">"
|
|
1911
|
+
cdata_escape = "]]" + "]]><![CDATA[>"
|
|
1912
|
+
json_body = json.dumps(body, ensure_ascii=False, indent=2).replace(cdata_end, cdata_escape)
|
|
1913
|
+
return (
|
|
1914
|
+
'<ac:structured-macro ac:name="code">'
|
|
1915
|
+
'<ac:parameter ac:name="language">json</ac:parameter>'
|
|
1916
|
+
f"<ac:plain-text-body><![CDATA[{json_body}]]></ac:plain-text-body>"
|
|
1917
|
+
"</ac:structured-macro>"
|
|
1918
|
+
)
|
|
1919
|
+
|
|
1811
1920
|
def update_or_create(
|
|
1812
1921
|
self,
|
|
1813
1922
|
parent_id=None,
|
|
@@ -1844,8 +1953,15 @@ class Server(ConfluenceServerBase):
|
|
|
1844
1953
|
raise ApiValueError("space is required when parent_id is omitted")
|
|
1845
1954
|
space = self.get_page_space(parent_id)
|
|
1846
1955
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1956
|
+
# A title is only unique among siblings. Searching the whole space
|
|
1957
|
+
# when a parent is supplied could update and move a same-titled page
|
|
1958
|
+
# from another branch (#956).
|
|
1959
|
+
if parent_id is not None:
|
|
1960
|
+
page_id = self.get_descendant_page_id(space, parent_id, title) or None
|
|
1961
|
+
else:
|
|
1962
|
+
page_id = self.get_page_id(space, title) if self.page_exists(space, title) else None
|
|
1963
|
+
|
|
1964
|
+
if page_id is not None:
|
|
1849
1965
|
parent_id = parent_id if parent_id is not None else self.get_parent_content_id(page_id)
|
|
1850
1966
|
result = self.update_page(
|
|
1851
1967
|
parent_id=parent_id,
|
|
@@ -1858,14 +1974,19 @@ class Server(ConfluenceServerBase):
|
|
|
1858
1974
|
full_width=full_width,
|
|
1859
1975
|
)
|
|
1860
1976
|
else:
|
|
1977
|
+
create_kwargs = {
|
|
1978
|
+
"space": space,
|
|
1979
|
+
"parent_id": parent_id,
|
|
1980
|
+
"title": title,
|
|
1981
|
+
"body": body,
|
|
1982
|
+
"representation": representation,
|
|
1983
|
+
"editor": editor,
|
|
1984
|
+
"full_width": full_width,
|
|
1985
|
+
}
|
|
1986
|
+
if version_comment is not None:
|
|
1987
|
+
create_kwargs["version_comment"] = version_comment
|
|
1861
1988
|
result = self.create_page(
|
|
1862
|
-
|
|
1863
|
-
parent_id=parent_id,
|
|
1864
|
-
title=title,
|
|
1865
|
-
body=body,
|
|
1866
|
-
representation=representation,
|
|
1867
|
-
editor=editor,
|
|
1868
|
-
full_width=full_width,
|
|
1989
|
+
**create_kwargs,
|
|
1869
1990
|
)
|
|
1870
1991
|
|
|
1871
1992
|
log.info(
|
|
@@ -1897,14 +2018,20 @@ class Server(ConfluenceServerBase):
|
|
|
1897
2018
|
"""
|
|
1898
2019
|
Set the page (content) property e.g. add hash parameters
|
|
1899
2020
|
:param page_id: content_id format
|
|
1900
|
-
:param data:
|
|
2021
|
+
:param data: property dictionary, or a JSON string representing one
|
|
1901
2022
|
:return:
|
|
1902
2023
|
"""
|
|
1903
2024
|
url = f"content/{page_id}/property"
|
|
1904
|
-
|
|
2025
|
+
if isinstance(data, str):
|
|
2026
|
+
try:
|
|
2027
|
+
data = json.loads(data)
|
|
2028
|
+
except json.JSONDecodeError as error:
|
|
2029
|
+
raise ApiValueError("Page property data must be valid JSON", reason=error)
|
|
2030
|
+
if not isinstance(data, dict):
|
|
2031
|
+
raise ApiValueError("Page property data must be a dictionary")
|
|
1905
2032
|
|
|
1906
2033
|
try:
|
|
1907
|
-
response = self.post(path=url, data=
|
|
2034
|
+
response = self.post(path=url, data=data)
|
|
1908
2035
|
except HTTPError as e:
|
|
1909
2036
|
if e.response.status_code == 400:
|
|
1910
2037
|
raise ApiValueError(
|
|
@@ -1929,11 +2056,19 @@ class Server(ConfluenceServerBase):
|
|
|
1929
2056
|
"""
|
|
1930
2057
|
Update the page (content) property.
|
|
1931
2058
|
Use json data or independent keys
|
|
1932
|
-
:param data:
|
|
2059
|
+
:param data: property dictionary, or a JSON string representing one
|
|
1933
2060
|
:param page_id: content_id format
|
|
1934
2061
|
:data: property data in json format
|
|
1935
2062
|
:return:
|
|
1936
2063
|
"""
|
|
2064
|
+
if isinstance(data, str):
|
|
2065
|
+
try:
|
|
2066
|
+
data = json.loads(data)
|
|
2067
|
+
except json.JSONDecodeError as error:
|
|
2068
|
+
raise ApiValueError("Page property data must be valid JSON", reason=error)
|
|
2069
|
+
if not isinstance(data, dict):
|
|
2070
|
+
raise ApiValueError("Page property data must be a dictionary")
|
|
2071
|
+
|
|
1937
2072
|
url = f"content/{page_id}/property/{data.get('key')}"
|
|
1938
2073
|
try:
|
|
1939
2074
|
response = self.put(path=url, data=data)
|
|
@@ -2075,6 +2210,7 @@ class Server(ConfluenceServerBase):
|
|
|
2075
2210
|
expand=None,
|
|
2076
2211
|
space_type=None,
|
|
2077
2212
|
space_status=None,
|
|
2213
|
+
label=None,
|
|
2078
2214
|
):
|
|
2079
2215
|
"""
|
|
2080
2216
|
Get all spaces with provided limit
|
|
@@ -2083,6 +2219,7 @@ class Server(ConfluenceServerBase):
|
|
|
2083
2219
|
fixed system limits. Default: 500
|
|
2084
2220
|
:param space_type: OPTIONAL: Filter the list of spaces returned by type (global, personal)
|
|
2085
2221
|
:param space_status: OPTIONAL: Filter the list of spaces returned by status (current, archived)
|
|
2222
|
+
:param label: OPTIONAL: Filter the list of spaces by a category label.
|
|
2086
2223
|
:param expand: OPTIONAL: additional info, e.g. metadata, icon, description, homepage
|
|
2087
2224
|
"""
|
|
2088
2225
|
url = "rest/api/space"
|
|
@@ -2097,9 +2234,11 @@ class Server(ConfluenceServerBase):
|
|
|
2097
2234
|
params["type"] = space_type
|
|
2098
2235
|
if space_status:
|
|
2099
2236
|
params["status"] = space_status
|
|
2237
|
+
if label:
|
|
2238
|
+
params["label"] = label
|
|
2100
2239
|
return self.get(url, params=params)
|
|
2101
2240
|
|
|
2102
|
-
def get_space_names(self, start=0, limit=50, space_type=None, space_status=None):
|
|
2241
|
+
def get_space_names(self, start=0, limit=50, space_type=None, space_status=None, label=None):
|
|
2103
2242
|
"""Return every visible Server/Data Center space name.
|
|
2104
2243
|
|
|
2105
2244
|
Only the space directory metadata endpoint is requested; no page or
|
|
@@ -2113,6 +2252,7 @@ class Server(ConfluenceServerBase):
|
|
|
2113
2252
|
limit=limit,
|
|
2114
2253
|
space_type=space_type,
|
|
2115
2254
|
space_status=space_status,
|
|
2255
|
+
label=label,
|
|
2116
2256
|
)
|
|
2117
2257
|
spaces = response.get("results", [])
|
|
2118
2258
|
names.extend(space["name"] for space in spaces if space.get("name"))
|
|
@@ -2199,14 +2339,23 @@ class Server(ConfluenceServerBase):
|
|
|
2199
2339
|
return self.post("space", data=data, **kwargs)
|
|
2200
2340
|
|
|
2201
2341
|
def update_space(self, space_key, data, **kwargs):
|
|
2202
|
-
"""Update existing space."""
|
|
2342
|
+
"""Update an existing Server/Data Center space with a REST payload."""
|
|
2203
2343
|
return self.put(f"space/{space_key}", data=data, **kwargs)
|
|
2204
2344
|
|
|
2205
|
-
def
|
|
2345
|
+
def set_space_homepage(self, space_key, homepage_id):
|
|
2346
|
+
"""Set a Server/Data Center space's homepage to an existing page.
|
|
2347
|
+
|
|
2348
|
+
``homepage_id`` must identify a page in the target space. The caller
|
|
2349
|
+
needs permission to administer the space and view the chosen page.
|
|
2206
2350
|
"""
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2351
|
+
return self.update_space(space_key, {"homepage": {"id": homepage_id}})
|
|
2352
|
+
|
|
2353
|
+
def delete_space(self, space_key, **kwargs):
|
|
2354
|
+
"""Delete a space by key.
|
|
2355
|
+
|
|
2356
|
+
Raises:
|
|
2357
|
+
ApiNotFoundError: If Confluence responds with HTTP 404. Confluence
|
|
2358
|
+
may use this status to avoid revealing an inaccessible space.
|
|
2210
2359
|
"""
|
|
2211
2360
|
url = f"space/{space_key}"
|
|
2212
2361
|
|
|
@@ -2214,7 +2363,7 @@ class Server(ConfluenceServerBase):
|
|
|
2214
2363
|
response = self.delete(url, **kwargs)
|
|
2215
2364
|
except HTTPError as e:
|
|
2216
2365
|
if e.response.status_code == 404:
|
|
2217
|
-
raise
|
|
2366
|
+
raise ApiNotFoundError(
|
|
2218
2367
|
"There is no space with the given key, "
|
|
2219
2368
|
"or the calling user does not have permission to delete it",
|
|
2220
2369
|
reason=e,
|
|
@@ -3148,11 +3297,39 @@ class Server(ConfluenceServerBase):
|
|
|
3148
3297
|
)
|
|
3149
3298
|
return content
|
|
3150
3299
|
|
|
3151
|
-
def
|
|
3300
|
+
def iter_page_tree_as_pdf(self, page_id):
|
|
3301
|
+
"""Yield ``(page_id, pdf_bytes)`` for a page and all descendant pages.
|
|
3302
|
+
|
|
3303
|
+
Confluence exposes single-page PDF export but does not provide a
|
|
3304
|
+
supported REST operation for one merged arbitrary subtree PDF. Results
|
|
3305
|
+
are yielded in depth-first page-tree order so callers can stream files
|
|
3306
|
+
to disk or merge them with their preferred PDF library.
|
|
3307
|
+
"""
|
|
3308
|
+
pending_page_ids = [page_id]
|
|
3309
|
+
while pending_page_ids:
|
|
3310
|
+
current_page_id = pending_page_ids.pop()
|
|
3311
|
+
yield current_page_id, self.get_page_as_pdf(current_page_id)
|
|
3312
|
+
children = list(self.get_page_child_by_type(current_page_id, type="page"))
|
|
3313
|
+
pending_page_ids.extend(child["id"] for child in reversed(children))
|
|
3314
|
+
|
|
3315
|
+
def export_page_tree_as_pdf(self, page_id):
|
|
3316
|
+
"""Return individual PDFs for a page subtree keyed by page ID.
|
|
3317
|
+
|
|
3318
|
+
Prefer :meth:`iter_page_tree_as_pdf` for large hierarchies to avoid
|
|
3319
|
+
keeping every PDF in memory.
|
|
3152
3320
|
"""
|
|
3153
|
-
|
|
3321
|
+
return dict(self.iter_page_tree_as_pdf(page_id))
|
|
3322
|
+
|
|
3323
|
+
def get_page_as_word(self, page_id):
|
|
3324
|
+
"""Export a page through Confluence's legacy Word exporter.
|
|
3325
|
+
|
|
3326
|
+
Returns the response bytes exactly as provided by Confluence. The
|
|
3327
|
+
exporter does not produce a DOCX file (nor necessarily a binary DOC
|
|
3328
|
+
file); its output is a Word-readable multipart HTML document. There is
|
|
3329
|
+
no supported Confluence REST endpoint for DOCX export.
|
|
3330
|
+
|
|
3154
3331
|
:param page_id: Page ID
|
|
3155
|
-
:return: Word
|
|
3332
|
+
:return: Legacy Word-export bytes
|
|
3156
3333
|
"""
|
|
3157
3334
|
headers = self.form_token_headers
|
|
3158
3335
|
url = f"exportword?pageId={page_id}"
|
|
@@ -3170,20 +3347,25 @@ class Server(ConfluenceServerBase):
|
|
|
3170
3347
|
:return: The URL to download the exported file.
|
|
3171
3348
|
"""
|
|
3172
3349
|
|
|
3350
|
+
# Space export is a browser workflow, not a REST resource. ``self.url``
|
|
3351
|
+
# normally ends in ``/rest/api/<version>``, so derive the Confluence UI
|
|
3352
|
+
# context before requesting its action endpoints.
|
|
3353
|
+
ui_base_url = self.url.split("/rest/api/", 1)[0]
|
|
3354
|
+
|
|
3355
|
+
def ui_url(path: str) -> str:
|
|
3356
|
+
return self.url_joiner(ui_base_url, path)
|
|
3357
|
+
|
|
3173
3358
|
def get_atl_request(link: str):
|
|
3174
3359
|
# Nested function used to get atl_token used for XSRF protection.
|
|
3175
3360
|
# This is only applicable to html/csv/xml space exports
|
|
3176
3361
|
try:
|
|
3177
|
-
response = self.get(link, advanced_mode=True)
|
|
3362
|
+
response = self.get(ui_url(link), absolute=True, advanced_mode=True)
|
|
3178
3363
|
parsed_html = BeautifulSoup(response.text, "html.parser")
|
|
3179
3364
|
atl_token = parsed_html.find("input", {"name": "atl_token"}).get("value") # type: ignore[union-attr]
|
|
3180
3365
|
return atl_token
|
|
3181
3366
|
except Exception as e:
|
|
3182
3367
|
raise ApiError("Problems with getting the atl_token for get_space_export method :", reason=e)
|
|
3183
3368
|
|
|
3184
|
-
# Checks if space_ke parameter is valid and if api_token has relevant permissions to space
|
|
3185
|
-
self.get_space(space_key=space_key, expand="permissions")
|
|
3186
|
-
|
|
3187
3369
|
try:
|
|
3188
3370
|
log.info(
|
|
3189
3371
|
"Initiated experimental get_space_export method for export type: "
|
|
@@ -3221,10 +3403,18 @@ class Server(ConfluenceServerBase):
|
|
|
3221
3403
|
raise ValueError("PDF space export is not supported yet for Server/Data Center")
|
|
3222
3404
|
else:
|
|
3223
3405
|
raise ValueError("Invalid export_type parameter value. Valid values are: 'html/csv/xml/pdf'")
|
|
3224
|
-
url =
|
|
3406
|
+
url = ui_url(f"spaces/doexportspace.action?key={space_key}")
|
|
3225
3407
|
|
|
3226
3408
|
# Sending a POST request that triggers the space export.
|
|
3227
|
-
response = self.session.post(
|
|
3409
|
+
response = self.session.post(
|
|
3410
|
+
url,
|
|
3411
|
+
headers=self.form_token_headers,
|
|
3412
|
+
data=form_data,
|
|
3413
|
+
timeout=self.timeout,
|
|
3414
|
+
verify=self.verify_ssl,
|
|
3415
|
+
proxies=self.proxies,
|
|
3416
|
+
)
|
|
3417
|
+
response.raise_for_status()
|
|
3228
3418
|
parsed_html = BeautifulSoup(response.text, "html.parser")
|
|
3229
3419
|
# Getting the poll URL to get the export progress status
|
|
3230
3420
|
try:
|
|
@@ -3236,21 +3426,15 @@ class Server(ConfluenceServerBase):
|
|
|
3236
3426
|
running_task = True
|
|
3237
3427
|
while running_task:
|
|
3238
3428
|
try:
|
|
3239
|
-
|
|
3429
|
+
progress_url = urljoin(ui_base_url + "/", poll_url)
|
|
3430
|
+
progress_response = self.get(progress_url, absolute=True) or {}
|
|
3240
3431
|
log.info(f"Space {space_key} export status: {progress_response.get('message', 'None')}")
|
|
3241
3432
|
if progress_response is not {} and progress_response.get("complete"):
|
|
3242
3433
|
parsed_html = BeautifulSoup(progress_response.get("message"), "html.parser")
|
|
3243
3434
|
download_url = cast(
|
|
3244
3435
|
"str", parsed_html.find("a", {"class": "space-export-download-path"}).get("href")
|
|
3245
3436
|
) # type: ignore
|
|
3246
|
-
|
|
3247
|
-
return download_url
|
|
3248
|
-
else:
|
|
3249
|
-
combined_url = self.url + download_url
|
|
3250
|
-
# Ensure only one /wiki is included in the path
|
|
3251
|
-
if combined_url.count("/wiki") > 1:
|
|
3252
|
-
combined_url = combined_url.replace("/wiki/wiki", "/wiki")
|
|
3253
|
-
return combined_url
|
|
3437
|
+
return urljoin(ui_base_url + "/", download_url)
|
|
3254
3438
|
time.sleep(30)
|
|
3255
3439
|
except Exception as e:
|
|
3256
3440
|
raise ApiError(
|
|
@@ -3261,6 +3445,22 @@ class Server(ConfluenceServerBase):
|
|
|
3261
3445
|
except Exception as e:
|
|
3262
3446
|
raise ApiError("Encountered error during space export from space " + space_key, reason=e)
|
|
3263
3447
|
|
|
3448
|
+
def iter_space_exports(self, space_keys, export_type: str):
|
|
3449
|
+
"""Yield exported-space download URLs one space at a time.
|
|
3450
|
+
|
|
3451
|
+
The underlying Confluence export is an asynchronous browser workflow.
|
|
3452
|
+
Confluence limits concurrent exports, so this iterator intentionally
|
|
3453
|
+
waits for each export to finish before starting the next one. It is a
|
|
3454
|
+
safer alternative to invoking :meth:`get_space_export` concurrently
|
|
3455
|
+
from multiple threads.
|
|
3456
|
+
|
|
3457
|
+
:param space_keys: Iterable of Confluence space keys.
|
|
3458
|
+
:param export_type: Export type accepted by :meth:`get_space_export`.
|
|
3459
|
+
:return: Iterator of ``(space_key, download_url)`` tuples.
|
|
3460
|
+
"""
|
|
3461
|
+
for space_key in space_keys:
|
|
3462
|
+
yield space_key, self.get_space_export(space_key, export_type)
|
|
3463
|
+
|
|
3264
3464
|
def export_page(self, page_id):
|
|
3265
3465
|
"""
|
|
3266
3466
|
Alias method for export page as pdf
|