From a85e7d4b2a66fe3dec95e1d5bc6ce0b72a6ad447 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 2 Aug 2023 14:53:22 -0400 Subject: [PATCH] fix: User shouldn't be able to alter built in properties Allowing this causes all kinds of bugs. Also trivial type fix for last commit --- src/main/frontend/components/property.cljs | 18 ++++++++++++------ .../frontend/handler/db_based/property.cljs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 12fbe56a71..5e093c618d 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -34,7 +34,8 @@ state))} [state repo property ] (let [*property-name (::property-name state) - *property-schema (::property-schema state)] + *property-schema (::property-schema state) + disabled? (contains? gp-property/db-built-in-properties-keys-str (:block/original-name property))] [:div.property-configure [:h1.title "Configure property"] @@ -43,6 +44,7 @@ [:label "Name:"] [:input.form-input {:on-change #(reset! *property-name (util/evalue %)) + :disabled disabled? :value @*property-name}]] [:div.grid.grid-cols-4.gap-1.leading-8 @@ -52,19 +54,21 @@ (map (comp string/capitalize name)) (map (fn [type] {:label type + :disabled disabled? :value type :selected (= (keyword (string/lower-case type)) (:type @*property-schema))})))] (ui/select schema-types - (fn [_e v] - (let [type (keyword (string/lower-case v))] - (swap! *property-schema assoc :type type)))))] + (fn [_e v] + (let [type (keyword (string/lower-case v))] + (swap! *property-schema assoc :type type)))))] (when-not (= (:type @*property-schema) :checkbox) [:div.grid.grid-cols-4.gap-1.items-center.leading-8 [:label "Multiple values:"] (let [many? (boolean (= :many (:cardinality @*property-schema)))] (ui/checkbox {:checked many? + :disabled disabled? :on-change (fn [] (swap! *property-schema assoc :cardinality (if many? :one :many)))}))]) @@ -74,17 +78,19 @@ (ui/ls-textarea {:on-change (fn [e] (swap! *property-schema assoc :description (util/evalue e))) + :disabled disabled? :value (:description @*property-schema)})]] [:div - (ui/button + (when-not disabled? + (ui/button "Save" :on-click (fn [] (property-handler/update-property! repo (:block/uuid property) {:property-name @*property-name :property-schema @*property-schema}) - (state/close-modal!)))] + (state/close-modal!))))] (when config/dev? [:div {:style {:max-width 900}} diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index e301051179..bd294b200e 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -64,7 +64,7 @@ :coll coll? :any some?}) -(def internal-builtin-schema-types #{:map :coll :any}) +(def internal-builtin-schema-types #{:keyword :map :coll :any}) ;; schema -> type, cardinality, object's class ;; min, max -> string length, number range, cardinality size limit