فهرست منبع

fix: disallow a page from adding a class via parent property

Tienson Qin 1 سال پیش
والد
کامیت
0dfb9fb8b5
2فایلهای تغییر یافته به همراه20 افزوده شده و 3 حذف شده
  1. 13 0
      deps/outliner/src/logseq/outliner/property.cljs
  2. 7 3
      src/main/frontend/components/property/value.cljs

+ 13 - 0
deps/outliner/src/logseq/outliner/property.cljs

@@ -25,6 +25,15 @@
     (throw (ex-info "Read-only property value shouldn't be edited"
                     {:property property-ident}))))
 
+(defn- throw-error-if-add-class-parent-to-page
+  [blocks entity]
+  (when (and (ldb/class? entity) (not (every? ldb/class? blocks)))
+    (throw (ex-info "Can't set a tag as a parent for non-tag page"
+                    {:type :notification
+                     :payload {:message "Can't set a tag as a parent for non-tag page"
+                               :type :warning}
+                     :blocks (remove ldb/class? blocks)}))))
+
 (defn- build-property-value-tx-data
   ([block property-id value]
    (build-property-value-tx-data block property-id value (= property-id :logseq.task/status)))
@@ -272,6 +281,10 @@
   (throw-error-if-read-only-property property-id)
   (let [block-eids (map ->eid block-ids)
         property (d/entity @conn property-id)
+        _ (when (= (:db/ident property) :logseq.property/parent)
+            (throw-error-if-add-class-parent-to-page
+             (map #(d/entity @conn %) block-eids)
+             (if (number? v) (d/entity @conn v) v)))
         _ (assert (some? property) (str "Property " property-id " doesn't exist yet"))
         property-type (get-in property [:block/schema :type] :default)
         _ (assert (some? v) "Can't set a nil property value must be not nil")

+ 7 - 3
src/main/frontend/components/property/value.cljs

@@ -463,9 +463,13 @@
            (let [;; Disallows cyclic hierarchies
                  exclude-ids (-> (set (map (fn [id] (:block/uuid (db/entity id))) children-pages))
                                  (conj (:block/uuid block))) ; break cycle
-                 options (if (ldb/class? block) (model/get-all-classes repo)
-                             (->> (model/get-all-pages repo)
-                                  (remove (fn [e] (or (ldb/built-in? e) (ldb/property? e))))))
+                 options (if (ldb/class? block)
+                           (model/get-all-classes repo)
+                           (cond->>
+                            (->> (model/get-all-pages repo)
+                                 (remove (fn [e] (or (ldb/built-in? e) (ldb/property? e)))))
+                             (contains? #{"property" "page"} (:block/type block))
+                             (remove ldb/class?)))
                  excluded-options (remove (fn [e] (contains? exclude-ids (:block/uuid e))) options)]
              excluded-options)