mirror of
https://github.com/logseq/logseq.git
synced 2026-05-02 18:06:32 +00:00
fix: batch delete tags breaks pages
Fixes https://test.logseq.com/#/page/6864f732-c4ac-4fea-8ef2-c40561e1bde6. Also fix protected property not notifying user
This commit is contained in:
committed by
Tienson Qin
parent
d0c54bb2b6
commit
04d39d8de8
32
deps/outliner/src/logseq/outliner/property.cljs
vendored
32
deps/outliner/src/logseq/outliner/property.cljs
vendored
@@ -45,12 +45,32 @@
|
|||||||
db-property/built-in-properties))
|
db-property/built-in-properties))
|
||||||
set))
|
set))
|
||||||
|
|
||||||
(defn- throw-error-if-protected-property
|
(defn- throw-error-if-deleting-protected-property
|
||||||
[entity-idents property-ident]
|
[entity-idents property-ident]
|
||||||
(when (some #(built-in-class-property->properties [% property-ident]) entity-idents)
|
(when (some #(built-in-class-property->properties [% property-ident]) entity-idents)
|
||||||
(throw (ex-info "Protected property shouldn't deleted"
|
(throw (ex-info "Property is protected and can't be deleted"
|
||||||
{:entity-idents entity-idents
|
{:type :notification
|
||||||
:property property-ident}))))
|
:payload {:type :error
|
||||||
|
:message "Property is protected and can't be deleted"
|
||||||
|
:entity-idents entity-idents
|
||||||
|
:property property-ident}}))))
|
||||||
|
|
||||||
|
(defn- throw-error-if-removing-private-tag
|
||||||
|
[entities]
|
||||||
|
(when-let [private-tags
|
||||||
|
(seq (set/intersection (set (mapcat #(map :db/ident (:block/tags %)) entities))
|
||||||
|
ldb/private-tags))]
|
||||||
|
(throw (ex-info "Can't remove private tags"
|
||||||
|
{:type :notification
|
||||||
|
:payload {:message (str "Can't remove private tags: " (string/join ", " private-tags))
|
||||||
|
:type :error}
|
||||||
|
:property-id :block/tags}))))
|
||||||
|
|
||||||
|
(defn- validate-batch-deletion-of-property
|
||||||
|
"Validates that the given property can be batch deleted from multiple nodes"
|
||||||
|
[entities property-ident]
|
||||||
|
(throw-error-if-deleting-protected-property (map :db/ident entities) property-ident)
|
||||||
|
(when (= :block/tags property-ident) (throw-error-if-removing-private-tag entities)))
|
||||||
|
|
||||||
(defn- build-property-value-tx-data
|
(defn- build-property-value-tx-data
|
||||||
[conn block property-id value]
|
[conn block property-id value]
|
||||||
@@ -304,7 +324,7 @@
|
|||||||
(let [block-eids (map ->eid block-ids)
|
(let [block-eids (map ->eid block-ids)
|
||||||
blocks (keep (fn [id] (d/entity @conn id)) block-eids)
|
blocks (keep (fn [id] (d/entity @conn id)) block-eids)
|
||||||
block-id-set (set (map :db/id blocks))]
|
block-id-set (set (map :db/id blocks))]
|
||||||
(throw-error-if-protected-property (map :db/ident blocks) property-id)
|
(validate-batch-deletion-of-property blocks property-id)
|
||||||
(when (seq blocks)
|
(when (seq blocks)
|
||||||
(when-let [property (d/entity @conn property-id)]
|
(when-let [property (d/entity @conn property-id)]
|
||||||
(let [txs (mapcat
|
(let [txs (mapcat
|
||||||
@@ -381,7 +401,7 @@
|
|||||||
(let [eid (->eid eid)
|
(let [eid (->eid eid)
|
||||||
block (d/entity @conn eid)
|
block (d/entity @conn eid)
|
||||||
property (d/entity @conn property-id)]
|
property (d/entity @conn property-id)]
|
||||||
(throw-error-if-protected-property [(:db/ident block)] property-id)
|
(validate-batch-deletion-of-property [block] property-id)
|
||||||
(when block
|
(when block
|
||||||
(cond
|
(cond
|
||||||
(= :logseq.property/empty-placeholder (:db/ident (get block property-id)))
|
(= :logseq.property/empty-placeholder (:db/ident (get block property-id)))
|
||||||
|
|||||||
@@ -231,7 +231,12 @@
|
|||||||
updated-blocks (map #(db-test/find-block-by-content @conn %) ["item 1" "item 2"])]
|
updated-blocks (map #(db-test/find-block-by-content @conn %) ["item 1" "item 2"])]
|
||||||
(is (= [nil nil]
|
(is (= [nil nil]
|
||||||
(map :logseq.property/order-list-type updated-blocks))
|
(map :logseq.property/order-list-type updated-blocks))
|
||||||
"Property values are batch removed")))
|
"Property values are batch removed")
|
||||||
|
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
js/Error
|
||||||
|
#"Can't remove private"
|
||||||
|
(outliner-property/batch-remove-property! conn [(:db/id (db-test/find-page-by-title @conn "page1"))] :block/tags)))))
|
||||||
|
|
||||||
(deftest add-existing-values-to-closed-values!
|
(deftest add-existing-values-to-closed-values!
|
||||||
(let [conn (db-test/create-conn-with-blocks
|
(let [conn (db-test/create-conn-with-blocks
|
||||||
|
|||||||
Reference in New Issue
Block a user