atlassian-python-api 4.0.3__py3-none-any.whl → 4.0.5__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.
@@ -3,9 +3,9 @@
3
3
  import copy
4
4
  import re
5
5
  import sys
6
-
7
6
  from datetime import datetime
8
7
  from pprint import PrettyPrinter
8
+
9
9
  from ..rest_client import AtlassianRestAPI
10
10
 
11
11
  RE_TIMEZONE = re.compile(r"(\d{2}):(\d{2})$")
@@ -1,11 +1,15 @@
1
1
  # coding=utf-8
2
2
 
3
3
  from .base import BitbucketCloudBase
4
- from .workspaces import Workspaces
5
4
  from .repositories import Repositories
5
+ from .workspaces import Workspaces
6
6
 
7
7
 
8
8
  class Cloud(BitbucketCloudBase):
9
+ """
10
+ Bitbucket Cloud REST API wrapper
11
+ """
12
+
9
13
  def __init__(self, url="https://api.bitbucket.org/", *args, **kwargs):
10
14
  kwargs["cloud"] = True
11
15
  kwargs["api_root"] = None
@@ -1,10 +1,10 @@
1
1
  # coding=utf-8
2
2
 
3
3
  import logging
4
- from ..base import BitbucketBase
5
-
6
4
  from requests import HTTPError
7
5
 
6
+ from ..base import BitbucketBase
7
+
8
8
  log = logging.getLogger(__name__)
9
9
 
10
10
 
@@ -1,3 +1,5 @@
1
+ from datetime import datetime
2
+
1
3
  from ..base import BitbucketCloudBase
2
4
 
3
5
 
@@ -31,6 +33,49 @@ class User(BitbucketCloudBase):
31
33
  return self.get_data("links")["avatar"]["href"]
32
34
 
33
35
 
36
+ class AppUser(BitbucketCloudBase):
37
+ def __init__(self, url, data, *args, **kwargs):
38
+ super(AppUser, self).__init__(url, *args, data=data, expected_type="app_user", **kwargs)
39
+
40
+ @property
41
+ def display_name(self):
42
+ """User display name"""
43
+ return str(self.get_data("display_name"))
44
+
45
+ @property
46
+ def account_id(self):
47
+ """User account id"""
48
+ return self.get_data("account_id")
49
+
50
+ @property
51
+ def account_status(self):
52
+ """User account status"""
53
+ return self.get_data("account_status")
54
+
55
+ @property
56
+ def created_on(self):
57
+ """User creation date"""
58
+ created_on = self.get_data("created_on")
59
+ if created_on is None:
60
+ return None
61
+ return datetime.strptime(created_on, self.CONF_TIMEFORMAT)
62
+
63
+ @property
64
+ def uuid(self):
65
+ """User id"""
66
+ return self.get_data("uuid")
67
+
68
+ @property
69
+ def kind(self):
70
+ """User kind"""
71
+ return self.get_data("kind")
72
+
73
+ @property
74
+ def links(self):
75
+ """User links"""
76
+ return self.get_data("links")
77
+
78
+
34
79
  class Participant(BitbucketCloudBase):
35
80
  ROLE_REVIEWER = "REVIEWER"
36
81
  ROLE_PARTICIPANT = "PARTICIPANT"
@@ -42,6 +87,9 @@ class Participant(BitbucketCloudBase):
42
87
  @property
43
88
  def user(self):
44
89
  """User object with user information of the participant."""
90
+ if self.get_data("type") == "app_user":
91
+ # If the participant is an app user, return an AppUser instance
92
+ return AppUser(None, self.get_data("app_user"), **self._new_session_args)
45
93
  return User(None, self.get_data("user"), **self._new_session_args)
46
94
 
47
95
  @property
@@ -1,18 +1,20 @@
1
1
  # coding=utf-8
2
2
 
3
3
  from requests import HTTPError
4
- from ..base import BitbucketCloudBase
5
- from .issues import Issues
4
+
6
5
  from .branchRestrictions import BranchRestrictions
