Skip to content
Snippets Groups Projects
Unverified Commit 7cfaddde authored by metamben's avatar metamben Committed by GitHub
Browse files

Hydrate app_id for dashboard activities (#25270)

Hydrate app_id for dashboard activities

Part of #25254.

Only the /recent_views and /popular_items endpoints have been extended.
The / endpoint currently doesn't deliver additional information like
the other endpoints do. (The other endpoints deliver at most 5 items,
but the / endpoint doesn't limit the number of results.)
parent 8cd55867
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
[medley.core :as m]
[metabase.api.common :refer [*current-user-id* defendpoint define-routes]]
[metabase.models.activity :refer [Activity]]
[metabase.models.app :refer [App]]
[metabase.models.bookmark :refer [CardBookmark DashboardBookmark]]
[metabase.models.card :refer [Card]]
[metabase.models.collection :refer [Collection]]
......@@ -113,14 +114,18 @@
"dashboard" [Dashboard
:id :name :collection_id :description
:archived :is_app_page
[(db/qualify App :id) :app_id]
(db/qualify Collection :authority_level)]
"table" [Table
:id :name :db_id
:display_name :initial_sync_status
:visibility_type])
(cond-> {:where [:in (db/qualify (symbol (str/capitalize model)) :id) ids]}
(not= model "table")
(merge {:left-join [Collection [:= (db/qualify Collection :id) :collection_id]]}))))
(let [model-symb (symbol (str/capitalize model))
self-qualify #(db/qualify model-symb %)]
(cond-> {:where [:in (self-qualify :id) ids]}
(not= model "table")
(merge {:left-join [Collection [:= (db/qualify Collection :id) (self-qualify :collection_id)]
App [:= (db/qualify App :collection_id) (db/qualify Collection :id)]]})))))
(defn- select-items! [model ids]
(when (seq ids)
......
......@@ -4,7 +4,9 @@
[java-time :as t]
[metabase.api.activity :as api.activity]
[metabase.models.activity :refer [Activity]]
[metabase.models.app :refer [App]]
[metabase.models.card :refer [Card]]
[metabase.models.collection :refer [Collection]]
[metabase.models.dashboard :refer [Dashboard]]
[metabase.models.interface :as mi]
[metabase.models.query-execution :refer [QueryExecution]]
......@@ -133,10 +135,13 @@
:display "table"
:archived true
:visualization_settings {}}]
Collection [{coll-id :id} {}]
App [{app-id :id} {:collection_id coll-id}]
Dashboard [page {:name "rand-name"
:description "rand-name"
:creator_id (mt/user->id :crowberto)
:is_app_page true}]
:is_app_page true
:collection_id coll-id}]
Dashboard [dash {:name "rand-name2"
:description "rand-name2"
:creator_id (mt/user->id :crowberto)}]
......@@ -163,7 +168,8 @@
(is (partial= [{:model "table" :model_id (:id table1)}
{:model "dashboard" :model_id (:id dash) :model_object {:is_app_page false}}
{:model "card" :model_id (:id card1)}
{:model "page" :model_id (:id page) :model_object {:is_app_page true}}
{:model "page" :model_id (:id page) :model_object {:is_app_page true
:app_id app-id}}
{:model "dataset" :model_id (:id dataset)}]
recent-views))))))
......@@ -180,10 +186,13 @@
Dashboard [dash1 {:name "rand-name"
:description "rand-name"
:creator_id (mt/user->id :crowberto)}]
Collection [{coll-id :id} {}]
App [{app-id :id} {:collection_id coll-id}]
Dashboard [dash2 {:name "other-dashboard"
:description "just another dashboard"
:creator_id (mt/user->id :crowberto)
:is_app_page true}]
:is_app_page true
:collection_id coll-id}]
Table [table1 {:name "rand-name"}]
Table [_hidden-table {:name "hidden table"
:visibility_type "hidden"}]
......@@ -225,14 +234,14 @@
[(mt/user->id :rasta) "card" (:id dataset)]
[(mt/user->id :rasta) "table" (:id table1)]
[(mt/user->id :rasta) "card" (:id card1)]]))
(is (= [["dashboard" (:id dash1)]
["page" (:id dash2)]
["card" (:id card1)]
["dataset" (:id dataset)]
["table" (:id table1)]]
;; all views are from :rasta, but :crowberto can still see popular items
(for [popular-item (mt/user-http-request :crowberto :get 200 "activity/popular_items")]
((juxt :model :model_id) popular-item))))))))
(is (partial= [{:model "dashboard" :model_id (:id dash1)}
{:model "page" :model_id (:id dash2) :model_object {:is_app_page true
:app_id app-id}}
{:model "card" :model_id (:id card1)}
{:model "dataset" :model_id (:id dataset)}
{:model "table" :model_id (:id table1)}]
;; all views are from :rasta, but :crowberto can still see popular items
(mt/user-http-request :crowberto :get 200 "activity/popular_items")))))))
;;; activities->referenced-objects, referenced-objects->existing-objects, add-model-exists-info
......
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