Skip to content
Snippets Groups Projects
Commit 33d5828b authored by Simon Belak's avatar Simon Belak
Browse files

Redo cell api, fix decoding bug

parent d7ff03aa
No related branches found
No related tags found
No related merge requests found
(ns metabase.api.automagic-dashboards (ns metabase.api.automagic-dashboards
(:require [cheshire.core :as json] (:require [buddy.core.codecs :as codecs]
[cheshire.core :as json]
[compojure.core :refer [GET POST]] [compojure.core :refer [GET POST]]
[metabase.api [metabase.api
[card :as card.api] [card :as card.api]
...@@ -22,6 +23,9 @@ ...@@ -22,6 +23,9 @@
[db :as db] [db :as db]
[hydrate :refer [hydrate]]])) [hydrate :refer [hydrate]]]))
(def ^:private ^{:arglists '([s])} decode-base64-json
(comp json/decode codecs/bytes->str codec/base64-decode))
(api/defendpoint GET "/database/:id/candidates" (api/defendpoint GET "/database/:id/candidates"
"Return a list of candidates for automagic dashboards orderd by interestingness." "Return a list of candidates for automagic dashboards orderd by interestingness."
[id] [id]
...@@ -57,23 +61,19 @@ ...@@ -57,23 +61,19 @@
api/check-404 api/check-404
(magic/automagic-dashboard (rules/load-rule (str prefix "/" rule ".yaml"))))) (magic/automagic-dashboard (rules/load-rule (str prefix "/" rule ".yaml")))))
(api/defendpoint GET "/question/:id/:cell-query" (api/defendpoint GET "/question/:id/cell/:cell-query"
"Return an automagic dashboard analyzing cell in question with id `id` defined by "Return an automagic dashboard analyzing cell in question with id `id` defined by
query `cell-querry`." query `cell-querry`."
[id cell-query] [id cell-query]
(-> (card.api/adhoc-query {:query {:filter (-> cell-query (-> (card.api/adhoc-query {:query {:filter (decode-base64-json cell-query)}})
codec/base64-decode
json/decode)}})
(magic/inject-segment (-> id Card api/check-404)) (magic/inject-segment (-> id Card api/check-404))
magic/automagic-dashboard)) magic/automagic-dashboard))
(api/defendpoint GET "/question/:id/:cell-query/:prefix/:rule" (api/defendpoint GET "/question/:id/cell/:cell-query/:prefix/:rule"
"Return an automagic dashboard analyzing cell in question with id `id` defined by "Return an automagic dashboard analyzing cell in question with id `id` defined by
query `cell-querry` using rule `rule`." query `cell-querry` using rule `rule`."
[id cell-query prefix rule] [id cell-query prefix rule]
(-> (card.api/adhoc-query {:query {:filter (-> cell-query (-> (card.api/adhoc-query {:query {:filter (decode-base64-json cell-query)}})
codec/base64-decode
json/decode)}})
(magic/inject-segment (-> id Card api/check-404)) (magic/inject-segment (-> id Card api/check-404))
(magic/automagic-dashboard (rules/load-rule (str prefix "/" rule ".yaml"))))) (magic/automagic-dashboard (rules/load-rule (str prefix "/" rule ".yaml")))))
...@@ -96,8 +96,7 @@ ...@@ -96,8 +96,7 @@
"Return an automagic dashboard analyzing ad hoc query." "Return an automagic dashboard analyzing ad hoc query."
[query] [query]
(-> query (-> query
codec/base64-decode decode-base64-json
json/decode
card.api/adhoc-query card.api/adhoc-query
magic/automagic-analysis)) magic/automagic-analysis))
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
(or (db/select-one 'Collection (or (db/select-one 'Collection
:name "Automatically Generated Questions") :name "Automatically Generated Questions")
(create-collection! "Automatically Generated Questions" (create-collection! "Automatically Generated Questions"
"#000000" "#509EE3"
"Cards used in automatically generated dashboards.")))) "Cards used in automatically generated dashboards."))))
(defn- add-card (defn- add-card
......
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