7
6
  from .commits import Commits
8
- from .hooks import Hooks
9
7
  from .defaultReviewers import DefaultReviewers
10
8
  from .deploymentEnvironments import DeploymentEnvironments
9
+ from .downloads import Downloads
11
10
  from .groupPermissions import GroupPermissions
11
+ from .hooks import Hooks
12
+ from .issues import Issues
12
13
  from .pipelines import Pipelines
13
14
  from .pullRequests import PullRequests
14
15
  from .refs import Branches, Tags
15
16
  from .repositoryVariables import RepositoryVariables
17
+ from ..base import BitbucketCloudBase
16
18
 
17
19
 
18
20
  class RepositoriesBase(BitbucketCloudBase):
@@ -277,6 +279,7 @@ class Repository(BitbucketCloudBase):
277
279
  f"{self.url}/pipelines_config/variables", **self._new_session_args
278
280
  )
279
281
  self.__tags = Tags(f"{self.url}/refs/tags", **self._new_session_args)
282
+ self.__downloads = Downloads(f"{self.url}/downloads", **self._new_session_args)
280
283
 
281
284
  def update(self, **kwargs):
282
285
  """
@@ -433,3 +436,8 @@ class Repository(BitbucketCloudBase):
433
436
  def tags(self):
434
437
  """The repository tags."""
435
438
  return self.__tags
439
+
440
+ @property
441
+ def downloads(self):
442
+ """The repository downloads"""
443
+ return self.__downloads
@@ -2,7 +2,7 @@
2
2
 
3
3
  from ..base import BitbucketCloudBase
4
4
 
5
- from six.moves.urllib.parse import urlunsplit, urlsplit
5
+ from urllib.parse import urlunsplit, urlsplit
6
6
 
7
7
 
8
8
  class DeploymentEnvironments(BitbucketCloudBase):
@@ -0,0 +1,75 @@
1
+ from datetime import datetime
2
+
3
+ from ..base import BitbucketCloudBase
4
+ from ..common.users import AppUser
5
+
6
+
7
+ class Download(BitbucketCloudBase):
8
+ def __init__(self, url, data, *args, **kwargs):
9
+ super(Download, self).__init__(url, *args, data=data, expected_type="download", **kwargs)
10
+
11
+ @property
12
+ def name(self):
13
+ """The download file name"""
14
+ return self.get_data("name")
15
+
16
+ @property
17
+ def size(self):
18
+ """The download size in bytes"""
19
+ return self.get_data("size")
20
+
21
+ @property
22
+ def created_on(self):
23
+ """The download created date"""
24
+ created_on = self.get_data("created_on")
25
+ if created_on is None:
26
+ return None
27
+ return datetime.strptime(created_on, self.CONF_TIMEFORMAT)
28
+
29
+ @property
30
+ def user(self):
31
+ """The user who created this download"""
32
+ return AppUser(None, self.get_data("user"))
33
+
34
+ @property
35
+ def downloads(self):
36
+ """The number of times this file was downloaded"""
37
+ return self.get_data("downloads")
38
+
39
+ @property
40
+ def links(self):
41
+ """The download links"""
42
+ return self.get_data("links")
43
+
44
+ def get_content(self):
45
+ """Download file content"""
46
+ return self.get(self.url, absolute=True)
47
+
48
+
49
+ class Downloads(BitbucketCloudBase):
50
+ def __init__(self, url, *args, **kwargs):
51
+ super(Downloads, self).__init__(url, *args, **kwargs)
52
+
53
+ def __get_object(self, data):
54
+ url = self.url_joiner(self.url, data["name"])
55
+ if data["links"] and data["links"]["self"] and data["links"]["self"]["href"]:
56
+ url = data["links"]["self"]["href"]
57
+
58
+ return Download(
59
+ url,
60
+ data,
61
+ **self._new_session_args
62
+ ) # fmt: skip
63
+
64
+ def each(self):
65
+ """
66
+ Returns the list of downloads in this repository.
67
+
68
+ :return: A generator for the Download objects
69
+
70
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-downloads/#api-repositories-workspace-repo-slug-downloads-get
71
+ """
72
+ for issue in self._get_paged(None):
73
+ yield self.__get_object(issue)
74
+
75
+ return
atlassian/cloud_admin.py CHANGED
@@ -16,9 +16,94 @@ class CloudAdminOrgs(AtlassianRestAPI):
16
16
  super(CloudAdminOrgs, self).__init__(url=ADMIN_URL, *args, **kwargs)
17
17
 
18
18
  def get_organizations(self):
19
+ """
20
+ Returns a list of your organizations (based on your API key).
21
+ :return:
22
+ """
19
23
  url = self.resource_url("orgs")
20
24
  return self.get(url)
21
25
 
26
+ def get_organization(self, org_id):
27
+ """
28
+ Returns information about a single organization by ID
29
+ :param org_id:
30
+ :return:
31
+ """
32
+ url = self.resource_url(f"orgs/{org_id}")
33
+ return self.get(url)
34
+
35
+ def get_managed_accounts_in_organization(self, org_id, cursor=None):
36
+ """
37
+ Returns a list of accounts managed by the organization
38
+ :param org_id:
39
+ :param cursor:
40
+ :return:
41
+ """
42
+ url = self.resource_url(f"orgs/{org_id}/users")
43
+ params = {}
44
+ if cursor:
45
+ params["cursor"] = cursor
46
+ return self.get(url, params=params)
47
+
48
+ def search_users_in_organization(
49
+ self,
50
+ org_id,
51
+ account_ids=None,
52
+ account_types=None,
53
+ account_statuses=None,
54
+ name_or_nicknames=None,
55
+ email_usernames=None,
56
+ email_domains=None,
57
+ is_suspended=None,
58
+ cursor=None,
59
+ limit=10000,
60
+ expand=None,
61
+ ):
62
+ """
63
+ Returns a list of accounts in the organization that match the search criteria.
64
+ The API is available for customers using the new user management experience only.
65
+ How the new user management experience works
66
+ Returns a list of users within an organization,
67
+ offering search functionality through multiple parameters for more precise results.
68
+ :param org_id:
69
+ :param account_ids: Unique ID of the users account. The format is [a-zA-Z0-9_|-:]{1,128}
70
+ :param account_types: The type of account Valid values: atlassian, customer, app
71
+ :param account_statuses: The lifecycle status of the account
72
+ :param name_or_nicknames:
73
+ :param email_usernames:
74
+ :param email_domains:
75
+ :param is_suspended: Suspended users with no access. This is independent of the user account status
76
+ :param cursor: Starting point marker for page result retrieval
77
+ :param limit: The number of items to return. Default = max = 10000
78
+ :param expand: Valid values: NAME, EMAIL, EMAIL_VERIFIED, PRODUCT_LAST_ACCESS, GROUPS
79
+ :return:
80
+ """
81
+
82
+ url = self.resource_url(f"orgs/{org_id}/users/search")
83
+ params = {}
84
+ if cursor:
85
+ params["cursor"] = cursor
86
+ if limit:
87
+ params["limit"] = limit
88
+ if account_ids:
89
+ params["accountIds"] = account_ids
90
+ if account_types:
91
+ params["accountTypes"] = account_types
92
+ if account_statuses:
93
+ params["accountStatuses"] = account_statuses
94
+ if name_or_nicknames:
95
+ params["nameOrNicknames"] = name_or_nicknames
96
+ if email_usernames:
97
+ params["emailUsernames"] = email_usernames
98
+ if email_domains:
99
+ params["emailDomains"] = email_domains
100
+ if is_suspended:
101
+ params["isSuspended"] = is_suspended
102
+ if expand:
103
+ params["expand"] = expand
104
+
105
+ return self.get(url, params=params)
106
+
22
107
 
23
108
  class CloudAdminUsers(AtlassianRestAPI):
24
109
  def __init__(self, admin_api_key, *args, **kwargs):
@@ -5,6 +5,7 @@ import logging
5
5
  import os
6
6
  import re
7
7
  import time
8
+ import warnings
8
9
  from typing import cast
9
10
 
10
11
  import requests
@@ -13,16 +14,23 @@ from deprecated import deprecated
13
14
  from requests import HTTPError
14
15
 
15
16
  from atlassian import utils
16
-
17
- from .errors import (
17
+ from atlassian.errors import (
18
18
  ApiConflictError,
19
19
  ApiError,
20
20
  ApiNotAcceptable,
21
21
  ApiNotFoundError,
22
22
  ApiPermissionError,
23
23
  ApiValueError,
24
+ JsonRPCError,
25
+ JsonRPCRestrictionsError,
24
26
  )
25
- from .rest_client import AtlassianRestAPI
27
+ from atlassian.rest_client import AtlassianRestAPI
28
+ import sys
29
+
30
+ if sys.version_info >= (3, 8):
31
+ from typing import Literal # Python 3.8+
32
+ else:
33
+ from typing_extensions import Literal # Python <=3.7
26
34
 
27
35
  log = logging.getLogger(__name__)
28
36
 
@@ -860,6 +868,160 @@ class Confluence(AtlassianRestAPI):
860
868
  url = f"rest/api/content/{content_id}/restriction/byOperation"
861
869
  return self.get(url)
862
870
 
871
+ def get_all_restrictions_from_page_json_rpc(self, page_id):
872
+ """
873
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
874
+ JSON-RPC APIs operate differently than REST APIs.
875
+ To learn more about how to use these APIs,
876
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
877
+ """
878
+ if self.api_version == "cloud" or self.cloud:
879
+ return {}
880
+ url = "rpc/json-rpc/confluenceservice-v2"
881
+ data = {"jsonrpc": "2.0", "method": "getContentPermissionSets", "id": 9, "params": [page_id]}
882
+ return self.post(url, data=data).get("result") or {}
883
+
884
+ def update_restrictions_for_page_json_rpc(self, page_id, permission_type, content_permissions):
885
+ """
886
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
887
+ JSON-RPC APIs operate differently than REST APIs.
888
+ To learn more about how to use these APIs,
889
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
890
+ """
891
+ if self.api_version == "cloud" or self.cloud:
892
+ return {}
893
+ url = "rpc/json-rpc/confluenceservice-v2"
894
+ data = {
895
+ "jsonrpc": "2.0",
896
+ "method": "setContentPermissions",
897
+ "id": 9,
898
+ "params": [page_id, permission_type, content_permissions],
899
+ }
900
+ return self.post(url, data=data).get("result") or {}
901
+
902
+ def get_users_from_restricts_in_page_by_type(self, page_id: str, restriction_type: Literal["View", "Edit"]):
903
+ page_name = self.get_page_by_id(page_id=page_id)["title"]
904
+ restrictions_in_page = self.get_all_restrictions_from_page_json_rpc(page_id=page_id)
905
+ try:
906
+ if len(restrictions_in_page) > 0:
907
+ for restriction_type_in_page in restrictions_in_page:
908
+ if dict(restriction_type_in_page).get("type") == restriction_type:
909
+ users = dict(restriction_type_in_page).get("contentPermissions")
910
+ return users
911
+ else:
912
+ raise JsonRPCRestrictionsError(
913
+ f'On page "{page_name}" has no restrictions type of "{restriction_type}"'
914
+ )
915
+ except JsonRPCError:
916
+ raise
917
+
918
+ def create_restricts_from_from_user(self, user_name: str, restriction_type: Literal["View", "Edit"]):
919
+ content = {"type": restriction_type, "userName": user_name, "groupName": None}
920
+
921
+ return content
922
+
923
+ def add_user_in_restricted_page(self, user_name: str, page_id: str, restriction_type: Literal["View", "Edit"]):
924
+ page_name = self.get_page_by_id(page_id=page_id).get("title")
925
+ user_find_view_bool = False
926
+ user_find_edit_bool = False
927
+ users_content_view: list = self.get_users_from_restricts_in_page_by_type(
928
+ page_id=page_id, restriction_type="View"
929
+ )
930
+ users_content_edit: list = self.get_users_from_restricts_in_page_by_type(
931
+ page_id=page_id, restriction_type="Edit"
932
+ )
933
+ current_user_content_view: dict = self.create_restricts_from_from_user(
934
+ user_name=user_name, restriction_type="View"
935
+ )
936
+ current_user_content_edit: dict = self.create_restricts_from_from_user(
937
+ user_name=user_name, restriction_type="Edit"
938
+ )
939
+ try:
940
+ if None not in [users_content_view, users_content_edit]:
941
+ if users_content_view is not None:
942
+ for user in users_content_view:
943
+ if dict(user).get("userName") == current_user_content_view.get("userName"):
944
+ user_find_view_bool = True
945
+ if users_content_edit is not None:
946
+ for user in users_content_edit:
947
+ if dict(user).get("userName") == current_user_content_edit.get("userName"):
948
+ user_find_edit_bool = True
949
+ if restriction_type == "View":
950
+ if user_find_view_bool is False:
951
+ current_user_content = self.create_restricts_from_from_user(
952
+ user_name=user_name, restriction_type=restriction_type
953
+ )
954
+ users_content_view.append(current_user_content)
955
+ self.update_restrictions_for_page_json_rpc(
956
+ page_id=page_id,
957
+ permission_type=restriction_type,
958
+ content_permissions=users_content_view,
959
+ )
960
+ elif user_find_view_bool:
961
+ raise JsonRPCRestrictionsError(
962
+ f'User "{user_name}" already have restrictions type of "{restriction_type}" on page "{page_name}"'
963
+ )
964
+ elif restriction_type == "Edit":
965
+ if not user_find_edit_bool:
966
+ current_user_content_view = self.create_restricts_from_from_user(
967
+ user_name=user_name, restriction_type="View"
968
+ )
969
+ current_user_content_edit = self.create_restricts_from_from_user(
970
+ user_name=user_name, restriction_type=restriction_type
971
+ )
972
+ users_content_view.append(current_user_content_view)
973
+ users_content_edit.append(current_user_content_edit)
974
+ self.update_restrictions_for_page_json_rpc(
975
+ page_id=page_id, permission_type="View", content_permissions=users_content_view
976
+ )
977
+ self.update_restrictions_for_page_json_rpc(
978
+ page_id=page_id, permission_type=restriction_type, content_permissions=users_content_edit
979
+ )
980
+ print(
981
+ f'User "{user_name}" granted restrictions type of "{restriction_type}" on page "{page_name}"'
982
+ )
983
+ elif user_find_edit_bool:
984
+ raise JsonRPCRestrictionsError(
985
+ f'User "{user_name}" already have restrictions type of "{restriction_type}" on page "{page_name}"'
986
+ )
987
+ except JsonRPCError:
988
+ raise
989
+
990
+ def remove_user_from_restricted_page(self, user_name: str, page_id: str):
991
+ page_name = self.get_page_by_id(page_id=page_id).get("title")
992
+ user_find_bool = False
993
+ users_content_view: list = self.get_users_from_restricts_in_page_by_type(
994
+ page_id=page_id, restriction_type="View"
995
+ )
996
+ users_content_edit: list = self.get_users_from_restricts_in_page_by_type(
997
+ page_id=page_id, restriction_type="Edit"
998
+ )
999
+ current_user_content_view = self.create_restricts_from_from_user(user_name=user_name, restriction_type="View")
1000
+ current_user_content_edit = self.create_restricts_from_from_user(user_name=user_name, restriction_type="Edit")
1001
+ for user_index, user_value in enumerate(users_content_view):
1002
+ if dict(user_value).get("userName") == current_user_content_view.get("userName"):
1003
+ user_find_bool = True
1004
+ users_content_view.pop(user_index)
1005
+ for user_index, user_value in enumerate(users_content_edit):
1006
+ if dict(user_value).get("userName") == current_user_content_edit.get("userName"):
1007
+ user_find_bool = True
1008
+ users_content_edit.pop(user_index)
1009
+ try:
1010
+ if user_find_bool:
1011
+ self.update_restrictions_for_page_json_rpc(
1012
+ page_id=page_id, permission_type="View", content_permissions=users_content_view
1013
+ )
1014
+ self.update_restrictions_for_page_json_rpc(
1015
+ page_id=page_id, permission_type="Edit", content_permissions=users_content_edit
1016
+ )
1017
+ print(f'User "{user_name}" has been deleted from restrictions on page "{page_name}"')
1018
+ elif not user_find_bool:
1019
+ raise JsonRPCRestrictionsError(
1020
+ f'User "{user_name}" has not founded in restrictions on page "{page_name}"'
1021
+ )
1022
+ except JsonRPCError:
1023
+ raise
1024
+
863
1025
  def remove_page_from_trash(self, page_id):
864
1026
  """
