Skip to content
Snippets Groups Projects
Unverified Commit 60888cc5 authored by bryan's avatar bryan Committed by GitHub
Browse files

handle RecentViews for non-existant entites (#42643)

* handle recent view for non-existant entity

* test that recent views works with missing entities

- just doesn't return them.

* dont count on there being entities in the app-db
parent 52d32c15
No related branches found
No related tags found
No related merge requests found
......@@ -195,6 +195,10 @@
(cond
(false? (:archived model)) model
;; The model for this recent view doesn't exist in the database, so we can't check if it's archived, so just
;; filter it out.
(not model) nil
(true? (:archived model)) nil
(nil? (:archived model))
......@@ -260,12 +264,12 @@
;; if we don't have the :active key, we need to do a query for it:
(let [table (t2/select-one :model/Table model-id)]
(if (nil? table)
(throw (ex-info "Table not found" {:table-id model-id}))
[nil nil]
[table (:active table)]))))
(defmethod fill-recent-view-info :table [{:keys [_model model_id timestamp model_object]}]
(let [[table is-active?] (ellide-inactive model_object model_id)]
(when is-active?
(when (and table is-active?)
{:id model_id
:name (:name table)
:description (:description table)
......
......@@ -243,3 +243,29 @@
(is (= ids-to-prune
(vec (sort (map #(- % 1337000)
(#'recent-views/ids-to-prune (mt/user->id :rasta))))))))))))
(deftest recent-views-for-non-existent-entity-test
(testing "If a user views a model that doesn't exist, it should not be added to recent views"
(mt/with-temp [:model/Database a-db {}
:model/Table _ {:db_id (:id a-db)}
:model/Collection _ {}
:model/Dashboard _ {}
:model/Card {card-id :id} {:type "question"}]
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Card card-id)
(let [before-ghosts (recent-views/get-list (mt/user->id :rasta))
missing-card-id (inc (apply max (t2/select-pks-vec :model/Card)))
missing-dashboard-id (inc (apply max (t2/select-pks-vec :model/Dashboard)))
missing-collection-id (inc (apply max (t2/select-pks-vec :model/Collection)))
missing-table-id (inc (apply max (t2/select-pks-vec :model/Table)))]
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Card missing-card-id)
(is (= before-ghosts (recent-views/get-list (mt/user->id :rasta)))
"If a user views a model that doesn't exist, it should not be added to recent views")
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Dashboard missing-dashboard-id)
(is (= before-ghosts (recent-views/get-list (mt/user->id :rasta)))
"If a user views a model that doesn't exist, it should not be added to recent views")
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Collection missing-collection-id)
(is (= before-ghosts (recent-views/get-list (mt/user->id :rasta)))
"If a user views a model that doesn't exist, it should not be added to recent views")
(recent-views/update-users-recent-views! (mt/user->id :rasta) :model/Table missing-table-id)
(is (= before-ghosts (recent-views/get-list (mt/user->id :rasta)))
"If a user views a model that doesn't exist, it should not be added to recent views")))))
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