fix: validate unique page by tags

only applies to type page. Otherwise their would be bugs
with properties and classes having duplicate names.
Also add test for f939b0eff1
pull/11525/head
Gabriel Horner 2024-09-11 14:33:23 -04:00
parent 6dbc0ce4fc
commit 4cd886cf1e
2 changed files with 12 additions and 4 deletions

View File

@ -15,7 +15,7 @@
(defn- validate-unique-for-page (defn- validate-unique-for-page
[db new-title {:block/keys [tags] :as entity}] [db new-title {:block/keys [tags] :as entity}]
(cond (cond
(seq tags) (and (seq tags) (= "page" (:block/type entity)))
(when-let [res (seq (d/q '[:find [?b ...] (when-let [res (seq (d/q '[:find [?b ...]
:in $ ?eid ?title [?tag-id ...] :in $ ?eid ?title [?tag-id ...]
:where :where
@ -67,8 +67,9 @@
(defn ^:api validate-unique-by-name-tag-and-block-type (defn ^:api validate-unique-by-name-tag-and-block-type
"Validates uniqueness of blocks and pages for the following cases: "Validates uniqueness of blocks and pages for the following cases:
- Page names are unique by tag e.g. their can be Apple #Company and Apple #Fruit - Page names of type 'page' are unique by tag e.g. their can be Apple #Company and Apple #Fruit
- Page names are unique by type e.g. their can be #Journal and Journal (normal page) - Page names of other types are unique for their type e.g. their can be #Journal ('class') and Journal ('page')
- Property names are unique and don't consider built-in property names
- Block names are unique by tag" - Block names are unique by tag"
[db new-title {:block/keys [tags] :as entity}] [db new-title {:block/keys [tags] :as entity}]
(cond (cond

View File

@ -98,4 +98,11 @@
@conn @conn
"page1" "page1"
(assoc (find-block-by-content conn "page1") :db/id 10000))) (assoc (find-block-by-content conn "page1") :db/id 10000)))
"Disallow duplicate page without tag"))) "Disallow duplicate page without tag")
(is (nil?
(outliner-validate/validate-unique-by-name-tag-and-block-type
@conn
"Apple"
(find-block-by-content conn "Fruit")))
"Allow class to have same name as a page")))