Use json.dumps for every detail in history

This works much better instead of just writing a str to the db and
expect it to be loaded just fine from json.loads
This commit is contained in:
AdvanticGmbH 2022-04-05 10:50:15 +02:00
parent 3df36adbf4
commit 44c9aff5db
3 changed files with 56 additions and 50 deletions

View File

@ -93,7 +93,7 @@ def extract_changelogs_from_a_history_entry(out_changes, history_entry, change_n
return
if "add_rrests" in history_entry.detail:
detail_dict = json.loads(history_entry.detail.replace("\'", ''))
detail_dict = json.loads(history_entry.detail)
else: # not a record entry
return
@ -362,13 +362,14 @@ def edit_key(key_id=None):
current_app.logger.error('Error: {0}'.format(e))
history = History(msg=history_message,
detail=str({
'key': apikey.id,
'role': apikey.role.name,
'description': apikey.description,
'domains': [domain.name for domain in apikey.domains],
'accounts': [a.name for a in apikey.accounts]
}),
detail=str(
json.dumps({
'key': apikey.id,
'role': apikey.role.name,
'description': apikey.description,
'domains': [domain.name for domain in apikey.domains],
'accounts': [a.name for a in apikey.accounts]
})),
created_by=current_user.username)
history.add()
@ -411,12 +412,13 @@ def manage_keys():
current_app.logger.info('Delete API key {0}'.format(apikey.id))
history = History(msg='Delete API key {0}'.format(apikey.id),
detail=str({
'key': history_apikey_id,
'role': history_apikey_role,
'description': history_apikey_description,
'domains': history_apikey_domains
}),
detail=str(
json.dumps({
'key': history_apikey_id,
'role': history_apikey_role,
'description': history_apikey_description,
'domains': history_apikey_domains
})),
created_by=current_user.username)
history.add()
@ -763,10 +765,7 @@ class DetailedHistory():
self.detailed_msg = ""
return
if 'add_rrest' in history.detail:
detail_dict = json.loads(history.detail.replace("\'", ''))
else:
detail_dict = json.loads(history.detail.replace("'", '"'))
detail_dict = json.loads(history.detail)
if 'domain_type' in detail_dict and 'account_id' in detail_dict: # this is a domain creation
self.detailed_msg = render_template_string("""
@ -1673,10 +1672,11 @@ def create_template():
result = t.create()
if result['status'] == 'ok':
history = History(msg='Add domain template {0}'.format(name),
detail=str({
'name': name,
'description': description
}),
detail=str(
json.dumps({
'name': name,
'description': description
})),
created_by=current_user.username)
history.add()
return redirect(url_for('admin.templates'))
@ -1720,10 +1720,11 @@ def create_template_from_zone():
result = t.create()
if result['status'] == 'ok':
history = History(msg='Add domain template {0}'.format(name),
detail=str({
'name': name,
'description': description
}),
detail=str(
json.dumps({
'name': name,
'description': description
})),
created_by=current_user.username)
history.add()
@ -1883,7 +1884,7 @@ def delete_template(template):
if result['status'] == 'ok':
history = History(
msg='Deleted domain template {0}'.format(template),
detail=str({'name': template}),
detail=str(json.dumps({'name': template})),
created_by=current_user.username)
history.add()
return redirect(url_for('admin.templates'))

View File

@ -409,11 +409,12 @@ def add():
domain_id = Domain().get_id_by_name(domain_name)
history = History(msg='Add domain {0}'.format(
pretty_domain_name(domain_name)),
detail=str({
detail=str(
json.dumps({
'domain_type': domain_type,
'domain_master_ips': domain_master_ips,
'account_id': account_id
}),
})),
created_by=current_user.username,
domain_id=domain_id)
history.add()
@ -464,7 +465,7 @@ def add():
msg=
'Failed to apply template {0} to {1}.'
.format(template.name, domain_name),
detail=str(result),
detail=str(json.dumps(result)),
created_by=current_user.username)
history.add()
return redirect(url_for('dashboard.dashboard'))
@ -617,10 +618,11 @@ def change_soa_edit_api(domain_name):
history = History(
msg='Update soa_edit_api for domain {0}'.format(
pretty_domain_name(domain_name)),
detail=str({
detail=str(
json.dumps({
"domain": domain_name,
"soa_edit_api": new_setting
}),
})),
created_by=current_user.username,
domain_id=d.get_id_by_name(domain_name))
history.add()

View File

@ -550,12 +550,13 @@ def signin_history(username, authenticator, success):
# Write history
History(msg='User {} authentication {}'.format(username, str_success),
detail=str({
"username": username,
"authenticator": authenticator,
"ip_address": request_ip,
"success": 1 if success else 0
}),
detail=str(
json.dumps({
"username": username,
"authenticator": authenticator,
"ip_address": request_ip,
"success": 1 if success else 0
})),
created_by='System').add()
# Get a list of Azure security groups the user is a member of
@ -864,13 +865,14 @@ def dyndns_update():
if result['status'] == 'ok':
history = History(
msg='DynDNS update: updated {} successfully'.format(hostname),
detail=str({
"domain": domain.name,
"record": hostname,
"type": rtype,
"old_value": oldip,
"new_value": str(ip)
}),
detail=str(
json.dumps({
"domain": domain.name,
"record": hostname,
"type": rtype,
"old_value": oldip,
"new_value": str(ip)
})),
created_by=current_user.username,
domain_id=domain.id)
history.add()
@ -906,11 +908,12 @@ def dyndns_update():
msg=
'DynDNS update: created record {0} in zone {1} successfully'
.format(hostname, domain.name, str(ip)),
detail=str({
"domain": domain.name,
"record": hostname,
"value": str(ip)
}),
detail=str(
json.dumps({
"domain": domain.name,
"record": hostname,
"value": str(ip)
})),
created_by=current_user.username,
domain_id=domain.id)
history.add()