cli: [list-permissions] backward compatibility for getUserPermsInheritance call

fixes: #3959
This commit is contained in:
Yu Ming Zhu 2023-12-08 23:52:15 +00:00
parent e55303c2ce
commit 7b1f2a6137
2 changed files with 37 additions and 5 deletions

View file

@ -2176,11 +2176,21 @@ def handle_list_permissions(goptions, session, args):
user = session.getUser(options.user)
if not user:
error("No such user: %s" % options.user)
for p, groups in session.getUserPermsInheritance(user['id']).items():
p = {'name': p}
if groups != [None]:
p['description'] = 'inherited from: %s' % ', '.join(groups)
perms.append(p)
try:
for p, groups in session.getUserPermsInheritance(user['id']).items():
p = {'name': p}
if groups != [None]:
p['description'] = 'inherited from: %s' % ', '.join(groups)
perms.append(p)
except koji.GenericError as e:
# backwards compatible
# TODO: can be removed in 1.36
if "Invalid method" in str(e):
warn("Old hub doesn't support Inherited Group Permissions.")
for p in session.getUserPerms(user['id']):
perms.append({'name': p})
else:
raise
else:
for p in session.getAllPerms():
perms.append({'name': p['name'], 'description': p['description']})