Skip to content
Snippets Groups Projects
Unverified Commit faf007aa authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

DELETE /api/ee/audit-app/user/:id/subscriptions archive Pulses created by user (#17981)

parent d925eeb5
Branches
Tags
No related merge requests found
......@@ -3,15 +3,20 @@
(:require [compojure.core :refer [DELETE]]
[metabase.api.common :as api]
[metabase.api.user :as api.user]
[metabase.models.pulse :refer [Pulse]]
[metabase.models.pulse-channel-recipient :refer [PulseChannelRecipient]]
[toucan.db :as db]))
(api/defendpoint DELETE "/:id/subscriptions"
"Delete all Alert and DashboardSubscription subscriptions for a User. Only allowed for admins or for the current
user."
"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."
[id]
(api.user/check-self-or-superuser id)
;; delete all `PulseChannelRecipient` rows for this User, which means they will no longer receive any
;; Alerts/DashboardSubscriptions
(db/delete! PulseChannelRecipient :user_id id)
;; archive anything they created.
(db/update-where! Pulse {:creator_id id, :archived false} :archived true)
api/generic-204-no-content)
(api/define-routes)
......@@ -19,7 +19,7 @@
(doseq [run-type [:admin :non-admin]]
(mt/with-temp* [User [{user-id :id}]
Card [{card-id :id}]
;; Alert
;; Alert, created by a different User
Pulse [{alert-id :id} {:alert_condition "rows"
:alert_first_only false
:name nil}]
......@@ -28,16 +28,19 @@
PulseChannel [{alert-chan-id :id} {:pulse_id alert-id}]
PulseChannelRecipient [_ {:user_id user-id
:pulse_channel_id alert-chan-id}]
;; DashboardSubscription
;; DashboardSubscription, created by this User; multiple recipients
Dashboard [{dashboard-id :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id
:card_id card-id}]
Pulse [{dash-sub-id :id} {:dashboard_id dashboard-id}]
Pulse [{dash-sub-id :id} {:dashboard_id dashboard-id
:creator_id user-id}]
PulseCard [_ {:pulse_id dash-sub-id
:card_id card-id
:dashboard_card_id dashcard-id}]
PulseChannel [{dash-sub-chan-id :id} {:pulse_id dash-sub-id}]
PulseChannelRecipient [_ {:user_id user-id
:pulse_channel_id dash-sub-chan-id}]
PulseChannelRecipient [_ {:user_id (mt/user->id :rasta)
:pulse_channel_id dash-sub-chan-id}]]
(letfn [(describe-objects []
{:num-subscriptions (db/count PulseChannelRecipient :user_id user-id)
......@@ -64,7 +67,8 @@
(describe-objects))))
(testing "should be allowed to delete all subscriptions for themselves."
(is (nil? (api-delete-subscriptions! user-id 204)))
(testing "\nAlert and DashboardSubscription should have gotten archived as well (since this was the last User)"
(testing (str "\nAlert should get archived because this User was the last subscriber."
"\nDashboardSubscription should get archived because this User created it.")
(is (= {:num-subscriptions 0
:alert-archived? true
:dashboard-subscription-archived? true}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment