Skip to content
Snippets Groups Projects
Commit a89592d1 authored by Ryan Senior's avatar Ryan Senior
Browse files

Add alerts to the activity feed

Previously alerts were showing up as pulses. This commit adds a
distinction between pulses and alerts
parent d4448755
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,44 @@ export default class Activity extends Component {
};
switch (item.topic) {
case "alert-create":
if(item.model_exists) {
description.summary = (
<span>
{t`created an alert about - `}
<Link to={Urls.modelToUrl(item.model, item.model_id)}
data-metabase-event={"Activity Feed;Header Clicked;Database -> " + item.topic}
className="link text-dark"
>
{item.details.name}
</Link>
</span>
);
} else {
description.summary = (
<span>{t`created an alert about - `}<span className="text-dark">{item.details.name}</span></span>
);
}
break;
case "alert-delete":
if(item.model_exists) {
description.summary = (
<span>
{t`deleted an alert about - `}
<Link to={Urls.modelToUrl(item.model, item.model_id)}
data-metabase-event={"Activity Feed;Header Clicked;Database -> " + item.topic}
className="link text-dark"
>
{item.details.name}
</Link>
</span>
);
} else {
description.summary = (
<span>{t`deleted an alert about- `}<span className="text-dark">{item.details.name}</span></span>
);
}
break;
case "card-create":
case "card-update":
if(item.table) {
......
......@@ -5,6 +5,7 @@
[medley.core :as m]
[metabase
[email :as email]
[events :as events]
[util :as u]]
[metabase.api
[common :as api]
......@@ -174,6 +175,8 @@
(db/delete! Pulse :id id)
(events/publish-event! :alert-delete (assoc alert :actor_id api/*current-user-id*))
(when (email/email-configured?)
(doseq [recipient recipients]
(messages/send-admin-unsubscribed-alert-email! alert recipient @api/*current-user*))
......
......@@ -15,7 +15,9 @@
(def ^:const activity-feed-topics
"The `Set` of event topics which are subscribed to for use in the Metabase activity feed."
#{:card-create
#{:alert-create
:alert-delete
:card-create
:card-update
:card-delete
:dashboard-create
......@@ -98,6 +100,16 @@
:object object
:details-fn details-fn)))
(defn- process-alert-activity! [topic {:keys [card] :as alert}]
(let [details-fn #(select-keys (:card %) [:name])]
(activity/record-activity!
;; Alerts are centered around a card/question. Users always interact with the alert via the question
:model "card"
:model-id (:id card)
:topic topic
:object alert
:details-fn details-fn)))
(defn- process-segment-activity! [topic object]
(let [details-fn #(select-keys % [:name :description :revision_message])
table-id (:table_id object)
......@@ -123,7 +135,8 @@
(db/insert! Activity, :topic "install", :model "install")))
(def ^:private model->processing-fn
{"card" process-card-activity!
{"alert" process-alert-activity!
"card" process-card-activity!
"dashboard" process-dashboard-activity!
"install" process-install-activity!
"metric" process-metric-activity!
......
......@@ -243,15 +243,14 @@
(doseq [[channel-type] pulse-channel/channel-types]
(handle-channel channel-type))))
(defn- create-notification [pulse card-ids channels retrieve-pulse-fn]
(defn- create-notification [pulse card-ids channels]
(db/transaction
(let [{:keys [id] :as pulse} (db/insert! Pulse pulse)]
;; add card-ids to the Pulse
(update-pulse-cards! pulse card-ids)
;; add channels to the Pulse
(update-pulse-channels! pulse channels)
;; return the full Pulse (and record our create event)
(events/publish-event! :pulse-create (retrieve-pulse-fn id)))))
id)))
(defn create-pulse!
......@@ -267,17 +266,21 @@
(every? integer? card-ids)
(coll? channels)
(every? map? channels)]}
(create-notification {:creator_id creator-id
:name pulse-name
:skip_if_empty skip-if-empty?}
card-ids channels retrieve-pulse))
(let [id (create-notification {:creator_id creator-id
:name pulse-name
:skip_if_empty skip-if-empty?}
card-ids channels)]
;; return the full Pulse (and record our create event)
(events/publish-event! :pulse-create (retrieve-pulse id))))
(defn create-alert!
"Creates a pulse with the correct fields specified for an alert"
[alert creator-id card-id channels]
(-> alert
(assoc :skip_if_empty true :creator_id creator-id)
(create-notification [card-id] channels retrieve-alert)))
(let [id (-> alert
(assoc :skip_if_empty true :creator_id creator-id)
(create-notification [card-id] channels))]
;; return the full Pulse (and record our create event)
(events/publish-event! :alert-create (retrieve-alert id))))
(defn update-notification!
"Updates the pulse/alert and updates the related channels"
......
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