Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to get stale dashboards and cards #44711

Merged
merged 23 commits into from
Jul 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add collections to stale endpoint
  • Loading branch information
johnswanson committed Jul 29, 2024
commit c73d448d4e2962b16ed370e168f1629a3ab85029
29 changes: 27 additions & 2 deletions src/metabase/api/collection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,29 @@
matter! The calling function, `present-items`, is responsible for ensuring the order is maintained."
(fn [model _items] model))

(defn- present-collections [rows]
(let [coll-id->coll (into {} (for [{coll :collection} rows
:when (some? coll)] [(:id coll) coll]))
to-fetch (into #{} (comp (keep :effective_location)
(mapcat collection/location-path->ids)
(remove coll-id->coll))
(vals coll-id->coll))
coll-id->coll (merge (if (seq to-fetch)
(t2/select-pk->fn identity :model/Collection :id [:in to-fetch])
{})
coll-id->coll)
annotate (fn [x]
(assoc x :collection {:id (get-in x [:collection :id])
:name (get-in x [:collection :name])
:authority_level (get-in x [:collection :authority_level])
:type (get-in x [:collection :type])
:effective_ancestors (if-let [loc (:effective_location (:collection x))]
(->> (collection/location-path->ids loc)
(map coll-id->coll)
(map #(select-keys % [:id :name :authority_level :type])))
[])}))]
(map annotate rows)))

(defmethod present-model-items :model/Card [_ cards]
(->> (t2/hydrate (t2/select [:model/Card
:id
Expand Down Expand Up @@ -997,7 +1020,8 @@
:limit 1}
:moderated_status]]
:id [:in (set (map :id cards))])
:can_write :can_delete :can_restore)
:can_write :can_delete :can_restore [:collection :effective_location])
present-collections
(map (fn [card]
(-> card
(assoc :model (if (card/model? card) "dataset" "card"))
Expand All @@ -1019,7 +1043,8 @@
[nil :database_id]]

:id [:in (set (map :id dashboards))])
:can_write :can_delete :can_restore)))
:can_write :can_delete :can_restore [:collection :effective_location])
present-collections))

(defenterprise find-stale-candidates
"Returns a boolean if the current user uses sandboxing for any database. In OSS this is always false. Will throw an
Expand Down