Skip to content
Snippets Groups Projects
Unverified Commit dd1e0bed authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Add the :archived status of card/dashboard/collection for filtering (#20921)

* Add the :archived status of card/dashboard/collection for filtering

If an item is bookmarked, we can follow the link to that item without issue. But, if we bookmark an item and then
archive that item, the bookmark shouldn't show up, as we don't want to link to an archived item.

The bookmark itself is not removed, it's just filtered away when :archived is true.

* Added test for bookmarked and archived items

The archived items that are still bookmarked should not be sent to the Frontend.
parent 8ad9254d
No related branches found
No related tags found
No related merge requests found
......@@ -70,16 +70,20 @@
[:card.id (db/qualify 'Card :item_id)]
[:card.name (db/qualify 'Card :name)]
[:card.description (db/qualify 'Card :description)]
[:card.archived (db/qualify 'Card :archived)]
[:dashboard.id (db/qualify 'Dashboard :item_id)]
[:dashboard.name (db/qualify 'Dashboard :name)]
[:dashboard.description (db/qualify 'Dashboard :description)]
[:dashboard.archived (db/qualify 'Dashboard :archived)]
[:collection.id (db/qualify 'Collection :item_id)]
[:collection.name (db/qualify 'Collection :name)]
[:collection.description (db/qualify 'Collection :description)]]
[:collection.description (db/qualify 'Collection :description)]
[:collection.archived (db/qualify 'Collection :archived)]]
:from [[(bookmarks-union-query id) :bookmark]]
:left-join [[:report_card :card] [:= :bookmark.card_id :card.id]
[:report_dashboard :dashboard] [:= :bookmark.dashboard_id :dashboard.id]
:collection [:= :bookmark.collection_id :collection.id]]})
(map remove-nil-values)
(sort-by :created_at)
(map normalize-bookmark-result)))
(map normalize-bookmark-result)
(remove :archived)))
(ns metabase.api.bookmark-test
"Tests for /api/bookmark endpoints."
(:require [clojure.test :refer :all]
[metabase.models.bookmark :refer [CardBookmark CollectionBookmark DashboardBookmark]]
[metabase.models.card :refer [Card]]
[metabase.models.collection :refer [Collection]]
[metabase.models.dashboard :refer [Dashboard]]
......@@ -11,7 +12,7 @@
(testing "POST /api/bookmark/:model/:model-id"
(mt/with-temp* [Collection [collection {:name "Test Collection"}]
Card [card {:name "Test Card"}]
Dashboard [dashboard {:name "Test Dashboard"}]]
Dashboard [dashboard {:name "Test Dashboard"}]]
(testing "check that we can bookmark a Collection"
(is (= (u/the-id collection)
(->> (mt/user-http-request :rasta :post 200 (str "bookmark/collection/" (u/the-id collection)))
......@@ -41,3 +42,20 @@
(->> (mt/user-http-request :rasta :get 200 "bookmark")
(map :type)
set)))))))
(deftest bookmarks-on-archived-items-test
(testing "POST /api/bookmark/:model/:model-id"
(mt/with-temp* [Collection [archived-collection {:name "Test Collection" :archived true}]
Card [archived-card {:name "Test Card" :archived true}]
Dashboard [archived-dashboard {:name "Test Dashboard" :archived true}]
CardBookmark [card-bookmark {:user_id (mt/user->id :rasta)
:card_id (u/the-id archived-card)}]
CollectionBookmark [collection-bookmark {:user_id (mt/user->id :rasta)
:collection_id (u/the-id archived-collection)}]
DashboardBookmark [dashboard-bookmark {:user_id (mt/user->id :rasta)
:dashboard_id (u/the-id archived-dashboard)}]]
(testing "check that we don't receive bookmarks of archived items"
(is (= #{}
(->> (mt/user-http-request :rasta :get 200 "bookmark")
(map :type)
set)))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment