Skip to content
Snippets Groups Projects
Unverified Commit f2ed9331 authored by Daniel Higginbotham's avatar Daniel Higginbotham Committed by GitHub
Browse files

add "unsubscribe from pulse" endpoint (#10688)

add an endpoint so that users who don't own a pulse can unsubscribe themselves from the pulse
parent 0d26bee7
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@
(assert 1)
(ex-info 1)
(expect 0)
(let-404 1)
(match 1)
(merge-with 1)
(with-redefs-fn 1)
......
......@@ -16,7 +16,8 @@
[collection :as collection]
[interface :as mi]
[pulse :as pulse :refer [Pulse]]
[pulse-channel :refer [channel-types]]]
[pulse-channel :refer [channel-types PulseChannel]]
[pulse-channel-recipient :refer [PulseChannelRecipient]]]
[metabase.pulse.render :as render]
[metabase.util
[i18n :refer [tru]]
......@@ -194,5 +195,13 @@
(p/send-pulse! body)
{:ok true})
(api/defendpoint DELETE "/:id/subscription/email"
"For uses to remove themselves from a pulse subscription"
[id]
(api/let-404 [pulse-id (db/select-one-id Pulse :id id)
pc-id (db/select-one-id PulseChannel :pulse_id pulse-id :channel_type "email")
pcr-id (db/select-one-id PulseChannelRecipient :pulse_channel_id pc-id :user_id api/*current-user-id*)]
(db/delete! PulseChannelRecipient :id pcr-id))
api/generic-204-no-content)
(api/define-routes)
......@@ -946,3 +946,30 @@
(tu/with-temporary-setting-values [slack-token nil]
(-> ((user->client :rasta) :get 200 "pulse/form_input")
(get-in [:channels :slack :fields]))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | DELETE /api/pulse/:pulse-id/subscription |
;;; +----------------------------------------------------------------------------------------------------------------+
(expect
nil
(tt/with-temp* [Pulse [{pulse-id :id} {:name "Lodi Dodi" :creator_id (user->id :crowberto)}]
PulseChannel [{channel-id :id} {:pulse_id pulse-id
:channel_type "email"
:schedule_type "daily"
:details {:other "stuff"
:emails ["foo@bar.com"]}}]
PulseChannelRecipient [pcr {:pulse_channel_id channel-id :user_id (user->id :rasta)}]]
((user->client :rasta) :delete 204 (str "pulse/" pulse-id "/subscription/email"))))
;; Users can't delete someone else's pulse subscription
(expect
"Not found."
(tt/with-temp* [Pulse [{pulse-id :id} {:name "Lodi Dodi" :creator_id (user->id :crowberto)}]
PulseChannel [{channel-id :id} {:pulse_id pulse-id
:channel_type "email"
:schedule_type "daily"
:details {:other "stuff"
:emails ["foo@bar.com"]}}]
PulseChannelRecipient [pcr {:pulse_channel_id channel-id :user_id (user->id :rasta)}]]
((user->client :lucky) :delete 404 (str "pulse/" pulse-id "/subscription/email"))))
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