Skip to content
Snippets Groups Projects
Commit 7fb525d2 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add in a `:configured?` property to the /api/pulse/form_input definitions of...

add in a `:configured?` property to the /api/pulse/form_input definitions of the available channels so the frontend knows if a given channel is actually available to the user.
parent d59e87c2
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,12 @@
[metabase.api.common :refer :all]
[metabase.db :as db]
[metabase.driver :as driver]
[metabase.email :as email]
[metabase.integrations.slack :as slack]
(metabase.models [card :refer [Card]]
[database :refer [Database]]
[pulse :refer [Pulse] :as pulse]
[pulse-channel :refer [channel-types]]
[setting :as setting])
[pulse-channel :refer [channel-types]])
[metabase.pulse :as p]))
......@@ -62,11 +62,16 @@
(defendpoint GET "/form_input"
"Provides relevant configuration information and user choices for creating/updating `Pulses`."
[]
(if (empty? (setting/get :slack-token))
{:channels channel-types}
(let [slack-channels (mapv (fn [ch] (str "#" (get ch "name"))) (get (slack/channels-list) "channels"))
slack-users (mapv (fn [u] (str "@" (get u "name"))) (get (slack/users-list) "members"))]
{:channels (assoc-in channel-types [:slack :fields 0 :options] (concat slack-channels slack-users))})))
(let [chan-types (-> channel-types
(assoc-in [:slack :configured?] (slack/slack-configured?))
(assoc-in [:email :configured?] (email/email-configured?)))]
{:channels (if-not (get-in chan-types [:slack :configured])
;; no Slack integration, so we are g2g
chan-types
;; if we have Slack enabled build a dynamic list of channels/users
(let [slack-channels (mapv (fn [ch] (str "#" (get ch "name"))) (get (slack/channels-list) "channels"))
slack-users (mapv (fn [u] (str "@" (get u "name"))) (get (slack/users-list) "members"))]
(assoc-in chan-types [:slack :fields 0 :options] (concat slack-channels slack-users))))}))
(defendpoint GET "/preview_card/:id"
......
(ns metabase.email
(:require [clojure.tools.logging :as log]
(:require [clojure.string :as s]
[clojure.tools.logging :as log]
[postal.core :as postal]
[metabase.models.setting :refer [defsetting]]
[metabase.models.setting :refer [defsetting] :as setting]
[metabase.util :as u]))
;; ## CONFIG
......@@ -20,6 +21,11 @@
Provided so you can swap this out with an \"inbox\" for test purposes."
postal/send-message)
(defn email-configured?
"Predicate function which returns `true` if we have a viable email configuration for the app, `false` otherwise."
[]
(not (s/blank? (setting/get* :email-smtp-host))))
(defn send-message
"Send an email to one or more RECIPIENTS.
RECIPIENTS is a sequence of email addresses; MESSAGE-TYPE must be either `:text` or `:html`.
......
......@@ -12,6 +12,12 @@
(def ^:const slack-api-baseurl "https://slack.com/api")
(defn slack-configured?
"Predicate function which returns `true` if the application has a valid integration with Slack, `false` otherwise."
[]
(not (empty? (slack-token))))
(defn slack-api-get
"Generic function which calls a given method on the Slack api via HTTP GET."
([token method]
......
......@@ -190,11 +190,10 @@
:anon_tracking_enabled (let [tracking? (get :anon-tracking-enabled)]
(or (nil? tracking?) (= "true" tracking?)))
:site_name (get :site-name)
:email_configured (not (s/blank? (or (get :email-smtp-host) (get-from-env-var :email-smtp-host))))
:email_configured (@(resolve 'metabase.email/email-configured?))
:admin_email (get :admin-email)
:report_timezone (get :report-timezone)
:timezone_short (short-timezone-name (get-instance-timezone))
})
:timezone_short (short-timezone-name (get-instance-timezone))})
;;; # IMPLEMENTATION
......
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