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
Don't send alerts to deactivated users (GDGT-1927) (#72444)
Ngoc Khuat109257d6bc83
diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.cljindex b641b119535..c3c31a83d5c 100644--- a/src/metabase/notification/models.clj+++ b/src/metabase/notification/models.clj@@ -264,12 +264,18 @@{:default []}))(methodical/defmethod t2/batched-hydrate [:default :recipients-detail]- "Batch hydration of details (user, group members) for NotificationRecipients"+ "Batch hydration of details (user, group members) for NotificationRecipients.+ Only active users are attached as :user; deactivated users get :user nil so they+ don't receive notifications (GDGT-1927)."[_model _k recipients](-> (group-by :type recipients)(m/update-existing :notification-recipient/user(fn [recipients]- (t2/hydrate recipients :user)))+ (let [id->user (when (seq recipients)+ (t2/select-fn->fn :id identity :model/User+ :id [:in (map :user_id recipients)]+ :is_active true))]+ (mapv #(assoc % :user (id->user (:user_id %))) recipients))))(m/update-existing :notification-recipient/group(fn [recipients](t2/hydrate recipients [:permissions_group :members])))diff --git a/test/metabase/notification/payload/impl/card_test.clj b/test/metabase/notification/payload/impl/card_test.cljindex 0c598c0a588..d7de360e20b 100644--- a/test/metabase/notification/payload/impl/card_test.clj+++ b/test/metabase/notification/payload/impl/card_test.clj@@ -236,6 +236,25 @@(map (comp set :recipients))set))))})))+(deftest deactivated-user-recipients-are-not-emailed-test+ (testing "card alert emails are not sent to deactivated user recipients (GDGT-1927)"+ (mt/with-temp [:model/User {deactivated-id :id} {:email "[email protected]" :is_active false}+ :model/User {active-id :id} {:email "[email protected]" :is_active true}]+ (notification.tu/with-card-notification+ [notification {:handlers [{:channel_type :channel/email+ :recipients [{:type :notification-recipient/user :user_id deactivated-id}+ {:type :notification-recipient/user :user_id active-id}+ {:type :notification-recipient/raw-value :details {:value "[email protected]"}}]}]}]+ (notification.tu/test-send-notification!+ notification+ {:channel/email+ (fn [emails]+ (let [all-recipients (into #{} (mapcat :recipients) emails)]+ (is (contains? all-recipients "[email protected]"))+ (is (contains? all-recipients "[email protected]"))+ (is (not (contains? all-recipients "[email protected]"))+ "deactivated user must not receive the alert")))})))))+(deftest send-condition-has-result-test(testing "no result should skip sending"(doseq [has-result [true false]]