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

bugfix/mypermissions args #1473

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,7 @@ 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.

Expand All @@ -2638,6 +2639,7 @@ def my_permissions(
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 +2653,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
47 changes: 44 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,11 @@ def test_fields(self):
self.assertGreater(len(fields), 10)


class MyPermissionsTests(JiraTestCase):
class MyPermissionsServerTests(JiraTestCase):
def setUp(self):
JiraTestCase.setUp(self)
super().setUp()
if self.jira._is_cloud:
self.skipTest("server only test class")
self.issue_1 = self.test_manager.project_b_issue1

def test_my_permissions(self):
Expand All @@ -178,6 +180,45 @@ 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_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