Merge pull request #1377 from raunz/historyfix

API record change history format fix
This commit is contained in:
Matt Scott 2023-02-20 10:26:04 -05:00 committed by GitHub
commit 4da10a9d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1109,14 +1109,16 @@ def api_zone_forward(server_id, zone_id):
if Setting().get('enable_api_rr_history'):
if request.method in ['POST', 'PATCH']:
data = request.get_json(force=True)
for rrset_data in data['rrsets']:
history = History(msg='{0} zone {1} record of {2}'.format(
rrset_data['changetype'].lower(), rrset_data['type'],
rrset_data['name'].rstrip('.')),
detail=json.dumps(data),
created_by=g.apikey.description,
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
history.add()
history = History(
msg='Apply record changes to domain {0}'.format(zone_id.rstrip('.')),
detail = json.dumps({
'domain': zone_id.rstrip('.'),
'add_rrsets': list(filter(lambda r: r['changetype'] == "REPLACE", data['rrsets'])),
'del_rrsets': list(filter(lambda r: r['changetype'] == "DELETE", data['rrsets']))
}),
created_by=g.apikey.description,
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
history.add()
elif request.method == 'DELETE':
history = History(msg='Deleted zone {0}'.format(zone_id.rstrip('.')),
detail='',