Add record comment

This commit is contained in:
Khanh Ngo
2019-12-09 17:50:48 +07:00
parent c1fae6f3dd
commit bca3c45e37
10 changed files with 158 additions and 64 deletions

View File

@ -851,7 +851,8 @@ def create_template_from_zone():
status=True
if subrecord['disabled'] else False,
ttl=jr['ttl'],
data=subrecord['content'])
data=subrecord['content'],
comment=jr['comment_data']['content'])
records.append(record)
else:
for jr in jrecords:
@ -863,7 +864,8 @@ def create_template_from_zone():
type=jr['type'],
status=True if jr['disabled'] else False,
ttl=jr['ttl'],
data=jr['content'])
data=jr['content'],
comment=jr['comment_data']['content'])
records.append(record)
result_records = t.replace_records(records)
@ -918,7 +920,8 @@ def edit_template(template):
type=jr.type,
status='Disabled' if jr.status else 'Active',
ttl=jr.ttl,
data=jr.data)
data=jr.data,
comment=jr.comment if jr.comment else '')
records.append(record)
return render_template('template_edit.html',
@ -948,12 +951,14 @@ def apply_records(template):
name = '@' if j['record_name'] in ['@', ''] else j['record_name']
type = j['record_type']
data = j['record_data']
comment = j['record_comment']
disabled = True if j['record_status'] == 'Disabled' else False
ttl = int(j['record_ttl']) if j['record_ttl'] else 3600
dtr = DomainTemplateRecord(name=name,
type=type,
data=data,
comment=comment,
status=disabled,
ttl=ttl)
records.append(dtr)

View File

@ -59,6 +59,7 @@ def domain(domain_name):
subrecord['disabled'] else 'Active',
ttl=jr['ttl'],
data=subrecord['content'],
comment=jr['comment_data']['content'],
is_allowed_edit=True)
records.append(record)
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
@ -80,6 +81,7 @@ def domain(domain_name):
status='Disabled' if jr['disabled'] else 'Active',
ttl=jr['ttl'],
data=jr['content'],
comment=jr['comment_data']['content'],
is_allowed_edit=True)
records.append(record)
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
@ -108,8 +110,9 @@ def add():
account_id = request.form.getlist('accountid')[0]
if ' ' in domain_name or not domain_name or not domain_type:
return render_template('errors/400.html',
msg="Please enter a valid domain name"), 400
return render_template(
'errors/400.html',
msg="Please enter a valid domain name"), 400
if domain_type == 'slave':
if request.form.getlist('domain_master_address'):
@ -140,8 +143,7 @@ def add():
history.add()
# grant user access to the domain
Domain(name=domain_name).grant_privileges(
[current_user.id])
Domain(name=domain_name).grant_privileges([current_user.id])
# apply template if needed
if domain_template != '0':
@ -157,7 +159,8 @@ def add():
'record_name': template_record.name,
'record_status': template_record.status,
'record_ttl': template_record.ttl,
'record_type': template_record.type
'record_type': template_record.type,
'comment_data': [{'content': template_record.comment, 'account': ''}]
}
record_data.append(record_row)
r = Record()
@ -341,6 +344,18 @@ def record_apply(domain_name):
'Domain name {0} does not exist'.format(domain_name)
}), 404)
# Modify the record's comment data. We append
# the "current_user" into account field as it
# a field with user-defined meaning
for sr in submitted_record:
if sr.get('record_comment'):
sr['comment_data'] = [{
'content': sr['record_comment'],
'account': current_user.username
}]
else:
sr['comment_data'] = []
r = Record()
result = r.apply(domain_name, submitted_record)
if result['status'] == 'ok':