Explorar el Código

fix: properties should not be parents of pages or classes

when created through page creation. Similar to parent property
validation, user could create weird and meaningless combos of
property/journal parents to a page/class child. Also made a new test for
basic page creation
Gabriel Horner hace 1 año
padre
commit
adb74f9521

+ 9 - 2
src/main/frontend/worker/handler/page/db_based/page.cljs

@@ -106,17 +106,24 @@
                                         (when last-part? (ldb/get-page db part))
                                         (when last-part? (ldb/get-page db part))
                                         (-> (gp-block/page-name->map part db true date-formatter
                                         (-> (gp-block/page-name->map part db true date-formatter
                                                                      {:page-uuid (when last-part? block-uuid)
                                                                      {:page-uuid (when last-part? block-uuid)
-                                                                      :skip-existing-page-check? true})
+                                                                      :skip-existing-page-check? true
+                                                                      :class? class?})
                                             (assoc :block/format :markdown)))]
                                             (assoc :block/format :markdown)))]
                          result))
                          result))
                      parts))]
                      parts))]
          (cond
          (cond
-           (and (not class?) (ldb/class? (first pages)))
+           (and (not class?) (not (every? ldb/internal-page? pages)))
            (throw (ex-info "Cannot create this page unless all parents are pages"
            (throw (ex-info "Cannot create this page unless all parents are pages"
                            {:type :notification
                            {:type :notification
                             :payload {:message "Cannot create this page unless all parents are pages"
                             :payload {:message "Cannot create this page unless all parents are pages"
                                       :type :warning}}))
                                       :type :warning}}))
 
 
+           (and class? (not (every? ldb/class? pages)))
+           (throw (ex-info "Cannot create this tag unless all parents are tags"
+                           {:type :notification
+                            :payload {:message "Cannot create this tag unless all parents are tags"
+                                      :type :warning}}))
+
            :else
            :else
            (map-indexed
            (map-indexed
             (fn [idx page]
             (fn [idx page]

+ 28 - 5
src/test/frontend/worker/handler/page/db_based/page_test.cljs

@@ -22,7 +22,8 @@
 
 
 (deftest create-namespace-pages
 (deftest create-namespace-pages
   (let [conn (db-test/create-conn-with-blocks
   (let [conn (db-test/create-conn-with-blocks
-              {:classes {:class1 {}}
+              {:properties {:property1 {:block/schema {:type :default}}}
+               :classes {:class1 {}}
                :pages-and-blocks [{:page {:block/title "page1"}}]})]
                :pages-and-blocks [{:page {:block/title "page1"}}]})]
 
 
     (testing "Valid workflows"
     (testing "Valid workflows"
@@ -30,12 +31,17 @@
             child-page (d/entity @conn [:block/uuid child-uuid])
             child-page (d/entity @conn [:block/uuid child-uuid])
             ;; Create a 2nd child page using existing parent pages
             ;; Create a 2nd child page using existing parent pages
             [_ child-uuid2] (worker-db-page/create! conn "foo/bar/baz2" {:split-namespace? true})
             [_ child-uuid2] (worker-db-page/create! conn "foo/bar/baz2" {:split-namespace? true})
-            child-page2 (d/entity @conn [:block/uuid child-uuid2])]
+            child-page2 (d/entity @conn [:block/uuid child-uuid2])
+            ;; Create a child page for a class
+            [_ child-uuid3] (worker-db-page/create! conn "c1/c2" {:split-namespace? true :class? true})
+            child-page3 (d/entity @conn [:block/uuid child-uuid3])]
         (is (= ["foo" "bar"] (map :block/title (ldb/get-page-parents child-page)))
         (is (= ["foo" "bar"] (map :block/title (ldb/get-page-parents child-page)))
             "Child page with new parent has correct parents")
             "Child page with new parent has correct parents")
         (is (= (map :block/uuid (ldb/get-page-parents child-page))
         (is (= (map :block/uuid (ldb/get-page-parents child-page))
                (map :block/uuid (ldb/get-page-parents child-page2)))
                (map :block/uuid (ldb/get-page-parents child-page2)))
             "Child page with existing parents has correct parents")
             "Child page with existing parents has correct parents")
+        (is (= ["Root Tag" "c1"] (map :block/title (ldb/get-classes-parents [child-page3])))
+            "Child class with new parent has correct parents")
 
 
         (worker-db-page/create! conn "foo/class1/baz3" {:split-namespace? true})
         (worker-db-page/create! conn "foo/class1/baz3" {:split-namespace? true})
         (is (= #{"class" "page"}
         (is (= #{"class" "page"}
@@ -51,6 +57,23 @@
           "Page can't have a class parent")
           "Page can't have a class parent")
       (is (thrown-with-msg?
       (is (thrown-with-msg?
            js/Error
            js/Error
-           #"can't include \"/"
-           (worker-db-page/create! conn "foo/bar" {}))
-          "Page can't have a class parent"))))
+           #"Cannot create"
+           (worker-db-page/create! conn "property1/page" {:split-namespace? true}))
+          "Page can't have a property parent")
+      (is (thrown-with-msg?
+           js/Error
+           #"Cannot create"
+           (worker-db-page/create! conn "property1/class" {:split-namespace? true :class? true}))
+          "Class can't have a property parent"))))
+
+(deftest create-page
+  (let [conn (db-test/create-conn)
+        [_ page-uuid] (worker-db-page/create! conn "fooz" {})]
+    (is (= "fooz" (:block/title (d/entity @conn [:block/uuid page-uuid])))
+        "Valid page created")
+
+    (is (thrown-with-msg?
+         js/Error
+         #"can't include \"/"
+         (worker-db-page/create! conn "foo/bar" {}))
+        "Page can't have '/'n title")))