editSideTag API call
New API call for editing basic info on sidetags. Needs to be applied with proper policies. Fixes: https://pagure.io/koji/issue/1998
This commit is contained in:
parent
164e4bfb6e
commit
76352587fa
4 changed files with 94 additions and 19 deletions
|
|
@ -93,3 +93,29 @@ def handle_list_sidetags(options, session, args):
|
|||
|
||||
for tag in session.listSideTags(basetag=opts.basetag, user=user):
|
||||
print(tag["name"])
|
||||
|
||||
|
||||
@export_cli
|
||||
def handle_edit_sidetag(options, session, args):
|
||||
"Edit sidetag"
|
||||
usage = _("usage: %(prog)s edit-sidetag [options]")
|
||||
usage += _("\n(Specify the --help global option for a list of other help options)")
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument("sidetag", help="name of sidetag")
|
||||
parser.add_argument("--debuginfo", action="store_true", default=None,
|
||||
help=_("Generate debuginfo repository"))
|
||||
parser.add_argument("--no-debuginfo", action="store_false", dest="debuginfo")
|
||||
parser.add_argument("-b", "--block", action="append", help="block package")
|
||||
parser.add_argument("-u", "--unblock", action="append", help="unblock package")
|
||||
|
||||
opts = parser.parse_args(args)
|
||||
|
||||
activate_session(session, options)
|
||||
|
||||
kwargs = {
|
||||
'block_pkgs': opts.block,
|
||||
'unblock_pkgs': opts.unblock,
|
||||
}
|
||||
if opts.debuginfo is not None:
|
||||
kwargs['debuginfo'] = opts.debuginfo
|
||||
session.editSideTag(opts.sidetag, **kwargs)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from kojihub import ( # noqa: F402
|
|||
get_tag,
|
||||
get_user,
|
||||
nextval
|
||||
_edit_tag,
|
||||
)
|
||||
|
||||
CONFIG_FILE = "/etc/koji-hub/plugins/sidetag.conf"
|
||||
|
|
@ -170,6 +171,49 @@ def listSideTags(basetag=None, user=None, queryOpts=None):
|
|||
return query.execute()
|
||||
|
||||
|
||||
@export
|
||||
def editSideTag(sidetag, debuginfo=None, block_pkgs=None, unblock_pkgs=None):
|
||||
"""Restricted ability to modify sidetags, parent tag must have:
|
||||
sidetag_debuginfo_allowed: 1
|
||||
sidetag_package_list_allowed: 1
|
||||
in extra, if modifying functions should work. For blocking/unblocking
|
||||
further policy must be compatible with these operations.
|
||||
|
||||
:param sidetag: sidetag id or name
|
||||
:type sidetag: int or str
|
||||
:param debuginfo: set or disable debuginfo repo generation
|
||||
:type debuginfo: bool
|
||||
:param block_pkgs: package names to be blocked in sidetag
|
||||
:type block_pkgs: list of str
|
||||
:param unblock_pkgs: package names to be unblocked in sidetag
|
||||
:type unblock_pkgs: list of str
|
||||
"""
|
||||
|
||||
context.session.assertLogin()
|
||||
user = get_user(context.session.user_id, strict=True)
|
||||
tag = get_tag(sidetag, strict=True)
|
||||
|
||||
if not sidetag["extra"].get("sidetag"):
|
||||
raise koji.GenericError("Not a sidetag: %(name)s" % sidetag)
|
||||
if sidetag["extra"].get("sidetag_user_id") != user["id"]:
|
||||
if not context.session.hasPerm("admin"):
|
||||
raise koji.ActionNotAllowed("This is not your sidetag")
|
||||
|
||||
parent_id = getInheritanceData(sidetag)[0]['parent_id']
|
||||
parent = get_tag(parent_id)
|
||||
|
||||
if debuginfo is not None and not parent['extra'].get('sidetag_debuginfo_allowed'):
|
||||
raise koji.GenericError("Debuginfo setting is not allowed in parent tag.")
|
||||
if (block_pkgs or unblock_pkgs) and not parent['extra'].get('sidetag_package_list_allowed'):
|
||||
raise koji.GenericError("Package un/blocking is not allowed in parent tag.")
|
||||
|
||||
if debuginfo is not None:
|
||||
_edit_tag(sidetag, extra={'with_debuginfo': bool(debuginfo)})
|
||||
for pkg in block_pkgs:
|
||||
pkglist_block(sidetag, pkg)
|
||||
for pkg in unblock_pkgs:
|
||||
pkglist_unblock(sidetag, pkg)
|
||||
|
||||
def handle_sidetag_untag(cbtype, *args, **kws):
|
||||
"""Remove a side tag when its last build is untagged
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue