Skip to content

Commit

Permalink
Merge branch 'master' of github.com:metabase/metabase into flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrobinson committed May 26, 2016
2 parents 027a34e + 74d5dad commit 5cf8f04
Show file tree
Hide file tree
Showing 102 changed files with 972 additions and 1,283 deletions.
1 change: 0 additions & 1 deletion .dir-locals.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
(match 1)
(match-$ 1)
(org-perms-case 1)
(post-insert 1)
(post-select 1)
(pre-cascade-delete 1)
(pre-insert 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ export default class MetadataEditor extends Component {
}
} else {
content = (
<div className="flex flex-full layout-centered">
<div style={{paddingTop: "10rem"}} className="full text-centered">
<h2 className="text-grey-3">Select any table to see its schema and add or edit metadata.</h2>
</div>
);
}
return (
<div className="MetadataEditor full-height p3">
<div className="p3">
<MetadataHeader
ref="header"
databaseId={this.props.databaseId}
Expand All @@ -108,7 +108,7 @@ export default class MetadataEditor extends Component {
isShowingSchema={this.state.isShowingSchema}
toggleShowSchema={this.toggleShowSchema}
/>
<div className="MetadataEditor-main flex flex-row flex-full mt2 full-height">
<div style={{minHeight: "60vh"}} className="flex flex-row flex-full mt2 full-height">
<MetadataTablePicker
tableId={this.props.tableId}
tables={(this.props.databaseMetadata) ? this.props.databaseMetadata.tables : []}
Expand Down
16 changes: 8 additions & 8 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[amalloy/ring-gzip-middleware "0.1.3"] ; Ring middleware to GZIP responses if client can handle it
[aleph "0.4.1"] ; Async HTTP library; WebSockets
[cheshire "5.6.1"] ; fast JSON encoding (used by Ring JSON middleware)
[clj-http "3.0.1" ; HTTP client
[clj-http "3.1.0" ; HTTP client
:exclusions [commons-codec
commons-io
slingshot]]
Expand All @@ -38,14 +38,14 @@
org.apache.httpcomponents/httpclient
net.sourceforge.nekohtml/nekohtml
ring/ring-core]]
[com.draines/postal "1.11.4"] ; SMTP library
[com.draines/postal "2.0.0"] ; SMTP library
[com.google.apis/google-api-services-bigquery ; Google BigQuery Java Client Library
"v2-rev294-1.21.0"]
"v2-rev300-1.22.0"]
[com.h2database/h2 "1.4.191"] ; embedded SQL database
[com.mattbertolini/liquibase-slf4j "2.0.0"] ; Java Migrations lib
[com.novemberain/monger "3.0.2"] ; MongoDB Driver
[compojure "1.5.0"] ; HTTP Routing library built on Ring
[environ "1.0.2"] ; easy environment management
[environ "1.0.3"] ; easy environment management
[hiccup "1.0.5"] ; HTML templating
[honeysql "0.6.3"] ; Transform Clojure data structures to SQL
[korma "0.4.2"] ; SQL generation
Expand All @@ -54,13 +54,13 @@
javax.jms/jms
com.sun.jdmk/jmxtools
com.sun.jmx/jmxri]]
[medley "0.7.4"] ; lightweight lib of useful functions
[medley "0.8.1"] ; lightweight lib of useful functions
[metabase/throttle "1.0.1"] ; Tools for throttling access to API endpoints and other code pathways
[mysql/mysql-connector-java "5.1.38"] ; MySQL JDBC driver *** DON'T UPDATE THIS YET - NEW VERSION IS JAVA 8+ ONLY: http://dev.mysql.com/doc/connector-j/6.0/en/connector-j-whats-new.html ***
[mysql/mysql-connector-java "5.1.39"] ; MySQL JDBC driver (don't upgrade to 6.0+ yet -- that's Java 8 only)
[net.sf.cssbox/cssbox "4.11" ; HTML / CSS rendering
:exclusions [org.slf4j/slf4j-api]]
[net.sourceforge.jtds/jtds "1.3.1"] ; Open Source SQL Server driver
[org.liquibase/liquibase-core "3.5.0"] ; migration management (Java lib)
[org.liquibase/liquibase-core "3.5.1"] ; migration management (Java lib)
[org.slf4j/slf4j-log4j12 "1.7.21"] ; abstraction for logging frameworks -- allows end user to plug in desired logging framework at deployment time
[org.yaml/snakeyaml "1.17"] ; YAML parser (required by liquibase)
[org.xerial/sqlite-jdbc "3.8.11.2"] ; SQLite driver
Expand All @@ -73,7 +73,7 @@
[stencil "0.5.0"] ; Mustache templates for Clojure
[swiss-arrows "1.0.0"]] ; 'Magic wand' macro -<>, etc.
:repositories [["bintray" "https://dl.bintray.com/crate/crate"]]
:plugins [[lein-environ "1.0.2"] ; easy access to environment variables
:plugins [[lein-environ "1.0.3"] ; easy access to environment variables
[lein-ring "0.9.7" ; start the HTTP server with 'lein ring server'
:exclusions [org.clojure/clojure]]] ; TODO - should this be a dev dependency ?
:main ^:skip-aot metabase.core
Expand Down
2 changes: 1 addition & 1 deletion reset_password/metabase/reset_password/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(defn- set-reset-token!
"Set and return a new `reset_token` for the user with EMAIL-ADDRESS."
[email-address]
(let [user-id (or (db/sel :one :id 'User, :email email-address)
(let [user-id (or (db/select-one-id 'User, :email email-address)
(throw (Exception. (format "No user found with email address '%s'. Please check the spelling and try again." email-address))))]
(user/set-user-password-reset-token user-id)))

Expand Down
20 changes: 1 addition & 19 deletions resources/words-by-frequency.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ as
he
on
by
s
with
from
or
Expand Down Expand Up @@ -136,7 +135,6 @@ work
now
could
long
j
however
group
what
Expand All @@ -145,7 +143,6 @@ started
way
since
around
d
both
commune
while
Expand Down Expand Up @@ -174,7 +171,6 @@ country
main
government
century
c
means
university
life
Expand Down Expand Up @@ -203,12 +199,9 @@ four
river
back
just
m
still
utc
n
located
t
population
including
king
Expand All @@ -220,7 +213,6 @@ left
school
great
end
e
against
september
high
Expand All @@ -247,7 +239,6 @@ using
district
based
form
b
german
games
near
Expand Down Expand Up @@ -354,7 +345,6 @@ next
moved
light
five
f
third
change
makes
Expand Down Expand Up @@ -421,7 +411,6 @@ formed
roman
instead
women
g
army
computer
find
Expand Down Expand Up @@ -524,9 +513,7 @@ space
hockey
led
close
p
political
r
eastern
look
hard
Expand Down Expand Up @@ -554,12 +541,10 @@ green
names
especially
soon
h
someone
idea
seven
included
l
caused
move
open
Expand All @@ -568,7 +553,6 @@ study
official
italian
run
k
village
ice
working
Expand Down Expand Up @@ -653,7 +637,6 @@ our
reason
event
goes
v
ocean
blood
hit
Expand Down Expand Up @@ -863,7 +846,6 @@ date
valley
tells
speed
w
stage
al
standard
Expand Down Expand Up @@ -125546,4 +125528,4 @@ sherd
blabbing
oracular
incapability
pebbliest
pebbliest
20 changes: 8 additions & 12 deletions src/metabase/api/activity.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns metabase.api.activity
(:require [compojure.core :refer [GET]]
[korma.core :as k]
[metabase.api.common :refer :all]
[metabase.db :as db]
(metabase.models [activity :refer [Activity]]
Expand All @@ -19,7 +18,7 @@
(defendpoint GET "/"
"Get recent activity."
[]
(-> (db/sel :many Activity (k/order :timestamp :DESC) (k/limit 40))
(-> (db/select Activity, {:order-by [[:timestamp :desc]], :limit 40})
(hydrate :user :table :database :model_exists)
(->> (mapv dashcard-exists))))

Expand All @@ -30,17 +29,14 @@
;; expected output of the query is a single row per unique model viewed by the current user
;; including a `:max_ts` which has the most recent view timestamp of the item and `:cnt` which has total views
;; and we order the results by most recently viewed then hydrate the basic details of the model
(for [view-log (k/select ViewLog
(k/fields :user_id :model :model_id)
(k/aggregate (count :*) :cnt)
(k/aggregate (max :timestamp) :max_ts)
(k/where (= :user_id *current-user-id*))
(k/group :user_id :model :model_id)
(k/order :max_ts :desc)
(k/limit 10))
(for [view-log (db/select [ViewLog :user_id :model :model_id [:%count.* :cnt] [:%max.timestamp :max_ts]]
:user_id *current-user-id*
{:group-by [:user_id :model :model_id]
:order-by [[:max_ts :desc]]
:limit 10})
:let [model-object (case (:model view-log)
"card" (db/sel :one [Card :id :name :description :display], :id (:model_id view-log))
"dashboard" (db/sel :one [Dashboard :id :name :description], :id (:model_id view-log))
"card" (db/select-one [Card :id :name :description :display], :id (:model_id view-log))
"dashboard" (db/select-one [Dashboard :id :name :description], :id (:model_id view-log))
nil)]
:when model-object]
(assoc view-log :model_object model-object)))
Expand Down
4 changes: 2 additions & 2 deletions src/metabase/api/card.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[cards]
(let [card-labels (db/select [CardLabel :card_id :label_id])
label-id->label (when (seq card-labels)
(db/select-id->obj Label :id [:in (map :label_id card-labels)]))
(u/key-by :id (db/select Label :id [:in (map :label_id card-labels)])))
card-id->card-labels (group-by :card_id card-labels)]
(for [card cards]
(assoc card :labels (for [card-label (card-id->card-labels (:id card))] ; TODO - do these need to be sorted ?
Expand Down Expand Up @@ -68,7 +68,7 @@
Make sure cards are returned in the same order as CARD-IDS`; `[in card-ids]` won't preserve the order."
[card-ids]
{:pre [(every? integer? card-ids)]}
(let [card-id->card (db/select-id->obj Card, :id [:in card-ids], :archived false)]
(let [card-id->card (u/key-by :id (db/select Card, :id [:in (set card-ids)], :archived false))]
(filter identity (map card-id->card card-ids))))

(defn- cards:recent
Expand Down
3 changes: 1 addition & 2 deletions src/metabase/api/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[walk :as walk])
[cheshire.core :as json]
[compojure.core :refer [defroutes]]
[korma.core :as k]
[medley.core :as m]
[metabase.api.common.internal :refer :all]
[metabase.db :as db]
Expand Down Expand Up @@ -65,7 +64,7 @@
(defn check-superuser
"Check that `*current-user*` is a superuser or throw a 403."
[]
(check-403 (:is_superuser @*current-user*)))
(check-403 (db/exists? 'User, :id *current-user-id*, :is_superuser true)))


;;; #### checkp- functions: as in "check param". These functions expect that you pass a symbol so they can throw exceptions w/ relevant error messages.
Expand Down
13 changes: 6 additions & 7 deletions src/metabase/api/dashboard.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns metabase.api.dashboard
"/api/dashboard endpoints."
(:require [compojure.core :refer [GET POST PUT DELETE]]
[korma.core :as k]
[metabase.events :as events]
[metabase.api.common :refer :all]
[metabase.db :as db]
Expand All @@ -19,10 +18,10 @@
* `mine` - Return `Dashboards` created by the current user."
[f]
{f FilterOptionAllOrMine}
(-> (case (or f :all)
:all (db/sel :many Dashboard (k/where (or {:creator_id *current-user-id*}
{:public_perms [> common/perms-none]})))
:mine (db/sel :many Dashboard :creator_id *current-user-id*))
(-> (db/select Dashboard {:where (case (or f :all)
:all [:or [:= :creator_id *current-user-id*]
[:> :public_perms common/perms-none]]
:mine [:= :creator_id *current-user-id*])})
(hydrate :creator :can_read :can_write)))

(defendpoint POST "/"
Expand Down Expand Up @@ -63,7 +62,7 @@
[id]
(write-check Dashboard id)
;; TODO - it would be much more natural if `cascade-delete` returned the deleted entity instead of an api response
(let [dashboard (db/sel :one Dashboard :id id)
(let [dashboard (Dashboard id)
result (db/cascade-delete! Dashboard :id id)]
(events/publish-event :dashboard-delete (assoc dashboard :actor_id *current-user-id*))
result))
Expand Down Expand Up @@ -96,7 +95,7 @@
...}]} ...]}"
[id :as {{:keys [cards]} :body}]
(write-check Dashboard id)
(let [dashcard-ids (set (db/sel :many :id DashboardCard, :dashboard_id id))]
(let [dashcard-ids (db/select-ids DashboardCard, :dashboard_id id)]
(doseq [{dashcard-id :id :as dashboard-card} cards]
;; ensure the dashcard we are updating is part of the given dashboard
(when (contains? dashcard-ids dashcard-id)
Expand Down
Loading

0 comments on commit 5cf8f04

Please sign in to comment.