Skip to content

Commit

Permalink
[FIX] - Only update state on connection webhooks, sort does not return (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsyro authored Oct 27, 2023
1 parent 821308a commit d7aa417
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
13 changes: 8 additions & 5 deletions services/core-api/app/api/parties/party/models/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PartyVerifiableCredentialConnection(AuditMixin, Base):


def __repr__(self):
return '<PartyVerifiableCredentialConnection party_guid=%r, connection_state=%r>' % (self.party_guid, self.connection_state or "UNKNOWN")
return '<PartyVerifiableCredentialConnection party_guid=%r, connection_state=%r>' % (self.party_guid, self.connection_state)

@classmethod
def find_by_party_guid(cls, party_guid) -> "PartyVerifiableCredentialConnection":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand All @@ -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()
Expand All @@ -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}'")

0 comments on commit d7aa417

Please sign in to comment.