Skip to content

Commit

Permalink
🚧(backend) student_signed_on with signature provider on serializer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanreveille committed Sep 20, 2024
1 parent 35f1361 commit c4dd411
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/backend/joanie/core/serializers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 get_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"""
Expand Down

0 comments on commit c4dd411

Please sign in to comment.