unify return values for permission denied

Fixes: https://pagure.io/koji/issue/1776
This commit is contained in:
Tomas Kopecek 2019-11-08 09:06:11 -05:00
parent 5c1c25db7e
commit bf45d6927f
5 changed files with 78 additions and 72 deletions

View file

@ -65,8 +65,8 @@ def handle_add_group(goptions, session, args):
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('tag')):
print("This action requires tag or admin privileges")
return 1
parser.error(_("This action requires tag or admin privileges"))
assert False # pragma: no cover
dsttag = session.getTag(tag)
if not dsttag:
@ -96,8 +96,8 @@ def handle_block_group(goptions, session, args):
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('tag')):
print("This action requires tag or admin privileges")
return 1
parser.error(_("This action requires tag or admin privileges"))
assert False # pragma: no cover
dsttag = session.getTag(tag)
if not dsttag:
@ -143,7 +143,7 @@ def handle_remove_group(goptions, session, args):
def handle_assign_task(goptions, session, args):
"[admin] Assign a task to a host"
usage = _('usage: %prog assign-task task_id hostname')
usage = _('usage: %prog assign-task <task_id> <hostname>')
usage += _('\n(Specify the --help global option for a list of other help options)')
parser = OptionParser(usage=usage)
parser.add_option('-f', '--force', action='store_true', default=False,
@ -170,8 +170,8 @@ def handle_assign_task(goptions, session, args):
activate_session(session, goptions)
if not session.hasPerm('admin'):
print("This action requires admin privileges")
return 1
parser.error(_("This action requires admin privileges"))
assert False # pragma: no cover
ret = session.assignTask(task_id, hostname, force)
if ret:
@ -3409,6 +3409,7 @@ def handle_clone_tag(goptions, session, args):
if not options.test and not (session.hasPerm('admin') or session.hasPerm('tag')):
parser.error(_("This action requires tag or admin privileges"))
assert False # pragma: no cover
if args[0] == args[1]:
parser.error(_('Source and destination tags must be different.'))
@ -3861,8 +3862,8 @@ def handle_add_target(goptions, session, args):
dest_tag = name
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('target')):
print("This action requires target or admin privileges")
return 1
parser.error(_("This action requires target or admin privileges"))
assert False # pragma: no cover
chkbuildtag = session.getTag(build_tag)
chkdesttag = session.getTag(dest_tag)
@ -3896,8 +3897,8 @@ def handle_edit_target(goptions, session, args):
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('target')):
print("This action requires target or admin privileges")
return
parser.error(_("This action requires target or admin privileges"))
assert False # pragma: no cover
targetInfo = session.getBuildTarget(args[0])
if targetInfo == None:
@ -3939,8 +3940,8 @@ def handle_remove_target(goptions, session, args):
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('target')):
print("This action requires target or admin privileges")
return
parser.error(_("This action requires target or admin privileges"))
assert False # pragma: no cover
target = args[0]
target_info = session.getBuildTarget(target)
@ -3964,8 +3965,8 @@ def handle_remove_tag(goptions, session, args):
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('tag')):
print("This action requires tag or admin privileges")
return
parser.error(_("This action requires tag or admin privileges"))
assert False # pragma: no cover
tag = args[0]
tag_info = session.getTag(tag)
@ -4964,8 +4965,8 @@ def handle_add_tag(goptions, session, args):
assert False # pragma: no cover
activate_session(session, goptions)
if not (session.hasPerm('admin') or session.hasPerm('tag')):
print("This action requires tag or admin privileges")
return
parser.error(_("This action requires tag or admin privileges"))
assert False # pragma: no cover
opts = {}
if options.parent:
opts['parent'] = options.parent