From 6ba1254759007b817c71978bb841abbb3e154f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BECOT?= Date: Mon, 21 Feb 2022 17:31:37 +0100 Subject: [PATCH 1/2] feat: Make domain update optional in assoc_account --- powerdnsadmin/models/domain.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerdnsadmin/models/domain.py b/powerdnsadmin/models/domain.py index e30421d..382cdee 100644 --- a/powerdnsadmin/models/domain.py +++ b/powerdnsadmin/models/domain.py @@ -806,7 +806,7 @@ class Domain(db.Model): else: return {'status': 'error', 'msg': 'This domain does not exist'} - def assoc_account(self, account_id): + def assoc_account(self, account_id, update=True): """ Associate domain with a domain, specified by account id """ @@ -842,7 +842,8 @@ class Domain(db.Model): current_app.logger.error(jdata['error']) return {'status': 'error', 'msg': jdata['error']} else: - self.update() + if update: + self.update() msg_str = 'Account changed for domain {0} successfully' current_app.logger.info(msg_str.format(domain_name)) return {'status': 'ok', 'msg': 'account changed successfully'} From 84a183d913f0ec0d6bad8a1e9c1e81e0d9c16686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BECOT?= Date: Mon, 21 Feb 2022 17:32:44 +0100 Subject: [PATCH 2/2] fix: Disassociate domains from account before deletion --- powerdnsadmin/routes/api.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/powerdnsadmin/routes/api.py b/powerdnsadmin/routes/api.py index 4fce368..187f693 100644 --- a/powerdnsadmin/routes/api.py +++ b/powerdnsadmin/routes/api.py @@ -940,6 +940,18 @@ def api_delete_account(account_id): account = account_list[0] else: abort(404) + current_app.logger.debug( + f'Deleting Account {account.name}' + ) + + # Remove account association from domains first + if len(account.domains) > 0: + for domain in account.domains: + current_app.logger.info(f"Disassociating domain {domain.name} with {account.name}") + Domain(name=domain.name).assoc_account(None, update=False) + current_app.logger.info("Syncing all domains") + Domain().update() + current_app.logger.debug( "Deleting account {} ({})".format(account_id, account.name)) result = account.delete_account()