From 57af3decbccbf2e0b91c0daaeabd8503c7c8e525 Mon Sep 17 00:00:00 2001
From: Jana Cupova <jcupova@redhat.com>
Date: Feb 17 2021 07:15:40 +0000
Subject: Unite add-tag-inheritance --force with hub


Added force argument to API call setTagInheritance and calls related to
this call.

Fixes: https://pagure.io/koji/issue/2614

---

diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 7118990..b2f5366 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -5201,7 +5201,7 @@ def handle_add_tag_inheritance(goptions, session, args):
     new_data['pkg_filter'] = options.pkg_filter or ''
 
     inheritanceData.append(new_data)
-    session.setInheritanceData(tag['id'], inheritanceData)
+    session.setInheritanceData(tag['id'], inheritanceData, force=options.force)
 
 
 def handle_edit_tag_inheritance(goptions, session, args):
diff --git a/hub/kojihub.py b/hub/kojihub.py
index c59aed8..e6117a1 100644
--- a/hub/kojihub.py
+++ b/hub/kojihub.py
@@ -675,13 +675,13 @@ def readDescendantsData(tag_id, event=None):
     return data
 
 
-def writeInheritanceData(tag_id, changes, clear=False):
+def writeInheritanceData(tag_id, changes, clear=False, force=False):
     """Add or change inheritance data for a tag"""
     context.session.assertPerm('tag')
-    _writeInheritanceData(tag_id, changes, clear)
+    _writeInheritanceData(tag_id, changes, clear, force=force)
 
 
-def _writeInheritanceData(tag_id, changes, clear=False):
+def _writeInheritanceData(tag_id, changes, clear=False, force=False):
     """Add or change inheritance data for a tag"""
     fields = ('parent_id', 'priority', 'maxdepth', 'intransitive', 'noconfig', 'pkg_filter')
     if isinstance(changes, dict):
@@ -696,7 +696,7 @@ def _writeInheritanceData(tag_id, changes, clear=False):
             if f not in link:
                 raise koji.GenericError("No value for %s" % f)
         parent_id = link['parent_id']
-        if parent_id in parent_ids:
+        if parent_id in parent_ids and not force:
             raise koji.GenericError("Changes should not contain duplicated"
                                     " parent_id(%i)" % parent_id)
         else:
@@ -11463,7 +11463,7 @@ class RootExports(object):
         tag = get_tag_id(tag, strict=True)
         return readInheritanceData(tag, event)
 
-    def setInheritanceData(self, tag, data, clear=False):
+    def setInheritanceData(self, tag, data, clear=False, force=False):
         """
         Set inheritance relationships for a tag.
 
@@ -11479,11 +11479,12 @@ class RootExports(object):
         :param bool clear: Wipe out all existing inheritance rules and only
                            apply the ones you submit here. If unspecified,
                            this defaults to False.
+        :param bool force: override inheritance relationship for tag
         """
         # verify existence of tag and/or convert name to id
         tag = get_tag_id(tag, strict=True)
         context.session.assertPerm('tag')
-        return writeInheritanceData(tag, data, clear=clear)
+        return writeInheritanceData(tag, data, clear=clear, force=force)
 
     def getFullInheritance(self, tag, event=None, reverse=False, stops=None, jumps=None):
         """