865
1027
  This method removes a page from trash
@@ -1322,6 +1484,42 @@ class Confluence(AtlassianRestAPI):
1322
1484
  params["status"] = space_status
1323
1485
  return self.get(url, params=params)
1324
1486
 
1487
+ def archive_space(self, space_key):
1488
+ """
1489
+ Archive space
1490
+ :param space_key:
1491
+ :return:
1492
+ """
1493
+ url = f"rest/api/space/{space_key}/archive"
1494
+ return self.put(url)
1495
+
1496
+ def get_trashed_contents_by_space(self, space_key, cursor=None, expand=None, limit=100):
1497
+ """
1498
+ Get trashed contents by space
1499
+ :param space_key:
1500
+ :param cursor:
1501
+ :param expand:
1502
+ :param limit:
1503
+ :return:
1504
+ """
1505
+ url = f"rest/api/space/{space_key}/content/trash"
1506
+ params = {"limit": limit}
1507
+ if cursor:
1508
+ params["cursor"] = cursor
1509
+ if expand:
1510
+ params["expand"] = expand
1511
+ return self.get(url, params=params)
1512
+
1513
+ def remove_trashed_contents_by_space(self, space_key):
1514
+ """
1515
+ Remove all content from the trash in the given space,
1516
+ deleting them permanently.Example request URI:
1517
+ :param space_key:
1518
+ :return:
1519
+ """
1520
+ url = f"rest/api/space/{space_key}/content/trash"
1521
+ return self.delete(url)
1522
+
1325
1523
  def add_comment(self, page_id, text):
