Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metabase channel #43924

Merged
merged 29 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
538d488
adding the channel
qnkhuat Jun 10, 2024
3305b8e
pulse with new slack channel
qnkhuat Jun 10, 2024
9b9ce20
pulse with email channels
qnkhuat Jun 10, 2024
d1cd4c2
pulse now use all channels api
qnkhuat Jun 10, 2024
ba0614b
tidy up and support retry
qnkhuat Jun 11, 2024
de5689e
fixing tests + retry sending
qnkhuat Jun 11, 2024
02ab272
pulse tests passed
qnkhuat Jun 11, 2024
17f8b34
fix test failed to compile
qnkhuat Jun 11, 2024
36f750f
test fixing...
qnkhuat Jun 11, 2024
8ed0d00
handle channel correctly
qnkhuat Jun 11, 2024
1c805de
remove debug code
qnkhuat Jun 11, 2024
2c82e37
still fixing tests
qnkhuat Jun 11, 2024
03de60a
test fixes :crossed-finger
qnkhuat Jun 12, 2024
579a475
test fixes :crossed-finger 2
qnkhuat Jun 12, 2024
578171e
ci should be green now
qnkhuat Jun 12, 2024
14df2a5
Tidy
qnkhuat Jun 12, 2024
09598d1
remove pulse test that no longer needed
qnkhuat Jun 12, 2024
607b81e
remove pulse test that no longer needed
qnkhuat Jun 12, 2024
7138fc6
add attachments test for dashboard sub
qnkhuat Jun 12, 2024
be29d5d
no more doall with for
qnkhuat Jun 12, 2024
56998cb
Merge branch 'master' into channel
qnkhuat Jun 12, 2024
fcba1b8
Update test/metabase/pulse_test.clj
qnkhuat Jun 13, 2024
6f67e2e
Merge branch 'master' into channel
qnkhuat Jun 18, 2024
4f3b26f
Add an helper and make sure we don't send to archived channels
qnkhuat Jun 13, 2024
354b6c1
final tidy
qnkhuat Jun 19, 2024
2342e92
no inline def for tests
qnkhuat Jun 19, 2024
caf79fa
helper docstring
qnkhuat Jun 19, 2024
25b55cf
test fixes
qnkhuat Jun 19, 2024
a2e03a9
retrieve the disabled pulses too
qnkhuat Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
metabase.audit #{metabase.audit}
metabase.bootstrap #{metabase.bootstrap}
metabase.cmd #{} ; there are no namespaces here since you shouldn't be using this in any other module.
metabase.channel #{metabase.channel.core}
metabase.config #{metabase.config}
metabase.core #{metabase.core.initialization-status} ; TODO -- only namespace used outside of EE, this probably belongs in `metabase.server` anyway since that's the only place it's used.
metabase.db #{metabase.db
Expand Down Expand Up @@ -265,6 +266,7 @@
metabase.bootstrap #{}
metabase.cmd :any
metabase.compatibility :any
metabase.channel :any
metabase.config #{metabase.plugins}
metabase.core :any
metabase.db :any
Expand Down Expand Up @@ -412,6 +414,7 @@
metabase.api.user api.user
metabase.api.util api.util
metabase.async.streaming-response.thread-pool thread-pool
metabase.channel.core channel
metabase.cmd.copy.h2 copy.h2
metabase.config config
metabase.config.file config.file
Expand Down
24 changes: 24 additions & 0 deletions dev/src/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
[metabase.driver :as driver]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
[metabase.email :as email]
[metabase.models.database :refer [Database]]
[metabase.models.setting :as setting]
[metabase.query-processor.compile :as qp.compile]
[metabase.query-processor.timezone :as qp.timezone]
[metabase.server :as server]
Expand Down Expand Up @@ -386,3 +388,25 @@
(when (failed?)
(throw (ex-info (format "Test failed after running: `%s`" test)
{:test test})))))))


