Просмотр исходного кода

fix(api): allow re-setting an auto-delegation, #370

Peter Thomassen 4 лет назад
Родитель
Сommit
f00429d9c3
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      api/desecapi/models.py

+ 6 - 4
api/desecapi/models.py

@@ -377,8 +377,12 @@ class Domain(ExportModelOperationsMixin('Domain'), models.Model):
             raise ValueError('Cannot update delegation of %s as it is not an immediate child domain of %s.' %
             raise ValueError('Cannot update delegation of %s as it is not an immediate child domain of %s.' %
                              (child_domain.name, self.name))
                              (child_domain.name, self.name))
 
 
+        # Always remove delegation so that we con properly recreate it
+        for rrset in self.rrset_set.filter(subname=child_subname, type__in=['NS', 'DS']):
+            rrset.delete()
+
         if child_domain.pk:
         if child_domain.pk:
-            # Domain real: set delegation
+            # Domain real: (re-)set delegation
             child_keys = child_domain.keys
             child_keys = child_domain.keys
             if not child_keys:
             if not child_keys:
                 raise APIException('Cannot delegate %s, as it currently has no keys.' % child_domain.name)
                 raise APIException('Cannot delegate %s, as it currently has no keys.' % child_domain.name)
@@ -388,9 +392,7 @@ class Domain(ExportModelOperationsMixin('Domain'), models.Model):
                                  contents=[ds for k in child_keys for ds in k['ds']])
                                  contents=[ds for k in child_keys for ds in k['ds']])
             metrics.get('desecapi_autodelegation_created').inc()
             metrics.get('desecapi_autodelegation_created').inc()
         else:
         else:
-            # Domain not real: remove delegation
-            for rrset in self.rrset_set.filter(subname=child_subname, type__in=['NS', 'DS']):
-                rrset.delete()
+            # Domain not real: that's it
             metrics.get('desecapi_autodelegation_deleted').inc()
             metrics.get('desecapi_autodelegation_deleted').inc()
 
 
     def delete(self):
     def delete(self):