From ab21d9e2fefa7e247e1c9111f60ff6d38020eeed Mon Sep 17 00:00:00 2001 From: Jonathan Reveille Date: Fri, 20 Sep 2024 16:44:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7(backend)=20student=5Fsigned=5Fon?= =?UTF-8?q?=20with=20signature=20provider=20on=20serializer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the serializer client ContractLightSerializer, whether the notification from the signature provider takes some time to let us know that the student has signed, when the viewset is called, it will trigger our serializer method that will check if the student has finished signing his part on the document. That allows the frontend to get the latest information when the student gets to his dashboard of course orders. --- src/backend/joanie/core/serializers/client.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/joanie/core/serializers/client.py b/src/backend/joanie/core/serializers/client.py index cead4a6978..f8c860ac5f 100644 --- a/src/backend/joanie/core/serializers/client.py +++ b/src/backend/joanie/core/serializers/client.py @@ -17,6 +17,7 @@ from joanie.core.serializers.base import CachedModelSerializer from joanie.core.serializers.fields import ISO8601DurationField, ThumbnailDetailField from joanie.payment.models import CreditCard +from joanie.signature.backends import get_signature_backend class AbilitiesModelSerializer(serializers.ModelSerializer): @@ -446,11 +447,30 @@ class Meta: class ContractLightSerializer(serializers.ModelSerializer): """Light serializer for Contract model.""" + student_signed_on = serializers.SerializerMethodField() + class Meta: model = models.Contract fields = ["id", "organization_signed_on", "student_signed_on"] read_only_fields = fields + def student_signed_on(self, contract): + """ + Returns if the student has signed the document. + """ + if ( + contract.submitted_for_signature_on + and not contract.student_signed_on + and not contract.organization_signed_on + ): + signature_backend = get_signature_backend() + signature_state = signature_backend.get_signature_state( + reference_id=contract.signature_backend_reference + ) + return signature_state.get("student") + + return contract.student_signed_on + class ContractSerializer(AbilitiesModelSerializer): """Serializer for Contract model serializer"""