(defn setup-email!
"Set up email settings for sending emails from Metabase. This is useful for testing email sending in the REPL."
[& settings]
(let [settings (merge {:host "localhost"
:port 1025
:user "metabase"
:pass "metabase@secret"
:security :none}
settings)]
(when (::email/error (email/test-smtp-connection settings))
(throw (ex-info "Failed to connect to SMTP server" {:settings settings})))
(setting/set-many! (update-keys settings
{:host :email-smtp-host,
:user :email-smtp-username,
:pass :email-smtp-password,
:port :email-smtp-port,
:security :email-smtp-security,
:sender-name :email-from-name,
:sender :email-from-address,
:reply-to :email-reply-to}))))
25 changes: 14 additions & 11 deletions dev/src/dev/render_png.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[metabase.email.messages :as messages]
[metabase.models :refer [Card]]
[metabase.models.card :as card]
[metabase.models.user :as user]
[metabase.pulse :as pulse]
[metabase.pulse.markdown :as markdown]
[metabase.pulse.render :as render]
Expand All @@ -30,11 +29,11 @@
(condp
#(<= 0 (.indexOf ^String %2 ^String %1))
(.toLowerCase (System/getProperty "os.name"))
"win" :win
"mac" :mac
"nix" :unix
"nux" :unix
nil))
"win" :win
"mac" :mac
"nix" :unix
"nux" :unix
nil))

;; taken from https://github.com/aysylu/loom/blob/master/src/loom/io.clj
(defn- open
Expand Down Expand Up @@ -81,16 +80,20 @@
nil
query-results)))

(defn open-hiccup-as-html
"Take a hiccup data structure, render it as html, then open it in the browser."
[hiccup]
(let [html-str (hiccup/html hiccup)
tmp-file (File/createTempFile "card-html" ".html")]
(defn open-html
"Take a html string, then open it in the browser."
[html-str]
(let [tmp-file (File/createTempFile "card-html" ".html")]
(with-open [w (io/writer tmp-file)]
(.write w ^String html-str))
(.deleteOnExit tmp-file)
(open tmp-file)))

(defn open-hiccup-as-html
"Take a hiccup data structure, render it as html, then open it in the browser."
[hiccup]
(open-html (hiccup/html hiccup)))

(def ^:private execute-dashboard #'pulse/execute-dashboard)

(defn render-dashboard-to-pngs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@

(deftest test-pulse-endpoint-should-respect-email-domain-allow-list-test
(testing "POST /api/pulse/test"
(t2.with-temp/with-temp [Card card {:dataset_query (mt/mbql-query venues)}]
(t2.with-temp/with-temp [Card card {:name "Test card"
:dataset_query (mt/mbql-query venues)}]
;; make sure we validate raw emails whether they're part of `:details` or part of `:recipients` -- we
;; technically allow either right now
(doseq [channel [{:details {:emails ["test@metabase.com"]}}
{:recipients [{:email "test@metabase.com"}]
:details {}}]]
(testing (format "\nChannel = %s\n" (u/pprint-to-str channel))
(letfn [(send! [expected-status-code]
(let [pulse-name (mt/random-name)]
(mt/with-fake-inbox
{:response (mt/user-http-request
:rasta :post expected-status-code "pulse/test"
{:name pulse-name
:cards [{:id (u/the-id card)
:include_csv false
:include_xls false
:dashboard_card_id nil}]
:channels [(merge {:enabled true
:channel_type "email"
:schedule_type "daily"
:schedule_hour 12
:schedule_day nil}
channel)]
:skip_if_empty false})
:recipients (set (keys (mt/regex-email-bodies (re-pattern pulse-name))))})))]
(mt/with-fake-inbox
{:response (mt/user-http-request
:rasta :post expected-status-code "pulse/test"
{:name (mt/random-name)
:cards [{:id (u/the-id card)
:include_csv false
:include_xls false
:dashboard_card_id nil}]
:channels [(merge {:enabled true
:channel_type "email"
:schedule_type "daily"
:schedule_hour 12
:schedule_day nil}
channel)]
:alert_condition "rows"
:skip_if_empty false})
:recipients (set (keys (mt/regex-email-bodies (re-pattern "Test card"))))}))]
(testing "allowed email -- should pass"
(mt/with-premium-features #{:email-allow-list}
(mt/with-temporary-setting-values [subscription-allowed-domains "metabase.com"]
Expand Down
Loading
Loading