From ddb2a654193e0d7ad0dd0c9e86c838bbee6f848a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 13 Oct 2025 14:12:06 +0000 Subject: [PATCH] Take permissions into account for deletion of WorkflowAttachment (+ type safety) --- .../unreleased/Fixed-20251013-160526.yaml | 6 +++ .../Resources/public/types/generic_doc.ts | 17 ++++++++ .../ChillMainBundle/Resources/public/types.ts | 24 ++++++++++- .../public/vuejs/WorkflowAttachment/App.vue | 3 +- .../Component/AttachmentList.vue | 43 +++++++++++++------ .../Component/GenericDocItemBox.vue | 4 +- .../translations/messages.fr.yml | 2 + 7 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 .changes/unreleased/Fixed-20251013-160526.yaml diff --git a/.changes/unreleased/Fixed-20251013-160526.yaml b/.changes/unreleased/Fixed-20251013-160526.yaml new file mode 100644 index 000000000..86419d005 --- /dev/null +++ b/.changes/unreleased/Fixed-20251013-160526.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: '[workflow] take permissions into account to delete the workflow attachment' +time: 2025-10-13T16:05:26.088124301+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/types/generic_doc.ts b/src/Bundle/ChillDocStoreBundle/Resources/public/types/generic_doc.ts index 497cfee5a..04c324b4a 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/types/generic_doc.ts +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/types/generic_doc.ts @@ -36,6 +36,18 @@ export interface GenericDocForAccompanyingPeriod extends GenericDoc { context: "accompanying-period"; } +export function isGenericDocForAccompanyingPeriod( + doc: GenericDoc, +): doc is GenericDocForAccompanyingPeriod { + return doc.context === "accompanying-period"; +} + +export function isGenericDocWithStoredObject( + doc: GenericDoc, +): doc is GenericDoc & { storedObject: StoredObject } { + return doc.storedObject !== null; +} + interface BaseMetadataWithHtml extends BaseMetadata { html: string; } @@ -44,28 +56,33 @@ export interface GenericDocForAccompanyingCourseDocument extends GenericDocForAccompanyingPeriod { key: "accompanying_course_document"; metadata: BaseMetadataWithHtml; + storedObject: StoredObject; } export interface GenericDocForAccompanyingCourseActivityDocument extends GenericDocForAccompanyingPeriod { key: "accompanying_course_activity_document"; metadata: BaseMetadataWithHtml; + storedObject: StoredObject; } export interface GenericDocForAccompanyingCourseCalendarDocument extends GenericDocForAccompanyingPeriod { key: "accompanying_course_calendar_document"; metadata: BaseMetadataWithHtml; + storedObject: StoredObject; } export interface GenericDocForAccompanyingCoursePersonDocument extends GenericDocForAccompanyingPeriod { key: "person_document"; metadata: BaseMetadataWithHtml; + storedObject: StoredObject; } export interface GenericDocForAccompanyingCourseWorkEvaluationDocument extends GenericDocForAccompanyingPeriod { key: "accompanying_period_work_evaluation_document"; metadata: BaseMetadataWithHtml; + storedObject: StoredObject; } diff --git a/src/Bundle/ChillMainBundle/Resources/public/types.ts b/src/Bundle/ChillMainBundle/Resources/public/types.ts index b96462ceb..c39db4a76 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/types.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/types.ts @@ -1,4 +1,7 @@ -import { GenericDoc } from "ChillDocStoreAssets/types/generic_doc"; +import { + GenericDoc, + isGenericDocWithStoredObject, +} from "ChillDocStoreAssets/types/generic_doc"; import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types"; import { Person } from "../../../ChillPersonBundle/Resources/public/types"; @@ -203,6 +206,25 @@ export interface WorkflowAttachment { genericDoc: null | GenericDoc; } +export type AttachmentWithDocAndStored = WorkflowAttachment & { + genericDoc: GenericDoc & { storedObject: StoredObject }; +}; + +export function isAttachmentWithDocAndStored( + a: WorkflowAttachment, +): a is AttachmentWithDocAndStored { + return ( + isWorkflowAttachmentWithGenericDoc(a) && + isGenericDocWithStoredObject(a.genericDoc) + ); +} + +export function isWorkflowAttachmentWithGenericDoc( + attachment: WorkflowAttachment, +): attachment is WorkflowAttachment & { genericDoc: GenericDoc } { + return attachment.genericDoc !== null; +} + export interface Workflow { name: string; text: string; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/App.vue index 289b49788..af319580d 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/App.vue @@ -6,6 +6,7 @@ import { GenericDocForAccompanyingPeriod } from "ChillDocStoreAssets/types/gener import AttachmentList from "ChillMainAssets/vuejs/WorkflowAttachment/Component/AttachmentList.vue"; import { GenericDoc } from "ChillDocStoreAssets/types"; import { fetchWorkflow } from "ChillMainAssets/lib/workflow/api"; +import { trans, WORKFLOW_ATTACHMENTS_ADD_AN_ATTACHMENT } from "translator"; interface AppConfig { workflowId: number; @@ -83,7 +84,7 @@ const canEditAttachement = computed(() => { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/Component/AttachmentList.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/Component/AttachmentList.vue index c0d3a8eb4..d12496266 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/Component/AttachmentList.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/WorkflowAttachment/Component/AttachmentList.vue @@ -1,7 +1,14 @@