Merge pull request #739 from sshipway/sorting

Sort rrset members by content before comparison to ensure correct compare
This commit is contained in:
Khanh Ngo 2020-05-24 21:06:51 +07:00 committed by GitHub
commit 5ac126f349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -14,6 +14,11 @@ from .setting import Setting
from .domain import Domain from .domain import Domain
from .domain_setting import DomainSetting from .domain_setting import DomainSetting
def byRecordContent(e):
return e['content']
def byRecordContentPair(e):
return e[0]['content']
class Record(object): class Record(object):
""" """
@ -60,7 +65,14 @@ class Record(object):
.format(e)) .format(e))
return [] return []
return jdata['rrsets'] rrsets=[]
for r in jdata['rrsets']:
while len(r['comments'])<len(r['records']):
r['comments'].append({"content":"", "account":""})
r['records'], r['comments'] = (list(t) for t in zip(*sorted(zip(r['records'],r['comments']),key=byRecordContentPair)))
rrsets.append(r)
return rrsets
def add(self, domain_name, rrset): def add(self, domain_name, rrset):
""" """
@ -131,6 +143,11 @@ class Record(object):
for r in rrsets[1:]: for r in rrsets[1:]:
rrest['records'] = rrest['records'] + r['records'] rrest['records'] = rrest['records'] + r['records']
rrest['comments'] = rrest['comments'] + r['comments'] rrest['comments'] = rrest['comments'] + r['comments']
while len(rrest['comments'])<len(rrest['records']):
rrest['comments'].append({"content":"", "account":""})
zipped_list = zip(rrest['records'],rrest['comments'])
tuples = zip(*sorted(zipped_list,key=byRecordContentPair))
rrest['records'], rrest['comments'] = [list(t) for t in tuples]
return rrest return rrest
def build_rrsets(self, domain_name, submitted_records): def build_rrsets(self, domain_name, submitted_records):
@ -185,7 +202,10 @@ class Record(object):
record_comments = [{ record_comments = [{
"content": record["record_comment"], "content": record["record_comment"],
"account": "" "account": ""
}] if record.get("record_comment") else [] }] if record.get("record_comment") else [{
"content": "",
"account": ""
}]
# Add the formatted record to rrsets list # Add the formatted record to rrsets list
rrsets.append({ rrsets.append({
@ -237,7 +257,8 @@ class Record(object):
# comparison between current and submitted rrsets # comparison between current and submitted rrsets
for r in current_rrsets: for r in current_rrsets:
for comment in r['comments']: for comment in r['comments']:
del comment['modified_at'] if 'modified_at' in comment:
del comment['modified_at']
# List of rrsets to be added # List of rrsets to be added
new_rrsets = {"rrsets": []} new_rrsets = {"rrsets": []}

View File

@ -99,14 +99,17 @@ def domain(domain_name):
# PDA jinja2 template can understand. # PDA jinja2 template can understand.
index = 0 index = 0
for record in r['records']: for record in r['records']:
if (len(r['comments'])>index):
c=r['comments'][index]['content']
else:
c=''
record_entry = RecordEntry( record_entry = RecordEntry(
name=r_name, name=r_name,
type=r['type'], type=r['type'],
status='Disabled' if record['disabled'] else 'Active', status='Disabled' if record['disabled'] else 'Active',
ttl=r['ttl'], ttl=r['ttl'],
data=record['content'], data=record['content'],
comment=r['comments'][index]['content'] comment=c,
if r['comments'] else '',
is_allowed_edit=True) is_allowed_edit=True)
index += 1 index += 1
records.append(record_entry) records.append(record_entry)