|
34 | 34 | )
|
35 | 35 | from . import (
|
36 | 36 | CredentialAttributeSpec, CredentialManager, CredentialManagerError,
|
37 |
| - CredentialProposalRequestSchema, CredExRecord, CredExRecordSchema, |
| 37 | + CredentialProposalRequestSchema, CredExRecord, CredExRecordSchema, CredentialProblemReport, |
38 | 38 | IndyCredPrecisSchema, PresentationPreview,
|
39 | 39 | PresentationProposalRequestSchema, PresExRecord, PresExRecordSchema,
|
40 | 40 | issue_credential, present_proof, PresentationManager,
|
@@ -317,6 +317,68 @@ class CredRequestSent(AdminHolderMessage):
|
317 | 317 | fields_from = CredExRecordSchema
|
318 | 318 |
|
319 | 319 |
|
| 320 | +@expand_message_class |
| 321 | +class CredOfferReject(AdminHolderMessage): |
| 322 | + """Credential offer reject message.""" |
| 323 | + message_type = "credential-offer-reject" |
| 324 | + |
| 325 | + class Fields: |
| 326 | + credential_exchange_id = fields.Str( |
| 327 | + required=True, |
| 328 | + description="ID of the credential exchange to reject.", |
| 329 | + example=UUIDFour.EXAMPLE |
| 330 | + ) |
| 331 | + |
| 332 | + def __init__(self, credential_exchange_id: str, **kwargs): |
| 333 | + super().__init__(**kwargs) |
| 334 | + self.credential_exchange_id = credential_exchange_id |
| 335 | + |
| 336 | + @log_handling |
| 337 | + @admin_only |
| 338 | + async def handle(self, context: RequestContext, responder: BaseResponder): |
| 339 | + """Handle credential offer reject message.""" |
| 340 | + async with context.session() as session: |
| 341 | + async with ExceptionReporter( |
| 342 | + responder, |
| 343 | + (StorageError, CredentialManagerError, BaseModelError), |
| 344 | + self |
| 345 | + ): |
| 346 | + cred_ex_record = await CredExRecord.retrieve_by_id( |
| 347 | + session, self.credential_exchange_id |
| 348 | + ) |
| 349 | + cred_ex_record = cast(CredExRecord, cred_ex_record) |
| 350 | + connection_id = cred_ex_record.connection_id |
| 351 | + connection_record = await get_connection(session, connection_id) |
| 352 | + |
| 353 | + # TODO add credential_manager.reject(..) to ACA-Py |
| 354 | + |
| 355 | + cred_ex_record.state = "reject-sent" # TODO add CredExRecord.STATE_REJECT_SENT to ACA-Py |
| 356 | + async with context.session() as session: |
| 357 | + await cred_ex_record.save(session, reason="Rejected credential offer.") |
| 358 | + |
| 359 | + problem_report = CredentialProblemReport( |
| 360 | + description={ |
| 361 | + "en": "Rejected credential offer.", |
| 362 | + "code": "rejected", # TODO add ProblemReportReason.REJECTED to ACA-Py |
| 363 | + } |
| 364 | + ) |
| 365 | + problem_report.assign_thread_id(cred_ex_record.thread_id) |
| 366 | + |
| 367 | + sent = CredOfferRejectSent(**cred_ex_record.serialize()) |
| 368 | + sent.assign_thread_from(self) |
| 369 | + |
| 370 | + await responder.send(problem_report, connection_id=connection_record.connection_id) |
| 371 | + await responder.send_reply(sent) |
| 372 | + |
| 373 | + |
| 374 | +@with_generic_init |
| 375 | +@expand_message_class |
| 376 | +class CredOfferRejectSent(AdminHolderMessage): |
| 377 | + """Credential offer reject sent.""" |
| 378 | + message_type = "credential-offer-reject-sent" |
| 379 | + fields_from = CredExRecordSchema |
| 380 | + |
| 381 | + |
320 | 382 | @with_generic_init
|
321 | 383 | @expand_message_class
|
322 | 384 | class CredReceived(AdminHolderMessage):
|
@@ -881,6 +943,7 @@ def __init__(
|
881 | 943 | CredGetList,
|
882 | 944 | CredList,
|
883 | 945 | CredOfferAccept,
|
| 946 | + CredOfferReject, |
884 | 947 | CredOfferRecv,
|
885 | 948 | CredRequestSent,
|
886 | 949 | CredReceived,
|
|
0 commit comments