The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
(ns metabase-enterprise.audit-app.api.user
"`/api/ee/audit-app/user` endpoints. These only work if you have a premium token with the `:audit-app` feature."
(:require
[metabase-enterprise.audit-app.audit :as ee-audit]
[metabase-enterprise.audit-app.db :as audit-app.db]
[metabase.api.common :as api]
[metabase.api.macros :as api.macros]
[metabase.audit-app.core :as audit]
[metabase.models.interface :as mi]
[metabase.users.core :as users]
[metabase.util :as u]
[metabase.util.malli.schema :as ms]))
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
;; use our API + we will need it when we make auto-TypeScript-signature generation happen
;;
#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}
(api.macros/defendpoint :get "/audit-info"
"Gets audit info for the current user if he has permissions to access the audit collection.
Otherwise return an empty map."
[]
(let [custom-reports (audit/default-custom-reports-collection)
question-overview (audit/memoized-select-audit-entity :model/Dashboard ee-audit/default-question-overview-entity-id)
dashboard-overview (audit/memoized-select-audit-entity :model/Dashboard ee-audit/default-dashboard-overview-entity-id)]
(merge
{}
(when (mi/can-read? (audit/default-custom-reports-collection))
{(:slug custom-reports) (:id custom-reports)})
(when (mi/can-read? (audit/default-audit-collection))
{(u/slugify (:name question-overview)) (:id question-overview)
(u/slugify (:name dashboard-overview)) (:id dashboard-overview)}))))
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
;; use our API + we will need it when we make auto-TypeScript-signature generation happen
;;
#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}
(api.macros/defendpoint :delete "/:id/subscriptions"
"Delete all Alert and DashboardSubscription subscriptions for a User (i.e., so they will no longer receive them).
Archive all Alerts and DashboardSubscriptions created by the User. Only allowed for admins or for the current user."
[{:keys [id]} :- [:map {:closed true}
[:id ms/PositiveInt]]]
(users/check-self-or-superuser id)
;; delete all `PulseChannelRecipient` rows for this User, which means they will no longer receive any
;; Alerts/DashboardSubscriptions
(audit-app.db/delete-pulse-channel-recipients-of-user! id)
(audit-app.db/delete-notification-recipients-of-user! id)
;; archive anything they created.
(audit-app.db/archive-pulses-of-creator! id)
(audit-app.db/deactivate-notifications-of-creator! id)
api/generic-204-no-content)