From d7aa417799841009e25835e6eeaf97161013dd65 Mon Sep 17 00:00:00 2001 From: Jason Syrotuck Date: Fri, 27 Oct 2023 12:16:26 -0700 Subject: [PATCH] [FIX] - Only update state on connection webhooks, sort does not return (#2761) --- .../app/api/parties/party/models/party.py | 13 ++++++++----- .../verifiable_credentials/models/connection.py | 2 +- .../resources/verifiable_credential_webhook.py | 15 ++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/services/core-api/app/api/parties/party/models/party.py b/services/core-api/app/api/parties/party/models/party.py index aeeb441b25..a6fed41a83 100644 --- a/services/core-api/app/api/parties/party/models/party.py +++ b/services/core-api/app/api/parties/party/models/party.py @@ -74,7 +74,10 @@ class Party(SoftDeleteMixin, AuditMixin, Base): 'PartyVerifiableCredentialConnection', lazy='select', uselist=True, - order_by='desc(PartyVerifiableCredentialConnection.connection_state)',) + order_by='desc(PartyVerifiableCredentialConnection.update_timestamp)',) + + + @hybrid_property def name(self): @@ -114,13 +117,13 @@ def business_roles_codes(self): @hybrid_property def digital_wallet_connection_status(self): - dwi = list(set([i.connection_state for i in self.digital_wallet_invitations if i.connection_state])).sort() # filter empty conn_state + dwi = list(set([i.connection_state for i in self.digital_wallet_invitations if i.connection_state])) + dwi.sort() if dwi: - current_app.logger.warning(dwi) - if "active" in dwi: + if "completed" in dwi or "active" in dwi: return "active" else: - return dwi[0].connection_state # active >> invitation + return dwi[0].connection_state else: return None diff --git a/services/core-api/app/api/verifiable_credentials/models/connection.py b/services/core-api/app/api/verifiable_credentials/models/connection.py index 9566dbdbd2..541d62d5ea 100644 --- a/services/core-api/app/api/verifiable_credentials/models/connection.py +++ b/services/core-api/app/api/verifiable_credentials/models/connection.py @@ -19,7 +19,7 @@ class PartyVerifiableCredentialConnection(AuditMixin, Base): def __repr__(self): - return '' % (self.party_guid, self.connection_state or "UNKNOWN") + return '' % (self.party_guid, self.connection_state) @classmethod def find_by_party_guid(cls, party_guid) -> "PartyVerifiableCredentialConnection": diff --git a/services/core-api/app/api/verifiable_credentials/resources/verifiable_credential_webhook.py b/services/core-api/app/api/verifiable_credentials/resources/verifiable_credential_webhook.py index 82b7ee62f1..bbea62161c 100644 --- a/services/core-api/app/api/verifiable_credentials/resources/verifiable_credential_webhook.py +++ b/services/core-api/app/api/verifiable_credentials/resources/verifiable_credential_webhook.py @@ -15,6 +15,7 @@ CONNECTIONS = "connections" CREDENTIAL_OFFER = "issue_credential" OUT_OF_BAND = "out_of_band" +PING = "ping" class VerifiableCredentialWebhookResource(Resource, UserMixin): @api.doc(description='Endpoint to recieve webhooks from Traction.', params={}) @@ -32,16 +33,7 @@ def post(self, topic): vc_conn.save() current_app.logger.info(f"Updated party_vc_conn connection_id={vc_conn.connection_id} with state={new_state}") elif topic == OUT_OF_BAND: - invitation_id = webhook_body["invi_msg_id"] - vc_conn = PartyVerifiableCredentialConnection.query.unbound_unsafe().filter_by(invitation_id=invitation_id).first() - assert vc_conn, f"out_of_band.invi_msg_id={invitation_id} not found" - new_state = webhook_body["state"] - if new_state == "await-response": - vc_conn.connection_state=new_state - vc_conn.save() - current_app.logger.info(f"Updated party_vc_conn invitation_id={invitation_id} with state={new_state}") - else: - current_app.logger.debug(f"do not update connection_state with oob_message state") + current_app.logger.info(f"out-of-band message invi_msg_id={webhook_body['invi_mds_id']}, state={webhook_body['state']}") elif topic == CREDENTIAL_OFFER: cred_exch_id = webhook_body["credential_exchange_id"] cred_exch_record = PartyVerifiableCredentialMinesActPermit.query.unbound_unsafe().filter_by(cred_exch_id=cred_exch_id).first() @@ -51,6 +43,7 @@ def post(self, topic): cred_exch_record.cred_exch_state=new_state cred_exch_record.save() current_app.logger.info(f"Updated cred_exch_record cred_exch_id={cred_exch_id} with state={new_state}") - + elif topic == PING: + current_app.logger.info(f"TrustPing received={request.get_json()}") else: current_app.logger.info(f"unknown topic '{topic}'")