1326
1524
  """
1327
1525
  Add comment into page
@@ -1466,16 +1664,15 @@ class Confluence(AtlassianRestAPI):
1466
1664
  content_type = self.content_types.get(extension, "application/binary")
1467
1665
 
1468
1666
  with open(filename, "rb") as infile:
1469
- content = infile.read()
1470
- return self.attach_content(
1471
- content,
1472
- name,
1473
- content_type,
1474
- page_id=page_id,
1475
- title=title,
1476
- space=space,
1477
- comment=comment,
1478
- )
1667
+ return self.attach_content(
1668
+ infile,
1669
+ name,
1670
+ content_type,
1671
+ page_id=page_id,
1672
+ title=title,
1673
+ space=space,
1674
+ comment=comment,
1675
+ )
1479
1676
 
1480
1677
  def download_attachments_from_page(self, page_id, path=None, start=0, limit=50, filename=None, to_memory=False):
1481
1678
  """
@@ -1535,6 +1732,15 @@ class Confluence(AtlassianRestAPI):
1535
1732
  file_obj = io.BytesIO(response)
1536
1733
  downloaded_files[file_name] = file_obj
1537
1734
  else:
1735
+ # Sanitize filename if needed
1736
+ if re.search(r'[<>:"/\\|?*\x00-\x1F]', file_name):
1737
+ sanitized = re.sub(r'[<>:"/\\|?*\x00-\x1F]', "_", file_name)
1738
+ warnings.warn(
1739
+ f"File name '{file_name}' contained invalid characters and was renamed to '{sanitized}'.",
1740
+ UserWarning,
1741
+ )
1742
+ file_name = sanitized
1743
+ file_path = os.path.join(path, file_name)
1538
1744
  # Save file to disk
