Skip to content

Commit

Permalink
Does not allow the download of a certificate for abandoned declaratio…
Browse files Browse the repository at this point in the history
…ns that used to be in observation
  • Loading branch information
alemangui committed Dec 19, 2024
1 parent 46982e4 commit 66b568e
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
29 changes: 25 additions & 4 deletions frontend/src/components/DeclarationAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script setup>
import { computed } from "vue"
import { isoToPrettyDate } from "@/utils/date"
const props = defineProps({ declaration: Object, role: { type: String, default: "declarant" } })
const props = defineProps({ declaration: Object, role: { type: String, default: "declarant" }, snapshots: Array })
const displayData = computed(() => {
switch (props.role) {
Expand All @@ -32,6 +32,12 @@ const displayData = computed(() => {
}
})
const canDownloadAbandonedCertificate = computed(() => {
if (!props.snapshots) return false
const latestSnapshot = [...props.snapshots].sort((a, b) => b.creationDate.localeCompare(a.creationDate))?.[0]
return latestSnapshot?.status === "OBJECTION"
})
const declarantDisplayData = computed(() => {
switch (props.declaration.status) {
case "DRAFT":
Expand Down Expand Up @@ -84,7 +90,12 @@ const declarantDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Attestation de déclaration", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: true }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -140,7 +151,12 @@ const instructorDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Cette déclaration a été autorisée", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: true }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -196,7 +212,12 @@ const visorDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Cette déclaration a été autorisée", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: true }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down
24 changes: 5 additions & 19 deletions frontend/src/components/HistoryTab.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<div v-if="isFetching" class="flex justify-center items-center min-h-60">
<div v-if="!snapshots" class="flex justify-center items-center min-h-60">
<ProgressSpinner />
</div>
<div v-if="snapshots && snapshots.length" class="flex flex-col gap-6">
Expand All @@ -19,20 +19,11 @@
</template>

<script setup>
import { useFetch } from "@vueuse/core"
import { onMounted, computed } from "vue"
import { handleError } from "@/utils/error-handling"
import { computed } from "vue"
import ProgressSpinner from "@/components/ProgressSpinner"
import SnapshotItem from "@/components/SnapshotItem"
const props = defineProps(["declarationId", "hideInstructionDetails"])
const { response, data, execute, isFetching } = useFetch(
() => `/api/v1/declarations/${props.declarationId}/snapshots/`,
{ immediate: false }
)
.get()
.json()
const props = defineProps(["snapshots", "declarationId", "hideInstructionDetails"])
const snapshots = computed(() => {
if (props.hideInstructionDetails) {
Expand All @@ -46,14 +37,9 @@ const snapshots = computed(() => {
"WITHDRAW",
"ABANDON",
]
return data.value?.filter((x) => allowedActions.indexOf(x.action) > -1)
return props.snapshots?.filter((x) => allowedActions.indexOf(x.action) > -1)
}
return data.value
})
onMounted(async () => {
await execute()
handleError(response)
return props.snapshots
})
const showOnRight = (snapshot) => {
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/views/InstructionPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
<p>Vous pouvez vous assigner cette déclaration pour instruction</p>
<DsfrButton class="mt-2" label="Instruire" tertiary @click="instructDeclaration" />
</DsfrAlert>
<DeclarationAlert class="mb-6" v-else-if="!canInstruct" role="instructor" :declaration="declaration" />
<DeclarationAlert
class="mb-6"
v-else-if="!canInstruct"
role="instructor"
:declaration="declaration"
:snapshots="snapshots"
/>
<div v-if="declaration">
<DeclarationSummary
:showArticle="true"
Expand Down Expand Up @@ -53,6 +59,7 @@
:declarationId="declaration?.id"
:user="declarant"
:company="company"
:snapshots="snapshots"
@decision-done="onDecisionDone"
:showArticle="true"
></component>
Expand Down Expand Up @@ -155,6 +162,14 @@ const {
.get()
.json()
const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.declarationId}/snapshots/`, { immediate: false })
.get()
.json()
// Sauvegarde du commentaire privé
const saveComment = useDebounceFn(async () => {
const { response } = await useFetch(() => `/api/v1/declarations/${declaration.value?.id}`, {
Expand All @@ -181,6 +196,8 @@ onMounted(async () => {
handleError(declarantResponse)
await executeCompanyFetch()
handleError(companyResponse)
await executeSnapshotsFetch()
handleError(snapshotsResponse)
isFetching.value = false
})
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/views/ProducerFormPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<div v-else class="mb-4">
<DeclarationAlert v-if="payload" role="declarant" :declaration="payload" class="mb-4" />
<DeclarationAlert v-if="payload" role="declarant" :declaration="payload" :snapshots="snapshots" class="mb-4" />

<DsfrAlert
class="mb-4"
Expand Down Expand Up @@ -61,6 +61,7 @@
:externalResults="$externalResults"
:readonly="readonly"
:declarationId="id"
:snapshots="snapshots"
@withdraw="onWithdrawal"
:hideInstructionDetails="true"
></component>
Expand Down Expand Up @@ -159,9 +160,19 @@ const { response, data, isFetching, execute } = useFetch(`/api/v1/declarations/$
.get()
.json()
const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.id}/snapshots/`, { immediate: false })
.get()
.json()
if (!isNewDeclaration.value || route.query.duplicate) execute()
if (!isNewDeclaration.value && !route.query.duplicate) executeSnapshotsFetch()
watch(response, () => handleError(response))
watch(snapshotsResponse, () => handleError(snapshotsResponse))
watch(data, () => {
const shouldDuplicate = route.query.duplicate && !props.id
if (shouldDuplicate) {
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/views/VisaPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<p>Vous pouvez vous assigner cette déclaration pour visa / signature</p>
<DsfrButton class="mt-2" label="Prendre pour validation" tertiary @click="takeDeclaration" />
</DsfrAlert>
<DeclarationAlert role="visor" class="mb-4" v-else :declaration="declaration" />
<DeclarationAlert role="visor" class="mb-4" v-else :declaration="declaration" :snapshots="snapshots" />
<div v-if="declaration">
<DeclarationSummary
:showArticle="true"
Expand Down Expand Up @@ -50,6 +50,7 @@
:showElementAuthorization="true"
:user="declarant"
:company="company"
:snapshots="snapshots"
@decision-done="onDecisionDone"
></component>
</DsfrTabContent>
Expand Down Expand Up @@ -150,6 +151,14 @@ const {
.get()
.json()
const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.declarationId}/snapshots/`, { immediate: false })
.get()
.json()
const privateNotesInstruction = ref(declaration.value?.privateNotesInstruction || "")
const privateNotesVisa = ref(declaration.value?.privateNotesVisa || "")
onMounted(async () => {
Expand All @@ -168,6 +177,8 @@ onMounted(async () => {
handleError(declarantResponse)
await executeCompanyFetch()
handleError(companyResponse)
await executeSnapshotsFetch()
handleError(snapshotsResponse)
isFetching.value = false
})
Expand Down
8 changes: 4 additions & 4 deletions web/views/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def get_template_path(self, declaration):
return f"certificates/certificate-submitted-art-{article}.html"

template_status = declaration.status

# La mise en abandon ne produit pas de Snapshot (car pas effectué en tant qu'action usager).
# On vérifie donc le status du dernier snapshot pour calculer le template
if template_status == status.ABANDONED:
pre_abandon_statuses = [status.OBJECTION, status.OBSERVATION]
template_status = (
declaration.snapshots.filter(status__in=pre_abandon_statuses).latest("creation_date").status
)
template_status = declaration.snapshots.latest("creation_date").status

if template_status in [status.AUTHORIZED, status.WITHDRAWN]:
return f"certificates/certificate-art-{article}.html"
Expand Down

0 comments on commit 66b568e

Please sign in to comment.