fix: user can right click delete private tags

resulting in invalid states. Also catch this at outliner level
This commit is contained in:
Gabriel Horner
2025-05-09 09:35:06 -04:00
parent 3d9cb9238c
commit ce4df797dd
3 changed files with 25 additions and 10 deletions

View File

@@ -437,6 +437,9 @@
(when-let [property (d/entity @conn property-id)]
(let [block (d/entity @conn block-eid)]
(when (and block (not= property-id (:db/ident block)) (db-property/many? property))
(when (= property-id :block/tags)
(outliner-validate/validate-tags-property-deletion @conn [block-eid] property-value))
(let [current-val (get block property-id)
fv (first current-val)]
(if (and (= 1 (count current-val)) (or (= property-value fv) (= property-value (:db/id fv))))

View File

@@ -183,30 +183,41 @@
:property-value v})))))
(defn- disallow-node-cant-tag-with-private-tags
[db block-eids v]
[db block-eids v & {:keys [delete?]}]
(when (and (ldb/private-tags (:db/ident (d/entity db v)))
;; Allow assets to be tagged
(not (and
(every? (fn [id] (ldb/asset? (d/entity db id))) block-eids)
(= :logseq.class/Asset (:db/ident (d/entity db v))))))
(throw (ex-info (str "Can't set tag with built-in #" (:block/title (d/entity db v)))
(throw (ex-info (str (if delete? "Can't remove tag" "Can't set tag")
" with built-in #" (:block/title (d/entity db v)))
{:type :notification
:payload {:message (str "Can't set tag with built-in #" (:block/title (d/entity db v)))
:payload {:message (str (if delete? "Can't remove tag" "Can't set tag")
" with built-in #" (:block/title (d/entity db v)))
:type :error}
:property-id :block/tags
:property-value v}))))
(defn- disallow-tagging-a-built-in-entity
[db block-eids]
[db block-eids & {:keys [delete?]}]
(when-let [built-in-ent (some #(when (:logseq.property/built-in? %) %)
(map #(d/entity db %) block-eids))]
(throw (ex-info (str "Can't add tag on built-in " (pr-str (:block/title built-in-ent)))
(throw (ex-info (str (if delete? "Can't remove tag" "Can't add tag")
" on built-in " (pr-str (:block/title built-in-ent)))
{:type :notification
:payload {:message (str "Can't add tag on built-in " (pr-str (:block/title built-in-ent)))
:payload {:message (str (if delete? "Can't remove tag" "Can't add tag")
" on built-in " (pr-str (:block/title built-in-ent)))
:type :error}}))))
(defn validate-tags-property
"Validates adding a property value to :block/tags for given blocks"
[db block-eids v]
(disallow-tagging-a-built-in-entity db block-eids)
(disallow-node-cant-tag-with-private-tags db block-eids v)
(disallow-node-cant-tag-with-built-in-non-tags db block-eids v))
(defn validate-tags-property-deletion
"Validates deleting a property value from :block/tags for given blocks"
[db block-eids v]
(disallow-tagging-a-built-in-entity db block-eids {:delete? true})
(disallow-node-cant-tag-with-private-tags db block-eids v {:delete? true}))

View File

@@ -2712,10 +2712,11 @@
:on-click #(state/sidebar-add-block! (state/get-current-repo) (:db/id tag) :page)}
"Open in sidebar"
(shui/dropdown-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))
(shui/dropdown-menu-item
{:key "Remove tag"
:on-click #(db-property-handler/delete-property-value! (:db/id block) :block/tags (:db/id tag))}
"Remove tag")])
(when-not (ldb/private-tags (:db/ident tag))
(shui/dropdown-menu-item
{:key "Remove tag"
:on-click #(db-property-handler/delete-property-value! (:db/id block) :block/tags (:db/id tag))}
"Remove tag"))])
popup-opts))}
(if (and @*hover? (not (ldb/private-tags (:db/ident tag))))
[:a.inline-flex.text-muted-foreground.mr-1