1539
1745
  file_path = os.path.join(path, file_name)
1540
1746
  with open(file_path, "wb") as file:
@@ -3368,9 +3574,21 @@ class Confluence(AtlassianRestAPI):
3368
3574
  :param group_name: str - name of group to add user to
3369
3575
  :return: Current state of the group
3370
3576
  """
3371
- url = "rest/api/user/%s/group/%s" % (username, group_name)
3577
+ url = f"rest/api/user/{username}/group/{group_name}"
3372
3578
  return self.put(url)
3373
3579
 
3580
+ def remove_user_from_group(self, username, group_name):
3581
+ """
3582
+ Remove the given {@link User} identified by username from the given {@link Group} identified by groupName.
3583
+ This method is idempotent i.e. if the membership is not present then no action will be taken.
3584
+
3585
+ :param username: str - username of user to add to group
3586
+ :param group_name: str - name of group to add user to
3587
+ :return: Current state of the group
3588
+ """
3589
+ url = f"rest/api/user/{username}/group/{group_name}"
3590
+ return self.delete(url)
3591
+
3374
3592
  # Space Permissions
3375
3593
  def get_all_space_permissions(self, space_key):
3376
3594
  """
@@ -3642,6 +3860,24 @@ class Confluence(AtlassianRestAPI):
3642
3860
 
