#490 getUserPerms should throw GenericError when no user found
Merged 6 years ago by mikem. Opened 6 years ago by julian8628.
julian8628/koji get-user-perm  into  master

file modified
+7 -3
@@ -10601,9 +10601,13 @@ 

          """Get a list of the permissions granted to the currently logged-in user."""

          return context.session.getPerms()

  

-     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)

+     def getUserPerms(self, userID=None):

+         """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'])

  

      def getAllPerms(self):

          """Get a list of all permissions in the system.  Returns a list of maps.  Each

@@ -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)

to fix issue#486

When specified userID is not found, GenericError will be thrown instead of [] result

GenericError: No such user: xxxx

If user exists and no perm for this user, the result will keep [] as usual time.

This change will also make getUserPerms accepts username as argument. It's not the same as the old behavior.

1 new commit added

  • allow getUserPerm accepting None arg
6 years ago

also submit a commit#f36d487 to make None as the default value of this API's argument -- userID.
If no userID provided when invoking. it will get current login user's perms as default.

Can you expand docstring on this new behaviour?

Can you expand docstring on this new behaviour?

Updated :smoking:

1 new commit added

  • explain new behavior in docstring of getUserPerms
6 years ago

Commit 801e166 fixes this pull-request

Pull-Request has been merged by mikem@redhat.com

6 years ago