Add history entries for association changes of domains

This commit is contained in:
AdvanticGmbH 2022-06-28 11:16:45 +02:00
parent 6a2ba1b1c3
commit cfab13824d
2 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import json
import re import re
import traceback import traceback
from flask import current_app from flask import current_app
from flask_login import current_user
from urllib.parse import urljoin from urllib.parse import urljoin
from distutils.util import strtobool from distutils.util import strtobool
@ -835,6 +836,7 @@ class Domain(db.Model):
headers = {'X-API-Key': self.PDNS_API_KEY, 'Content-Type': 'application/json'} headers = {'X-API-Key': self.PDNS_API_KEY, 'Content-Type': 'application/json'}
account_name_old = Account().get_name_by_id(domain.account_id)
account_name = Account().get_name_by_id(account_id) account_name = Account().get_name_by_id(account_id)
post_data = {"account": account_name} post_data = {"account": account_name}
@ -858,6 +860,13 @@ class Domain(db.Model):
self.update() self.update()
msg_str = 'Account changed for domain {0} successfully' msg_str = 'Account changed for domain {0} successfully'
current_app.logger.info(msg_str.format(domain_name)) current_app.logger.info(msg_str.format(domain_name))
history = History(msg='Update domain {0} associate account {1}'.format(domain.name, 'none' if account_name == '' else account_name),
detail = json.dumps({
'assoc_account': 'None' if account_name == '' else account_name,
'dissoc_account': 'None' if account_name_old == '' else account_name_old
}),
created_by=current_user.username)
history.add()
return {'status': 'ok', 'msg': 'account changed successfully'} return {'status': 'ok', 'msg': 'account changed successfully'}
except Exception as e: except Exception as e:

View File

@ -919,6 +919,16 @@ class DetailedHistory():
''', ''',
history_status=DetailedHistory.get_key_val(detail_dict, 'status'), history_status=DetailedHistory.get_key_val(detail_dict, 'status'),
history_msg=DetailedHistory.get_key_val(detail_dict, 'msg')) history_msg=DetailedHistory.get_key_val(detail_dict, 'msg'))
elif 'Update domain' in history.msg and 'associate account' in history.msg: # When an account gets associated or dissociate with domains
self.detailed_msg = render_template_string('''
<table class="table table-bordered table-striped">
<tr><td>Associate: </td><td>{{ history_assoc_account }}</td></tr>
<tr><td>Dissociate:</td><td>{{ history_dissoc_account }}</td></tr>
</table>
''',
history_assoc_account=DetailedHistory.get_key_val(detail_dict, 'assoc_account'),
history_dissoc_account=DetailedHistory.get_key_val(detail_dict, 'dissoc_account'))
# check for lower key as well for old databases # check for lower key as well for old databases
@staticmethod @staticmethod