3643
3861
  return self.post(url, data=data, headers=self.experimental_headers)
3644
3862
 
3863
+ def add_space_permission_json_rpc(self, space_key, user, permission):
3864
+ """
3865
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
3866
+ JSON-RPC APIs operate differently than REST APIs.
3867
+ To learn more about how to use these APIs,
3868
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
3869
+ """
3870
+ if self.api_version == "cloud" or self.cloud:
3871
+ return {}
3872
+ url = "rpc/json-rpc/confluenceservice-v2"
3873
+ data = {
3874
+ "jsonrpc": "2.0",
3875
+ "method": "addPermissionToSpace",
3876
+ "id": 9,
3877
+ "params": [permission, user, space_key],
3878
+ }
3879
+ return self.post(url, data=data).get("result") or {}
3880
+
3645
3881
  def remove_space_permission(self, space_key, user, permission):
3646
3882
  """
3647
3883
  The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
atlassian/errors.py CHANGED
@@ -7,6 +7,11 @@ class ApiError(Exception):
7
7
  super(ApiError, self).__init__(*args)
8
8
 
9
9
 
10
+ class JsonRPCError(Exception):
11
+ def __init__(self, *args):
12
+ super(JsonRPCError, self).__init__(*args)
13
+
14
+
10
15
  class ApiNotFoundError(ApiError):
11
16
  pass
12
17
 
@@ -25,3 +30,7 @@ class ApiConflictError(ApiError):
25
30
 
26
31
  class ApiNotAcceptable(ApiError):
27
32
  pass
33
+
34
+
35
+ class JsonRPCRestrictionsError(JsonRPCError):
36
+ pass
atlassian/insight.py CHANGED
@@ -28,7 +28,7 @@ class Insight(AtlassianRestAPI):
28
28
 
29
29
  def __cloud_init(self, *args, **kwargs):
30
30
  """
31
- Creates a InsightCloud specific version of Insight()
31
+ Creates an InsightCloud specific version of Insight()
32
32
 
33
33
  Returns:
34
34
  Insight(AtlassianRestAPI)