From 66f8cd4cd7b048a2f1b60ce1c93da477ae199990 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 15 2019 06:54:37 +0000 Subject: PR#1160: hub: new listCGs RPC Merges #1160 https://pagure.io/koji/pull-request/1160 Fixes: #1566 hub: new listCGs RPC https://pagure.io/koji/issue/1566 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 724df28..8f05bce 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -8060,6 +8060,35 @@ def set_user_status(user, status): raise koji.GenericError('invalid user ID: %i' % user_id) +def list_cgs(): + """List all available content generators in the system + + :returns: A map of content generators, like {"name": data}. The data map + for each content generator has an "id" key for the content + generator ID, and a "users" key for the a list usernames who + are permitted to import for this content generator. + """ + + fields = {'content_generator.id': 'id', 'content_generator.name': 'name', + 'users.name': 'user_name'} + columns, aliases = zip(*fields.items()) + tables = ['cg_users'] + joins = ['content_generator ON content_generator.id = cg_users.cg_id', + 'users ON users.id = cg_users.user_id'] + clauses = ['cg_users.active = TRUE'] + query = QueryProcessor(tables=tables, aliases=aliases, columns=columns, + joins=joins, clauses=clauses) + cgs = {} + for result in query.iterate(): + cg_id = result['id'] + cg_name = result['name'] + user_name = result['user_name'] + if cg_name not in cgs: + cgs[cg_name] = {'id': cg_id, 'users': []} + cgs[cg_name]['users'].append(user_name) + return cgs + + def grant_cg_access(user, cg, create=False): """ Grant user access to act as the given content generator @@ -11068,6 +11097,7 @@ class RootExports(object): raise koji.GenericError('unknown user: %s' % username) set_user_status(user, koji.USER_STATUS['BLOCKED']) + listCGs = staticmethod(list_cgs) grantCGAccess = staticmethod(grant_cg_access) revokeCGAccess = staticmethod(revoke_cg_access)