The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Call utils/slugify from mc.c.m.collection with a map as the second arg. (#72130)
technomancye38aad4c929a
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex 8f6cec1df3f..8cd438cb7ee 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -281,7 +281,7 @@(when (str/blank? collection-name)(throw (ex-info (tru "Collection name cannot be blank!"){:status-code 400, :errors {:name (tru "cannot be blank")}})))- (u/slugify collection-name collection-slug-max-length))+ (u/slugify collection-name {:max-length collection-slug-max-length}));;; +----------------------------------------------------------------------------------------------------------------+;;; | Nested Collections: Location Paths |diff --git a/src/metabase/models/serialization.clj b/src/metabase/models/serialization.cljindex fe418849859..21afea472fb 100644--- a/src/metabase/models/serialization.clj+++ b/src/metabase/models/serialization.clj@@ -337,7 +337,9 @@(defmethod generate-path :default [model-name entity];; This default works for most models, but needs overriding for those that don't rely on entity_id.- (maybe-labeled model-name entity :name))+ (maybe-labeled model-name entity #(if (string? (:name %))+ (:name %)+ (:format-string (:name %)))))(defn log-path-str"Returns a string for logging from a serdes path sequence (i.e. in :serdes/meta)"diff --git a/src/metabase/util.cljc b/src/metabase/util.cljcindex 26a0b52a24f..a1a144a6ab3 100644--- a/src/metabase/util.cljc+++ b/src/metabase/util.cljc@@ -26,6 +26,7 @@[metabase.util.format :as u.format][metabase.util.i18n :refer [tru]][metabase.util.log :as log]+ [metabase.util.malli :as mu][metabase.util.memoize :as memoize][metabase.util.namespaces :as u.ns][metabase.util.number :as u.number]@@ -525,7 +526,7 @@:cljs (js/encodeURIComponent c))c)))-(defn slugify+(mu/defn slugify"Return a version of String `s` appropriate for use as a URL slug.Downcase the name and remove diacritcal marks, and replace non-alphanumeric *ASCII* characters with underscores.@@ -537,7 +538,12 @@Optionally specify `:max-length` which will truncate the slug after that many characters."(^String [^String s](slugify s {}))- (^String [s {:keys [max-length unicode?]}]+ (^String [s :- [:maybe :string]+ {:keys [max-length unicode?]} :- [:maybe+ [:map+ {:closed true}+ [:max-length {:optional true} pos-int?]+ [:unicode? {:optional true} [:maybe boolean?]]]]](when (seq s)(cond->> (remove-diacritical-marks (lower-case-en s))true (map #(slugify-char % (not unicode?)))diff --git a/src/metabase/util/malli/defn.clj b/src/metabase/util/malli/defn.cljindex 55fa813629b..d38474904dd 100644--- a/src/metabase/util/malli/defn.clj+++ b/src/metabase/util/malli/defn.clj@@ -4,7 +4,7 @@[clojure.core :as core][clojure.string :as str][malli.destructure]- [metabase.util :as u]+ [me.flowthing.pp :as pp][metabase.util.malli.fn :as mu.fn][net.cgrand.macrovich :as macros]))@@ -53,7 +53,10 @@(map (comp pr-str :args :values)(:arities arities-value)))")"))- "\n Return: " (str/replace (u/pprint-to-str (:schema (:values return) :any))+ "\n Return: " (str/replace (with-out-str+ #_{:clj-kondo/ignore [:discouraged-var]}+ (pp/pprint (:schema (:values return) :any)+ {:max-width 120}))"\n""\n ")(when (not-empty doc)diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.cljindex c99025ee8cb..081af6520e1 100644--- a/test/metabase/collections/models/collection_test.clj+++ b/test/metabase/collections/models/collection_test.clj@@ -39,11 +39,11 @@(deftest format-personal-collection-name-length-test(testing "test that an unrealistically long collection name with unicode letters is still less than the max length for a slug (metabase#33917)"(mt/with-temporary-setting-values [site-locale "ru"]- (is (< (count (#'collection/slugify (collection/format-personal-collection-name (apply str (repeat 34 "Б"))- (apply str (repeat 35 "Б"))- :site)))- (var-get #'collection/collection-slug-max-length))))))+ (is (<= (count (#'collection/slugify (collection/format-personal-collection-name (apply str (repeat 256 "Б"))+ (apply str (repeat 256 "Б"))+ :site)))+ (var-get #'collection/collection-slug-max-length))))))(deftest user->personal-collection-name-test(testing "test that we can get the name of a user's personal collection as :site"