From 1ad3855aef0c753ff2d1878fed5b550327a16df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 31 Oct 2023 11:22:02 +0100 Subject: [PATCH] :wrench: Validate frame-id is valid ancestor --- common/src/app/common/files/validate.cljc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index b86c8b80c..eec7ac026 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -125,17 +125,29 @@ :child-id child-id))))))) (defn validate-frame - "Validate that the frame-id shape exists and is indeed a frame." + "Validate that the frame-id shape exists and is indeed a frame. Also it must point to the + parent shape (if this is a frame) or to the frame-id of the parent (if not)." [shape file page] (let [frame (ctst/get-shape page (:frame-id shape))] (if (nil? frame) (report-error :frame-not-found (str/format "Frame %s not found" (:frame-id shape)) shape file page) - (when (not= (:type frame) :frame) + (if (not= (:type frame) :frame) (report-error :invalid-frame (str/format "Frame %s is not actually a frame" (:frame-id shape)) - shape file page))))) + shape file page) + (let [parent (ctst/get-shape page (:parent-id shape))] + (when (some? parent) + (if (= (:type parent) :frame) + (when-not (= (:frame-id shape) (:id parent)) + (report-error :invalid-frame + (str/format "Frame-id should point to parent" (:id parent)) + shape file page)) + (when-not (= (:frame-id shape) (:frame-id parent)) + (report-error :invalid-frame + (str/format "Frame-id should point to parent frame" (:frame-id parent)) + shape file page))))))))) (defn validate-component-main-head "Validate shape is a main instance head, component exists and its main-instance points to this shape."