Skip to content

Commit

Permalink
add required parameter field 'permissions' to my_permissions() (#1472)
Browse files Browse the repository at this point in the history
for Jira Cloud
  • Loading branch information
codectl committed Aug 24, 2022
1 parent 009ec9f commit 968d983
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
9 changes: 9 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,14 +2630,20 @@ def my_permissions(
projectId: Optional[str] = None,
issueKey: Optional[str] = None,
issueId: Optional[str] = None,
permissions: Optional[str] = None,
) -> Dict[str, Dict[str, Dict[str, str]]]:
"""Get a dict of all available permissions on the server.
``permissions`` is a comma-separated value list of permission keys that is
required in Jira Cloud. For possible and allowable permission values, see
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-permission-schemes/#built-in-permissions
Args:
projectKey (Optional[str]): limit returned permissions to the specified project
projectId (Optional[str]): limit returned permissions to the specified project
issueKey (Optional[str]): limit returned permissions to the specified issue
issueId (Optional[str]): limit returned permissions to the specified issue
permissions (Optional[str]): limit returned permissions to the specified csv permission keys (cloud required field)
Returns:
Dict[str, Dict[str, Dict[str, str]]]
Expand All @@ -2651,6 +2657,9 @@ def my_permissions(
params["issueKey"] = issueKey
if issueId is not None:
params["issueId"] = issueId
if permissions is not None:
params["permissions"] = permissions

return self._get_json("mypermissions", params=params)

# Priorities
Expand Down
49 changes: 46 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from jira import JIRA, Issue, JIRAError
from jira.client import ResultList
from jira.resources import Dashboard, Resource, cls_for_resource
from tests.conftest import JiraTestCase, rndpassword
from tests.conftest import JiraTestCase, allow_on_cloud, rndpassword

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,9 +154,9 @@ def test_fields(self):
self.assertGreater(len(fields), 10)


class MyPermissionsTests(JiraTestCase):
class MyPermissionsServerTests(JiraTestCase):
def setUp(self):
JiraTestCase.setUp(self)
super().setUp()
self.issue_1 = self.test_manager.project_b_issue1

def test_my_permissions(self):
Expand All @@ -178,6 +178,49 @@ def test_my_permissions_by_issue(self):
self.assertGreaterEqual(len(perms["permissions"]), 10)


@allow_on_cloud
class MyPermissionsCloudTests(JiraTestCase):
def setUp(self):
super().setUp()
if not self.jira._is_cloud:
self.skipTest("cloud only test class")
self.issue_1 = self.test_manager.project_b_issue1
self.permission_keys = "BROWSE_PROJECTS,CREATE_ISSUES,ADMINISTER_PROJECTS"

def test_my_permissions(self):
perms = self.jira.my_permissions(permissions=self.permission_keys)
self.assertEqual(len(perms["permissions"]), 3)

def test_my_permissions_by_project(self):
perms = self.jira.my_permissions(
projectKey=self.test_manager.project_a, permissions=self.permission_keys
)
self.assertEqual(len(perms["permissions"]), 3)
perms = self.jira.my_permissions(
projectId=self.test_manager.project_a_id, permissions=self.permission_keys
)
self.assertEqual(len(perms["permissions"]), 3)

def test_my_permissions_by_issue(self):
perms = self.jira.my_permissions(
issueKey=self.issue_1, permissions=self.permission_keys
)
self.assertEqual(len(perms["permissions"]), 3)
perms = self.jira.my_permissions(
issueId=self.test_manager.project_b_issue1_obj.id,
permissions=self.permission_keys,
)
self.assertEqual(len(perms["permissions"]), 3)

def test_missing_required_param_my_permissions_raises_exception(self):
with self.assertRaises(JIRAError):
self.jira.my_permissions()

def test_invalid_param_my_permissions_raises_exception(self):
with self.assertRaises(JIRAError):
self.jira.my_permissions("INVALID_PERMISSION")


class SearchTests(JiraTestCase):
def setUp(self):
JiraTestCase.setUp(self)
Expand Down

0 comments on commit 968d983

Please sign in to comment.