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

streamline public settings availability and syncing. this is driven mostly by...

streamline public settings availability and syncing.  this is driven mostly by the need to have an `:email_configured` property that we can use on the frontend to dictate some of our UI.
parent 76f2d08b
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ MetabaseControllers.controller('Metabase', ['$scope', '$location', 'MetabaseCore
$scope.$on("appstate:site-settings", function(event, settings) {
// change in global settings
$scope.siteName = settings['site-name'].value;
$scope.siteName = settings.site_name;
});
$scope.$on("appstate:user", function(event, user) {
......
......@@ -26,6 +26,10 @@ const MetabaseSettings = {
return mb_settings.email_configured;
},
isTrackingEnabled: function() {
return mb_settings.anon_tracking_enabled || false;
},
hasSetupToken: function() {
return (mb_settings.setup_token !== undefined && mb_settings.setup_token !== null);
},
......
......@@ -2,13 +2,12 @@
import _ from "underscore";
/* Services */
import MetabaseAnalytics from 'metabase/lib/analytics';
import MetabaseCookies from 'metabase/lib/cookies';
import MetabaseCore from 'metabase/lib/core';
import MetabaseSettings from 'metabase/lib/settings';
var MetabaseServices = angular.module('metabase.services', ['http-auth-interceptor', 'ipCookie', 'metabase.core.services']);
MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interval', '$timeout', 'ipCookie', 'Session', 'User', 'Settings',
......@@ -25,11 +24,11 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva
model: {
setupToken: null,
currentUser: null,
siteSettings: null,
appContext: 'none'
},
init: function() {
console.log(window.MetabaseBootstrap);
if (!initPromise) {
// hackery to allow MetabaseCookies to tie into Angular
......@@ -51,7 +50,7 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva
// start Intercom updater
// this tells Intercom to update every 60s if we have a currently logged in user
$interval(function() {
if (service.model.currentUser && isTracking()) {
if (service.model.currentUser && MetabaseSettings.isTrackingEnabled()) {
window.Intercom('update');
}
}, 60000);
......@@ -89,12 +88,11 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva
refreshSiteSettings: function() {
var settingsRefresh = Session.properties(function(result) {
var settings = _.indexBy(result, 'key');
var settingsRefresh = Session.properties(function(settings) {
service.model.siteSettings = settings;
MetabaseSettings.setAll(settings);
MetabaseSettings.setAll(_.omit(settings, function(value, key, object) {
return (key.indexOf('$') === 0);
}));
$rootScope.$broadcast('appstate:site-settings', settings);
......@@ -187,14 +185,6 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva
}
};
function isTracking() {
var settings = service.model.siteSettings;
if (!settings) return false;
var tracking = settings['anon-tracking-enabled']['value'];
return (tracking === "true" || tracking === null);
}
function startupIntercom(user) {
window.Intercom('boot', {
app_id: "gqfmsgf1",
......@@ -237,14 +227,14 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva
});
$rootScope.$on("appstate:user", function(event, user) {
if (isTracking()) {
if (MetabaseSettings.isTrackingEnabled()) {
startupIntercom(user);
}
});
// enable / disable GA based on opt-out of anonymous tracking
$rootScope.$on("appstate:site-settings", function(event, settings) {
if (isTracking()) {
if (MetabaseSettings.isTrackingEnabled()) {
// we are doing tracking
window['ga-disable-UA-60817802-1'] = null;
......@@ -309,8 +299,7 @@ CoreServices.factory('Session', ['$resource', '$cookies', function($resource, $c
},
properties: {
url: '/api/session/properties',
method: 'GET',
isArray: true
method: 'GET'
},
forgot_password: {
url: '/api/session/forgot_password',
......
......@@ -125,7 +125,6 @@
(defendpoint GET "/properties"
"Get all global properties and their values. These are the specific `Settings` which are meant to be public."
[]
(filter #(contains? #{:site-name :anon-tracking-enabled} (:key %)) (setting/all-with-descriptions)))
(setting/public-settings))
(define-routes)
......@@ -6,6 +6,7 @@
[korma.core :as k]
[metabase.db :refer [sel del]]
[metabase.models.interface :refer :all]
[metabase.setup :as setup]
[metabase.util :as u]))
;; Settings are a fast + simple way to create a setting that can be set
......@@ -149,6 +150,19 @@
:value (k settings))))
(sort-by :key))))
(defn public-settings
"Return a simple map of key/value pairs which represent the public settings for the application."
[]
{:ga_code "UA-60817802-1"
:intercom_code "gqfmsgf1"
:password_complexity (metabase.util.password/active-password-complexity)
:setup_token (setup/token-value)
:timezones metabase.models.common/timezones
:version (metabase.config/mb-version-info)
;; all of these values are dynamic settings controlled at runtime
:anon_tracking_enabled (= "true" (get :anon-tracking-enabled))
:site_name (get :site-name)
:email_configured (not (clojure.string/blank? (get :email-smtp-host)))})
;; # IMPLEMENTATION
......
......@@ -8,34 +8,17 @@
[metabase.api.routes :as api]
(metabase.models common
[setting :as setting])
(metabase [config :as config]
[setup :as setup]
[util :as u])
[metabase.util :as u]
metabase.util.password))
(def ^:private ^:const date-format-rfc2616
"Java SimpleDateFormat representing rfc2616 style date used in http headers."
"EEE, dd MMM yyyy HH:mm:ss zzz")
(defn- index-page-vars
"Static values that we inject into the index.html page via Mustache."
[]
{:ga_code "UA-60817802-1"
:intercom_code "gqfmsgf1"
:password_complexity (metabase.util.password/active-password-complexity)
:setup_token (setup/token-value)
:timezones metabase.models.common/timezones
:version (config/mb-version-info)
;; all of these values are dynamic settings from the admin UI but we include them here for bootstrapping availability
:anon-tracking-enabled (setting/get :anon-tracking-enabled)
:-site-name (setting/get :-site-name)
:email_configured (not (clojure.string/blank? (setting/get :email-smtp-host)))})
(defn- index [request]
(-> (io/resource "frontend_client/index.html")
slurp
(stencil/render-string {:bootstrap_json (json/generate-string (index-page-vars))})
(stencil/render-string {:bootstrap_json (json/generate-string (setting/public-settings))})
resp/response
(resp/content-type "text/html")
(resp/header "Last-Modified" (u/now-with-format date-format-rfc2616))))
......
(ns metabase.setup
(:require [metabase.db :as db]
[metabase.models.user :refer [User]]))
(ns metabase.setup)
(defonce ^:private setup-token
(atom nil))
......@@ -10,12 +8,6 @@
[]
@setup-token)
(defn incomplete?
"Return `true` if a setup token exists and no `Users` exist in the DB."
[]
(and @setup-token
(not (db/exists? User))))
(defn token-match?
"Function for checking if the supplied string matches our setup token.
Returns boolean `true` if supplied token matches `@setup-token`, `false` otherwise."
......
......@@ -169,12 +169,6 @@
;; GET /session/properties
;; Check that a non-superuser can't read settings
(expect
[{:key "anon-tracking-enabled"
:description "Enable the collection of anonymous usage data in order to help Metabase improve."
:default "true"}
{:key "site-name"
:description "The name used for this instance of Metabase."
:default "Metabase"}]
(mapv #(dissoc % :value) ((user->client :rasta) :get 200 "session/properties")))
(vec (keys (metabase.models.setting/public-settings)))
(vec (keys ((user->client :rasta) :get 200 "session/properties"))))
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