hub: [hasPerm] add strict behavior
This commit is contained in:
parent
946017930a
commit
a34896bddb
2 changed files with 33 additions and 1 deletions
|
|
@ -10897,9 +10897,11 @@ class RootExports(object):
|
|||
|
||||
listBuildroots = staticmethod(query_buildroots)
|
||||
|
||||
def hasPerm(self, perm):
|
||||
def hasPerm(self, perm, strict=False):
|
||||
"""Check if the logged-in user has the given permission. Return False if
|
||||
they do not have the permission, or if they are not logged-in."""
|
||||
if strict and not lookup_perm(perm):
|
||||
raise koji.GenericError('No such permission %s defined' % perm)
|
||||
return context.session.hasPerm(perm)
|
||||
|
||||
def getPerms(self):
|
||||
|
|
|
|||
30
tests/test_hub/test_perm_operations.py
Normal file
30
tests/test_hub/test_perm_operations.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestPerm(unittest.TestCase):
|
||||
|
||||
@mock.patch('kojihub.context')
|
||||
@mock.patch('kojihub.lookup_perm', return_value=None)
|
||||
def test_has_perm(self, lookup_perm, context):
|
||||
rv = kojihub.RootExports().hasPerm('perm')
|
||||
self.assertEqual(rv, context.session.hasPerm.return_value)
|
||||
lookup_perm.assert_not_called()
|
||||
context.session.hasPerm.assert_called_once_with('perm')
|
||||
|
||||
context.session.hasPerm.reset_mock()
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.RootExports().hasPerm('perm', strict=True)
|
||||
lookup_perm.assert_called_once_with('perm')
|
||||
context.session.hasPerm.assert_not_called()
|
||||
self.assertEqual(cm.exception.args[0],
|
||||
'No such permission perm defined')
|
||||
Loading…
Add table
Add a link
Reference in a new issue