Utility functions for generating the frontend URLs that correspond various user-facing Metabase objects, like Cards or Dashboards. This is intended as the central place for all such URL-generation activity, so if frontend routes change, only this file need be changed on the backend. Functions for generating URLs not related to Metabase objects generally do not belong here, unless they are used in many places in the codebase; one-off URL-generation functions should go in the same namespaces or modules where they are used. | (ns metabase.util.urls (:require [clojure.string :as str] [metabase.models.params.shared :as shared.params] [metabase.public-settings :as public-settings] [ring.util.codec :as codec])) |
Return the Notification Link Base URL if set by enterprise env var, or Site URL. | (defn site-url [] (or (public-settings/notification-link-base-url) (public-settings/site-url))) |
Return an appropriate URL to view the archive page. | (defn archive-url [] (str (site-url) "/archive")) |
Return an appropriate URL for a (dashboard-url 10) -> "http://localhost:3000/dashboard/10" | (defn dashboard-url ([^Integer id] (format "%s/dashboard/%d" (site-url) id)) ([^Integer id parameters] (let [base-url (dashboard-url id) url-params (flatten (for [param parameters :let [values (shared.params/param-val-or-default param)]] (for [value (if ((some-fn sequential? set? nil?) values) values [values])] (str (codec/url-encode (:slug param)) "=" (codec/url-encode value)))))] (str base-url (when (seq url-params) (str "?" (str/join "&" url-params))))))) |
Return an appropriate URL for a (card-url 10) -> "http://localhost:3000/question/10" | (defn card-url [^Integer id] (format "%s/question/%d" (site-url) id)) |
Return an appropriate URL for a legacy (legacy-pulse-url 10) -> "http://localhost:3000/pulse/10" | (defn legacy-pulse-url [^Integer id] (format "%s/pulse/%d" (site-url) id)) |
Returns an appropriate URL to view a database. (database-url 4) -> "http://localhost:3000/browse/4" | (defn database-url [^Integer db-id] (format "%s/browse/%d" (site-url) db-id)) |
Returns an appropriate URL to view a table. (table-url 1 10) -> "http://localhost:3000/question?db=1&table=10" | (defn table-url [^Integer db-id ^Integer table-id] (format "%s/question?db=%d&table=%d" (site-url) db-id table-id)) |
URL prefix for a public Cards. Get the complete URL by adding the UUID to the end. | (defn public-card-prefix [] (str (site-url) "/public/question/")) |
URL prefix for a public Dashboards. Get the complete URL by adding the UUID to the end. | (defn public-dashboard-prefix [] (str (site-url) "/public/dashboard/")) |
URL for the notification management page in account settings. | (defn notification-management-url [] (str (site-url) "/account/notifications")) |
URL for nonusers to unsubscribe from alerts | (defn unsubscribe-url [] (str (site-url) "/unsubscribe")) |
Return an appropriate URL for a | (defn collection-url [collection-id-or-nil] (format "%s/collection/%s" (site-url) (or collection-id-or-nil "root"))) |
Return an appropriate URL for linking to caching log details. | (defn tools-caching-details-url [^Integer persisted-info-id] (format "%s/admin/tools/model-caching/%d" (site-url) persisted-info-id)) |