Skip to content

Commit

Permalink
Fix: List DDAs in descending order
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <george.padayatti@igrant.io>
  • Loading branch information
georgepadayatti committed Apr 9, 2024
1 parent 022af71 commit 94578e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
18 changes: 13 additions & 5 deletions data_disclosure_agreement/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ def list_unique_dda_template_ids() -> typing.List[str]:
return list(set(unique))

@staticmethod
def list_unique_dda_template_ids_for_a_data_source(data_source_id,**kwargs) -> typing.List[str]:
unique = []
ddas = DataDisclosureAgreement.list_by_data_source_id(data_source_id=data_source_id,**kwargs)
def list_unique_dda_template_ids_for_a_data_source(data_source_id, **kwargs) -> typing.List[str]:
unique_set = set()
ddas = DataDisclosureAgreement.list_by_data_source_id(data_source_id=data_source_id, **kwargs)
for dda in ddas:
unique.append(dda.templateId)
return list(set(unique))
unique_set.add(dda.templateId)

# Convert set to list while preserving the order of insertion
unique_list = []
for item in ddas:
if item.templateId in unique_set:
unique_list.append(item.templateId)
unique_set.remove(item.templateId)

return unique_list

def __str__(self):
return str(self.id)
11 changes: 8 additions & 3 deletions webhook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ def receive_data_disclosure_agreement(request):
"codeOfConduct": response["dda"]["codeOfConduct"],
"connection": dda_connection,
}
post_save.connect(
query_ddas_and_update_is_latest_flag_to_false_for_previous_versions,
DataDisclosureAgreement,

# Iterate through existing DDAs and mark `isLatestVersion=false`
existing_ddas = DataDisclosureAgreement.objects.filter(
templateId=dda_template_id, isLatestVersion=True
)
for existing_dda in existing_ddas:
existing_dda.isLatestVersion = False
existing_dda.save()


dda = DataDisclosureAgreement.objects.create(
version=dda_version,
Expand Down

0 comments on commit 94578e4

Please sign in to comment.