From 1528bc0022368310b14f6a49b0c461fcb320439f Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Jun 28 2017 07:11:33 +0000 Subject: [PATCH 1/3] getUserPerms should throw GenericError when no user found --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 4fce02b..b86da43 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10603,7 +10603,8 @@ class RootExports(object): def getUserPerms(self, userID): """Get a list of the permissions granted to the user with the given ID.""" - return koji.auth.get_user_perms(userID) + user_info = get_user(userID, strict=True) + return koji.auth.get_user_perms(user_info['id']) def getAllPerms(self): """Get a list of all permissions in the system. Returns a list of maps. Each diff --git a/tests/test_hub/test_get_user_perms.py b/tests/test_hub/test_get_user_perms.py new file mode 100644 index 0000000..5112083 --- /dev/null +++ b/tests/test_hub/test_get_user_perms.py @@ -0,0 +1,25 @@ +import mock +import unittest + +import koji +import kojihub + + +class TestGetUserPerms(unittest.TestCase): + def setUp(self): + self.get_user = mock.patch('kojihub.get_user').start() + self.get_user_perms = mock.patch('koji.auth.get_user_perms').start() + + def tearDown(self): + mock.patch.stopall() + + def test_no_user(self): + self.get_user.side_effect = koji.GenericError + with self.assertRaises(koji.GenericError): + kojihub.RootExports().getUserPerms(123) + self.get_user_perms.assert_not_called() + + def test_normal(self): + self.get_user.return_value = {'id': 123, 'name': 'testuser'} + kojihub.RootExports().getUserPerms(123) + self.get_user_perms.assert_called_once_with(123) From f36d487d4e7ab9307fb37c556830aa28f564d160 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Jun 27 2017 16:22:26 +0000 Subject: [PATCH 2/3] allow getUserPerm accepting None arg --- diff --git a/hub/kojihub.py b/hub/kojihub.py index b86da43..4bdf569 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10601,7 +10601,7 @@ class RootExports(object): """Get a list of the permissions granted to the currently logged-in user.""" return context.session.getPerms() - def getUserPerms(self, userID): + def getUserPerms(self, userID=None): """Get a list of the permissions granted to the user with the given ID.""" user_info = get_user(userID, strict=True) return koji.auth.get_user_perms(user_info['id']) From 6fc00f2531e05c92d805460e1a4f4a2b6d373323 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Jun 28 2017 13:12:05 +0000 Subject: [PATCH 3/3] explain new behavior in docstring of getUserPerms --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 4bdf569..f9e7c7c 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10602,7 +10602,10 @@ class RootExports(object): return context.session.getPerms() def getUserPerms(self, userID=None): - """Get a list of the permissions granted to the user with the given ID.""" + """Get a list of the permissions granted to the user with the given ID/name. + Options: + - userID: User ID or username. If no userID provided, current login user's + permissions will be listed.""" user_info = get_user(userID, strict=True) return koji.auth.get_user_perms(user_info['id'])