Skip to content

Commit

Permalink
Fix upload signée preview
Browse files Browse the repository at this point in the history
  • Loading branch information
syldb committed Feb 7, 2025
1 parent a2658b4 commit 4e7f276
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
30 changes: 28 additions & 2 deletions conventions/tests/views/test_preview_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def logged_in_user(client, convention):
),
(
ConventionStatut.A_SIGNER.label,
"00000000-0000-0000-0000-000000000000.pdf",
b"Test PDF en instruction",
"test-signed-file.pdf",
b"Test PDF signes",
),
],
)
Expand Down Expand Up @@ -96,6 +96,32 @@ def test_display_pdf(
default_storage.delete(f"{convention_path}/00000000-0000-0000-000000000000.pdf")


@pytest.mark.django_db
def test_display_pdf_a_signer(client, convention, logged_in_user):
# Case where nom_fichier_signe is not defined
convention.statut = ConventionStatut.A_SIGNER.label
convention.save()

convention_path = "conventions/00000000-0000-0000-0000-000000000000/convention_docs"
default_storage.save(
f"{convention_path}/00000000-0000-0000-0000-000000000000.pdf",
io.BytesIO(b"Test PDF en instruction"),
)

url = reverse("conventions:display_pdf", args=[convention.uuid])
response = client.get(url)

assert response.status_code == 200
assert (
'inline; filename="00000000-0000-0000-0000-000000000000.pdf"'
in response["Content-Disposition"]
)
content = b"".join(response.streaming_content)
assert content == b"Test PDF en instruction"

default_storage.delete(f"{convention_path}/00000000-0000-0000-000000000000.pdf")


@pytest.mark.django_db
def test_display_pdf_fallback(client, convention, logged_in_user):
convention.uuid = UUID("00000000-0000-0000-0000-000000000001")
Expand Down
5 changes: 5 additions & 0 deletions conventions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@
views.ConventionPreviewUploadSignedView.as_view(),
name="preview_upload_signed",
),
path(
"upload_signed/cancel/<convention_uuid>",
views.ConventionCancelUploadSignedView.as_view(),
name="cancel_upload_signed",
),
path(
"upload_signed/date/<convention_uuid>",
views.ConventionDateUploadSignedView.as_view(),
Expand Down
10 changes: 10 additions & 0 deletions conventions/views/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ class ConventionPreviewUploadSignedView(ConventionBaseUploadSignedView):
template_path: str = "conventions/upload_signed/preview_document.html"


class ConventionCancelUploadSignedView(BaseConventionView):

@currentrole_campaign_permission_required("convention.view_convention")
def post(self, request, convention_uuid):
self.convention.nom_fichier_signe = None
self.convention.save()
return HttpResponseRedirect(reverse("conventions:sent", args=[convention_uuid]))


class ConventionDateUploadSignedView(ConventionBaseUploadSignedView):
step_number: int = 2
template_path: str = "conventions/upload_signed/signature_date.html"
Expand Down Expand Up @@ -678,6 +687,7 @@ def display_pdf(request, convention_uuid):
if (
convention.statut
in [
ConventionStatut.A_SIGNER.label,
ConventionStatut.SIGNEE.label,
ConventionStatut.RESILIEE.label,
ConventionStatut.DENONCEE.label,
Expand Down
9 changes: 6 additions & 3 deletions templates/conventions/upload_signed/preview_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ <h4>Assurez-vous d'avoir téléversé le bon document</h4>

<ul class="fr-mb-7w fr-btns-group fr-btns-group--inline-md fr-btns-group--right">
<li>
<a class="fr-btn fr-btn--secondary" href="{% url 'conventions:sent' convention_uuid=convention.uuid %}">
Annuler
</a>
<form action="{% url 'conventions:cancel_upload_signed' convention_uuid=convention.uuid %}" method="post">
{% csrf_token %}
<button type="submit" class="fr-btn fr-btn--secondary">
Annuler
</button>
</form>
</li>
<li>
<a class="fr-btn" href="{% url 'conventions:date_upload_signed' convention_uuid=convention.uuid %}">
Expand Down
4 changes: 2 additions & 2 deletions templates/conventions/upload_signed/signature_date.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ <h4>Indiquez la date de signature de la convention</h4>

<ul class="fr-my-7w fr-btns-group fr-btns-group--inline-md fr-btns-group--right">
<li>
<a class="fr-btn fr-btn--secondary" href="{% url 'conventions:sent' convention_uuid=convention.uuid %}">
<button type="submit" formaction="{% url 'conventions:cancel_upload_signed' convention_uuid=convention.uuid %}" class="fr-btn fr-btn--secondary">
Annuler
</a>
</button>
</li>
<li>
<button type="submit" class="fr-btn">
Expand Down

0 comments on commit 4e7f276

Please sign in to comment.