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
update comments email template (#63626)
Stas Gavrylov432287f763f3
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 78871bca5c4..c90a45bb7e2 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1625,6 +1625,7 @@:api #{metabase-enterprise.comments.apimetabase-enterprise.comments.init}:uses #{api+ channeleventsmodelsrequestdiff --git a/bb.edn b/bb.ednindex 377702a742f..394e69b57f8 100644--- a/bb.edn+++ b/bb.edn@@ -160,6 +160,18 @@:requires [[mage.stats-repl :as stats-repl]]:task (stats-repl/connect (cli/parse! (current-task)))}+ notify+ {:doc "Send notification for a comment (that already exists"+ :requires [[mage.be-dev :refer [nrepl-eval]]]+ :options [["-c" "--comment-id ID" "Notify about this comment id"]+ ["-p" "--port PORT" "Port to use for the task, defaults to value in .nrepl-port"]]+ :task (let [opts (:options (cli/parse! (current-task)))+ ;; note: no quoting -> expect it to be int+ code (format "(notify-comment-id! %d)" (parse-long (:comment-id opts)))]+ (if (:port opts)+ (nrepl-eval "metabase-enterprise.comments.core" code (:port opts))+ (nrepl-eval "metabase-enterprise.comments.core" code)))}+ls {:doc "List all mage public and private tasks":examples [["./bin/mage ls" "List all tasks"]]:requires [[mage.util :as u]]diff --git a/e2e/support/helpers/api/createComment.ts b/e2e/support/helpers/api/createComment.tsindex 62c22b10b4a..9e70969abad 100644--- a/e2e/support/helpers/api/createComment.ts+++ b/e2e/support/helpers/api/createComment.ts@@ -6,6 +6,7 @@ export const createComment = ({child_target_id,parent_comment_id = null,content,+ html,}: Partial<CreateCommentRequest>): Cypress.Chainable<Cypress.Response<Comment>> => {@@ -15,5 +16,6 @@ export const createComment = ({child_target_id,parent_comment_id,content,+ html,});};diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.tsindex 57d5f46f750..c7a2d2e5c10 100644--- a/e2e/test/scenarios/documents/comments.cy.spec.ts+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts@@ -1537,6 +1537,7 @@ H.describeWithSnowplowEE("document comments", () => {},],},+ html: "<a href='#'>Robert Tableton</a>",}).then(({ body: comment }) => {H.getInbox().then((response: any) => {const emails = response.body;@@ -1871,6 +1872,7 @@ function createComment(nodeId: string,text: string,parent_comment_id: CommentId | null = null,+ html?: string,) {return H.createComment({target_type: "document",@@ -1887,6 +1889,7 @@ function createComment(},],},+ html: html ?? `<p>${text}</p>`,});}diff --git a/enterprise/backend/src/metabase_enterprise/comments/api.clj b/enterprise/backend/src/metabase_enterprise/comments/api.cljindex 2504aa9539e..3e0ef9072e5 100644--- a/enterprise/backend/src/metabase_enterprise/comments/api.clj+++ b/enterprise/backend/src/metabase_enterprise/comments/api.clj@@ -7,6 +7,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]]+ [metabase.channel.render.core :as channel.render][metabase.events.core :as events][metabase.request.core :as request][metabase.users.api :as api.user]@@ -32,11 +33,6 @@(case (t2/model entity):model/Document (str "/document/" (:id entity))))-(defn- content->str [content]- (when content- (or (:text content)- (pr-str content))))-;;; schemas(def CommentContent@@ -54,6 +50,7 @@[:target_type [:enum "document"]][:target_id ms/PositiveInt][:content CommentContent]+ [:html :string][:child_target_id {:optional true} [:maybe :string]][:parent_comment_id {:optional true} [:maybe ms/PositiveInt]]])@@ -61,6 +58,7 @@"Schema for updating a comment"[:map[:content {:optional true} CommentContent]+ [:html {:optional true} :string][:is_resolved {:optional true} :boolean]]);;; routes@@ -83,7 +81,10 @@{:emoji emoji:count (count users):users (take 10 users)})))))]- (into [] (comp (map render-reactions) (keep delete-comment)) comments)))+ (into [] (comp (map #(dissoc % :content_html))+ (map render-reactions)+ (keep delete-comment))+ comments)))(api.macros/defendpoint :get "/""Get comments for an entity"@@ -100,11 +101,53 @@(t2/hydrate :creator :reactions))]{:comments (render-comments comments)}))+(defn notify-comment!+ "Send a notification about comment"+ [{:keys [target_type target_id parent_comment_id] :as comment}+ & [{:keys [entity parent]+ ;; if you don't pass them we'll try to fetch them+ :or {entity (t2/select-one (TYPE->MODEL target_type) :id target_id)+ parent (when parent_comment_id+ (t2/select-one :model/Comment :id parent_comment_id))}}]]+ (let [clause (if parent_comment_id+ {:where [:in :id {:from [:comment]+ :select [:creator_id]+ :where [:or+ [:= :id parent_comment_id]+ [:= :parent_comment_id parent_comment_id]]}]}+ ;; TODO: when we expand to more entity types, add dispatch here if not everyone has `creator_id`+ {:where [:= :id (:creator_id entity)]})+ mentions (comment/mentions (:content comment))+ recipients (-> (t2/select-fn-set :email [:model/User :email]+ (cond-> clause+ (seq mentions) (sql.helpers/where :or [:in :id mentions])))+ (disj (:email @api/*current-user*)))+ payload {:entity_type (:target_type comment)+ :entity_title (:name entity)+ :comment_href (comment/url entity comment)+ :document_href (urlpath-for entity)+ :created_at (:created_at comment)+ :author (:common_name (:creator comment))+ :comment (:content_html comment)+ :parent_author (:common_name (:creator parent))+ :parent_comment (:content_html parent)+ :style {:color_text_dark channel.render/color-text-dark+ :color_text_light channel.render/color-text-light+ :color_text_medium channel.render/color-text-medium}}]+ (doseq [email recipients]+ (events/publish-event! :event/comment-created (assoc payload :email email)))))++(defn notify-comment-id!+ "Send a notification using only comment id"+ [comment-id]+ (notify-comment! (-> (t2/select-one :model/Comment :id comment-id)+ (t2/hydrate :creator :reactions))))+(api.macros/defendpoint :post "/""Create a new comment"[_route-params_query-params- {:keys [target_type target_id child_target_id parent_comment_id content]} :- CreateComment]+ {:keys [target_type target_id child_target_id parent_comment_id content html]} :- CreateComment](let [entity (-> (api/read-check (TYPE->MODEL target_type) target_id)(u/prog1 (api/check-400 (not (entity-archived? <>))"Cannot comment on archived entities")))@@ -122,41 +165,19 @@:child_target_id child_target_id:parent_comment_id parent_comment_id:content content+ :content_html html:creator_id api/*current-user-id*})(t2/hydrate :creator);; New comments always have empty reactions map- (assoc :reactions []))- clause (if parent_comment_id- {:where [:in :id {:from [:comment]- :select [:creator_id]- :where [:or- [:= :id parent_comment_id]- [:= :parent_comment_id parent_comment_id]]}]}- ;; FIXME: add dispatch on different entity types- {:where [:= :id (:creator_id entity)]})- mentions (comment/mentions content)- recipients (-> (t2/select-fn-set :email [:model/User :email]- (cond-> clause- (seq mentions) (sql.helpers/where :or [:in :id mentions])))- (disj (:email @api/*current-user*)))- payload {:entity_type target_type- :entity_title (:name entity)- :comment_href (comment/url entity comment)- :document_href (urlpath-for entity)- :created_at (:created_at comment)- :author (:common_name (:creator comment))- :comment (content->str (:content comment))- :parent_author (:common_name (:creator parent))- :parent_comment (content->str (:content parent))}]- (doseq [email recipients]- (events/publish-event! :event/comment-created (assoc payload :email email)))+ (assoc :reactions []))]+ (notify-comment! comment {:entity entity :parent parent})comment))(api.macros/defendpoint :put "/:comment-id""Update a comment"[{:keys [comment-id]} :- [:map [:comment-id ms/PositiveInt]]_query-params- {:keys [content is_resolved]} :- UpdateComment]+ {:keys [content html is_resolved]} :- UpdateComment](let [comment (api/check-404 (t2/select-one :model/Comment :id comment-id))entity (-> (api/read-check (TYPE->MODEL (:target_type comment)) (:target_id comment))(u/prog1 (api/check-400 (not (entity-archived? <>))@@ -174,7 +195,7 @@;; Anyone with write permission to target entity can resolve/unresolve(api/write-check entity))- (when-let [updates (-> {:content content :is_resolved is_resolved}+ (when-let [updates (-> {:content content :html html :is_resolved is_resolved}u/remove-nilsnot-empty)](t2/update! :model/Comment comment-id updates))diff --git a/enterprise/backend/src/metabase_enterprise/comments/core.clj b/enterprise/backend/src/metabase_enterprise/comments/core.cljnew file mode 100644index 00000000000..a9e26b9d627--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/comments/core.clj@@ -0,0 +1,8 @@+(ns metabase-enterprise.comments.core+ (:require+ [metabase-enterprise.comments.api :as api.comments]+ [potemkin :as p]))++(p/import-vars+ [api.comments+ notify-comment-id!])diff --git a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj b/enterprise/backend/test/metabase_enterprise/comments/api_test.cljindex 7eaf1fded8c..c59accdf8fb 100644--- a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/comments/api_test.clj@@ -82,12 +82,14 @@:target_type "document":target_id doc-id))))(testing "creates and returns comments for entity"- (let [created (mt/user-http-request :rasta :post 200 "ee/comment/"+ (let [content (tiptap [:p "New comment"])+ created (mt/user-http-request :rasta :post 200 "ee/comment/"{:target_type "document":target_id doc-id- :content {:text "New comment"}})+ :content content+ :html "<p>New comment</p>"})expected1 {:id int?- :content {:text "New comment"}+ :content content:target_type "document":target_id doc-id:creator {:id (mt/user->id :rasta)}@@ -108,13 +110,15 @@(first (swap-vals! mt/inbox empty)))))(testing "creates a reply to an existing comment"- (let [child (mt/user-http-request :crowberto :post 200 "ee/comment/"+ (let [content2 (tiptap [:p "Other comment"])+ child (mt/user-http-request :crowberto :post 200 "ee/comment/"{:target_type "document":target_id doc-id:parent_comment_id (:id created)- :content {:text "Other comment"}})+ :content content2+ :html "<p>Other comment</p>"})expected2 {:id int?- :content {:text "Other comment"}+ :content content2:target_type "document":target_id doc-id:creator {:id (mt/user->id :crowberto)}@@ -137,7 +141,8 @@{:target_type "document":target_id doc-id:parent_comment_id (:id created)- :content {:text "Third comment in a thread"}})]+ :content (tiptap [:p "Third comment in a thread"])+ :html "<p>Third comment in a thread</p>"})](is (=? {(:email (mt/fetch-user :rasta))[{:subject "Comment on New Document":body [{:content (relaxed-re@@ -154,9 +159,10 @@{:target_type "document":target_id doc-id:child_target_id part-id- :content {:text "Part comment"}})]+ :content (tiptap [:p "Part comment"])+ :html "<p>Part comment</p>"})](is (=? {:id int?- :content {:text "Part comment"}+ :content {:type "doc"}:target_type "document":target_id doc-id:child_target_id part-id@@ -178,7 +184,8 @@:target_id doc-id:content (tiptap[:smartLink {:model "user"- :entityId (mt/user->id :crowberto)}])})]+ :entityId (mt/user->id :crowberto)}])+ :html "<p>Mention of @crowberto :)</p>"})](is (=? {(:email (mt/fetch-user :lucky)) [{:subject "Comment on New Document"}](:email (mt/fetch-user :crowberto)) [{:subject "Comment on New Document"}]}(first (swap-vals! mt/inbox empty)))))))))))@@ -259,7 +266,7 @@(mt/with-non-admin-groups-no-root-collection-perms(mt/with-temp [:model/Collection {restricted-col :id} {:name "Restricted Collection"}:model/Document {restricted-doc-id :id} {:collection_id restricted-col- :name "Restricted Document"}+ :name "Restricted Document"}:model/Comment {restricted-comment-id :id} {:target_id restricted-doc-id}](mt/with-model-cleanup [:model/Comment]@@ -274,7 +281,8 @@(mt/user-http-request :lucky :post 403 "ee/comment/"{:target_type "document":target_id restricted-doc-id- :content {:text "Comment by lucky"}}))))+ :content (tiptap "Comment by lucky")+ :html "You shall not pass"}))))(testing "PUT /api/ee/comment/:id - users without document access cannot update comments"(is (= "You don't have permissions to do that."diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx b/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsxindex f4aa8e85915..fdb47410e2f 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx+++ b/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx@@ -43,7 +43,7 @@ interface Props {readonly?: boolean;onBlur?: (content: DocumentContent, editor: Editor) => void;onChange?: (content: DocumentContent) => void;- onSubmit?: (content: DocumentContent) => void;+ onSubmit?: (content: DocumentContent, html: string) => void;onEscape?: () => void;}@@ -147,8 +147,10 @@ export const CommentEditor = ({const content = editor.getJSON() as DocumentContent;const isEmpty = editor.isEmpty;+ const html = stripInternalIds(editor.getHTML());+if (!isEmpty && onSubmit) {- onSubmit(content);+ onSubmit(content, html);editor.commands.clearContent(true);editor.commands.blur();}@@ -210,3 +212,11 @@ export const CommentEditor = ({</Flex>);};++function stripInternalIds(html: string): string {+ const parser = new DOMParser();+ const doc = parser.parseFromString(html, "text/html");+ const elements = doc.body.querySelectorAll("[_id]");+ elements.forEach((el) => el.removeAttribute("_id"));+ return doc.body.innerHTML;+}diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsx b/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsxindex e10047982dc..7213d576083 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsx+++ b/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsx@@ -52,13 +52,14 @@ export const Discussion = ({const [deleteComment] = useDeleteCommentMutation();const [toggleReaction] = useToggleReactionMutation();- const handleSubmit = async (doc: DocumentContent) => {+ const handleSubmit = async (doc: DocumentContent, html: string) => {const { error } = await createComment({child_target_id: effectiveChildTargetId,target_id: targetId,target_type: targetType,content: doc,parent_comment_id: parentCommentId,+ html,});if (error) {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsxindex 88db278a12d..5afbae28a58 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx@@ -159,7 +159,7 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {}});- const handleSubmit = async (doc: DocumentContent) => {+ const handleSubmit = async (doc: DocumentContent, html: string) => {if (!childTargetId || !document) {return;}@@ -170,6 +170,7 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {target_type: "document",content: doc,parent_comment_id: null,+ html,});if (error) {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsxindex 5777e1088ee..8d8b184d02a 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsx+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsx@@ -28,6 +28,7 @@ export interface MenuItem {action: () => void;model?: SuggestionModel;id?: number | string;+ href?: string;}export const MenuItemComponent = ({diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.tsindex 97236eeb369..404b5ae71d0 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts@@ -22,6 +22,8 @@ export interface CommandProps {embedItem?: boolean;entityId?: number | string;model?: string;+ label?: string;+ href?: string;document?: Document | null;}@@ -189,6 +191,8 @@ export const CommandExtension = Extension.create<CommandOptions>({attrs: {entityId: props.entityId,model: props.model,+ label: props.label,+ href: props.href,},}).run();diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.tsindex 5fab0ca0529..ec893eb5162 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts@@ -21,6 +21,7 @@ export interface MentionCommandProps {model?: string;document?: Document | null;label?: string;+ href?: string | null;}export const MentionPluginKey = new PluginKey("mention");@@ -59,8 +60,10 @@ export const MentionExtension = Extension.create<MentionOptions>({entityId: props.id,model: props.model,label: props.label,+ href: props.href,},})+ .insertContent(" ").run();if (props.document) {trackDocumentAddSmartLink(props.document);diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsxindex 2e5769a14a6..1e3e331c4fd 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx@@ -38,11 +38,17 @@ const MentionSuggestionComponent = forwardRef<) {const document = useSelector(getCurrentDocument);const onSelectEntity = useCallback(- (item: { id: number | string; model: string; label?: string }) => {+ (item: {+ id: number | string;+ model: string;+ label?: string;+ href?: string | null;+ }) => {command({id: item.id,model: item.model,label: item.label,+ href: item.href,document,});},diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxindex 880e76f72f9..f7a12151231 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx@@ -20,7 +20,7 @@ import {getIcon,} from "metabase/lib/icon";import { useDispatch } from "metabase/lib/redux";-import { type UrlableModel, modelToUrl } from "metabase/lib/urls/modelToUrl";+import { modelToUrl } from "metabase/lib/urls/modelToUrl";import { extractEntityId } from "metabase/lib/urls/utils";import { Icon } from "metabase/ui";import {@@ -39,7 +39,11 @@ import type {MentionableUser,Table,} from "metabase-types/api";-import { isObject } from "metabase-types/guards";++import {+ entityToUrlableModel,+ isMentionableUser,+} from "../shared/suggestionUtils";import styles from "./SmartLinkNode.module.css";@@ -155,6 +159,10 @@ export const SmartLink = Node.create<{default: null,parseHTML: (element) => element.getAttribute("data-label"),},+ href: {+ default: "/",+ parseHTML: (element) => element.getAttribute("data-href"),+ },};},@@ -170,22 +178,25 @@ export const SmartLink = Node.create<{];},- renderHTML({ node, HTMLAttributes }) {- const { entityId, model } = node.attrs;+ renderHTML({ node }) {+ const { entityId, model, label, href } = node.attrs;return [- "span",+ "a",mergeAttributes(- HTMLAttributes,{"data-type": "smart-link","data-entity-id": entityId,"data-model": model,- "data-label": node.attrs.label ?? undefined,+ "data-label": label ?? undefined,+ "data-site-url": this.options.siteUrl,+ href: this.options.siteUrl + href ?? "",+ style: "text-decoration: none;",},this.options.HTMLAttributes,),- `{% entity id="${entityId}" model="${model}" %}`,+ // 0 is Tiptap’s “content placeholder,” which tells it to render the node’s inner content.+ label ?? 0,];},@@ -406,29 +417,6 @@ export const SmartLinkComponent = memo(SmartLinkComponent.displayName = "SmartLinkComponent";-function entityToUrlableModel(- entity: SmartLinkEntity,- model: SuggestionModel | null,-): UrlableModel {- const result: UrlableModel = {- id: entity.id as number, // it is string | number in reality, but then gets casted to a string in "modelToUrl"- model: (entity as Dashboard).model || model || "",- name: isMentionableUser(entity) ? entity.common_name : entity.name,- };-- if ("db_id" in entity && entity.db_id) {- result.database = {- id: entity.db_id,- };- }-- if ("database_id" in entity && entity.database_id) {- result.database = { id: entity.database_id };- }-- return result;-}-function entityToObjectWithModel(entity: SmartLinkEntity,model: SuggestionModel | null,@@ -439,7 +427,3 @@ function entityToObjectWithModel(is_personal: (entity as Collection).is_personal,};}--function isMentionableUser(value: unknown): value is MentionableUser {- return isObject(value) && typeof value.common_name === "string";-}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.tsindex f6fb2c35849..cdeb3e5b112 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts@@ -1,5 +1,6 @@import { getIcon } from "metabase/lib/icon";import { getName } from "metabase/lib/name";+import type { UrlableModel } from "metabase/lib/urls/modelToUrl";import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";import type { SuggestionModel } from "metabase-enterprise/documents/components/Editor/types";import type {@@ -8,6 +9,7 @@ import type {RecentItem,SearchResult,} from "metabase-types/api";+import { isObject } from "metabase-types/guards";export const filterRecents = (item: RecentItem, models: SuggestionModel[]) =>models.includes(item.model);@@ -77,3 +79,37 @@ export function buildUserMenuItems(};});}++export function entityToUrlableModel<+ T extends {+ id: string | number;+ name?: string;+ common_name?: string;+ db_id?: number;+ database_id?: number;+ },+>(entity: T, model: SuggestionModel | null): UrlableModel {+ const result: UrlableModel = {+ id: entity.id as number, // it is string | number in reality, but then gets casted to a string in "modelToUrl"+ model: model || "",+ name: isMentionableUser(entity)+ ? entity.common_name+ : (entity.name as string),+ };++ if ("db_id" in entity && entity.db_id) {+ result.database = {+ id: entity.db_id,+ };+ }++ if ("database_id" in entity && entity.database_id) {+ result.database = { id: entity.database_id };+ }++ return result;+}++export function isMentionableUser(value: unknown): value is MentionableUser {+ return isObject(value) && typeof value.common_name === "string";+}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.tsindex add783c3d27..488bddcd157 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.ts@@ -2,6 +2,7 @@ import type { Editor } from "@tiptap/core";import { useCallback, useEffect, useState } from "react";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";+import { modelToUrl } from "metabase/lib/urls/modelToUrl";import type { SuggestionModel } from "metabase-enterprise/documents/components/Editor/types";import type {MentionableUser,@@ -9,6 +10,7 @@ import type {SearchResult,} from "metabase-types/api";+import { entityToUrlableModel } from "./suggestionUtils";import { useEntitySearch } from "./useEntitySearch";interface UseEntitySuggestionsOptions {@@ -18,6 +20,7 @@ interface UseEntitySuggestionsOptions {id: number | string;model: string;label?: string;+ href: string | null;}) => void;enabled?: boolean;searchModels?: SuggestionModel[];@@ -59,6 +62,7 @@ export function useEntitySuggestions({id: item.id,model: item.model,label: "display_name" in item ? item.display_name : item.name,+ href: modelToUrl(entityToUrlableModel(item, item.model)),});},[onSelectEntity],@@ -70,6 +74,7 @@ export function useEntitySuggestions({id: item.id,model: item.model,label: item.name,+ href: modelToUrl(entityToUrlableModel(item, item.model)),});},[onSelectEntity],@@ -81,6 +86,7 @@ export function useEntitySuggestions({id: item.id,model: "user",label: item.common_name,+ href: modelToUrl(entityToUrlableModel(item, "user")),});},[onSelectEntity],@@ -153,6 +159,8 @@ export function useEntitySuggestions({onSelectEntity({id: item.id,model: item.model,+ label: item.name,+ href: modelToUrl(entityToUrlableModel(item, item.model)),});setModal(null);},diff --git a/frontend/src/metabase-types/api/comments.ts b/frontend/src/metabase-types/api/comments.tsindex 556188f4303..276afb47efa 100644--- a/frontend/src/metabase-types/api/comments.ts+++ b/frontend/src/metabase-types/api/comments.ts@@ -53,6 +53,7 @@ export interface CreateCommentRequest {child_target_id: EntityId | null;parent_comment_id: CommentId | null;content: DocumentContent;+ html: string;}export interface UpdateCommentRequest {diff --git a/resources/migrations/057_update_migrations.yaml b/resources/migrations/057_update_migrations.yamlindex 24b903a2b7c..31a4c3d40c6 100644--- a/resources/migrations/057_update_migrations.yaml+++ b/resources/migrations/057_update_migrations.yaml@@ -512,7 +512,7 @@ databaseChangeLog:- column:name: transform_idtype: int- remarks: 'Identifier for the transform'+ remarks: "Identifier for the transform"constraints:nullable: falsereferencedTableName: transform@@ -522,39 +522,39 @@ databaseChangeLog:- column:name: run_methodtype: varchar(255)- remarks: 'Method used to execute the transform job'+ remarks: "Method used to execute the transform job"constraints:nullable: false- column:name: statustype: varchar(50)- remarks: 'Current status of the transform job (running, completed, failed, etc.)'+ remarks: "Current status of the transform job (running, completed, failed, etc.)"constraints:nullable: false- column:name: is_activetype: ${boolean.type}- remarks: 'True only for currently running jobs, null for the others'+ remarks: "True only for currently running jobs, null for the others"constraints:nullable: truedefaultValue: true- column:name: start_timetype: ${timestamp_type}- remarks: 'When the transform job started'+ remarks: "When the transform job started"defaultValueComputed: current_timestampconstraints:nullable: false- column:name: end_timetype: ${timestamp_type}- remarks: 'When the transform job completed (null if still running)'+ remarks: "When the transform job completed (null if still running)"constraints:nullable: true- column:name: messagetype: ${text.type}- remarks: 'Human-readable message about the run; may contain error message in case status is error'+ remarks: "Human-readable message about the run; may contain error message in case status is error"constraints:nullable: true@@ -648,7 +648,7 @@ databaseChangeLog:- column:name: timetype: ${timestamp_type}- remarks: 'The time of the request'+ remarks: "The time of the request"defaultValueComputed: current_timestampconstraints:nullable: false@@ -700,7 +700,7 @@ databaseChangeLog:- column:name: built_in_typetype: varchar(255)- remarks: 'Type of the built-in transform tag: hourly, daily, weekly, monthly.'+ remarks: "Type of the built-in transform tag: hourly, daily, weekly, monthly."constraints:nullable: true@@ -761,7 +761,7 @@ databaseChangeLog:- column:name: built_in_typetype: varchar(255)- remarks: 'Type of the built-in transform job: hourly, daily, weekly, monthly.'+ remarks: "Type of the built-in transform job: hourly, daily, weekly, monthly."constraints:nullable: true@@ -941,45 +941,45 @@ databaseChangeLog:- column:name: job_idtype: bigint- remarks: 'Identifier for the transform job'+ remarks: "Identifier for the transform job"constraints:nullable: false- column:name: run_methodtype: varchar(255)- remarks: 'Method used to execute the transform job'+ remarks: "Method used to execute the transform job"constraints:nullable: false- column:name: statustype: varchar(50)- remarks: 'Current status of the transform job (running, completed, failed, etc.)'+ remarks: "Current status of the transform job (running, completed, failed, etc.)"constraints:nullable: false- column:name: is_activetype: ${boolean.type}- remarks: 'True only for currently running jobs, null for the others'+ remarks: "True only for currently running jobs, null for the others"constraints:nullable: truedefaultValue: true- column:name: start_timetype: ${timestamp_type}- remarks: 'When the transform job started'+ remarks: "When the transform job started"defaultValueComputed: current_timestampconstraints:nullable: false- column:name: end_timetype: ${timestamp_type}- remarks: 'When the tranform job completed (null if still running)'+ remarks: "When the tranform job completed (null if still running)"constraints:nullable: true- column:name: messagetype: ${text.type}- remarks: 'Human-readable message about the run; may contain error message in case status is error'+ remarks: "Human-readable message about the run; may contain error message in case status is error"constraints:nullable: true- column:@@ -998,50 +998,50 @@ databaseChangeLog:nullable: false- changeSet:- id: v57.2025-08-22T00:13:00- author: ranquild- comment: Create built-in transform tags- changes:- - sql: >-- INSERT INTO transform_tag(name, entity_id, built_in_type) VALUES- ('hourly', 'wYLcUPbtF7jVPO0duGGHR', 'hourly'),- ('daily', 'dUW7nvQHQBdA0Rx0gJckI', 'daily'),- ('weekly', 'qPGCJu7t97kn-X07_fgSj', 'weekly'),- ('monthly', 'DeeJHc81qKhD9qWINISO8', 'monthly');- rollback:- - sql: DELETE FROM transform_tag WHERE built_in_type IS NOT NULL;+ id: v57.2025-08-22T00:13:00+ author: ranquild+ comment: Create built-in transform tags+ changes:+ - sql: >-+ INSERT INTO transform_tag(name, entity_id, built_in_type) VALUES+ ('hourly', 'wYLcUPbtF7jVPO0duGGHR', 'hourly'),+ ('daily', 'dUW7nvQHQBdA0Rx0gJckI', 'daily'),+ ('weekly', 'qPGCJu7t97kn-X07_fgSj', 'weekly'),+ ('monthly', 'DeeJHc81qKhD9qWINISO8', 'monthly');+ rollback:+ - sql: DELETE FROM transform_tag WHERE built_in_type IS NOT NULL;- changeSet:- id: v57.2025-08-22T00:14:00- author: ranquild- comment: Create built-in transform jobs- changes:- - sql: >-- INSERT INTO transform_job(name, description, schedule, entity_id, built_in_type) VALUES- ('Hourly job', 'Executes transforms tagged with ''hourly'' every hour', '0 0 * * * ? *', 'RognTgBT2fXaxoQh4ws7z', 'hourly'),- ('Daily job', 'Executes transforms tagged with ''daily'' once per day', '0 0 0 * * ? *', 'PJahvcoF61oX5T4uCT_FY', 'daily'),- ('Weekly job', 'Executes transforms tagged with ''weekly'' once per week', '0 0 0 ? * 1 *', 'lXIFa2SUrXLgaLZJx33oU', 'weekly'),- ('Monthly job', 'Executes transforms tagged with ''monthly'' once per month', '0 0 0 1 * ? *', 'CL1TVitmzJrDjdjvO2xmN', 'monthly');- rollback:- - sql: DELETE FROM transform_job WHERE built_in_type IS NOT NULL;+ id: v57.2025-08-22T00:14:00+ author: ranquild+ comment: Create built-in transform jobs+ changes:+ - sql: >-+ INSERT INTO transform_job(name, description, schedule, entity_id, built_in_type) VALUES+ ('Hourly job', 'Executes transforms tagged with ''hourly'' every hour', '0 0 * * * ? *', 'RognTgBT2fXaxoQh4ws7z', 'hourly'),+ ('Daily job', 'Executes transforms tagged with ''daily'' once per day', '0 0 0 * * ? *', 'PJahvcoF61oX5T4uCT_FY', 'daily'),+ ('Weekly job', 'Executes transforms tagged with ''weekly'' once per week', '0 0 0 ? * 1 *', 'lXIFa2SUrXLgaLZJx33oU', 'weekly'),+ ('Monthly job', 'Executes transforms tagged with ''monthly'' once per month', '0 0 0 1 * ? *', 'CL1TVitmzJrDjdjvO2xmN', 'monthly');+ rollback:+ - sql: DELETE FROM transform_job WHERE built_in_type IS NOT NULL;- changeSet:- id: v57.2025-08-22T00:15:00- author: ranquild- comment: Create associations between built-in transform jobs and tags- changes:- - sql: >-- INSERT INTO transform_job_transform_tag(job_id, tag_id, entity_id, position)- SELECT job.id, tag.id, job.entity_id, 0 AS position- FROM transform_job AS job- JOIN transform_tag AS tag ON job.built_in_type = tag.built_in_type- WHERE job.built_in_type IS NOT NULL AND tag.built_in_type IS NOT NULL;- rollback:- - sql: >-- DELETE FROM transform_job_transform_tag- WHERE- job_id IN (SELECT id FROM transform_job WHERE built_in_type IS NOT NULL) AND- tag_id IN (SELECT id FROM transform_tag WHERE built_in_type IS NOT NULL);+ id: v57.2025-08-22T00:15:00+ author: ranquild+ comment: Create associations between built-in transform jobs and tags+ changes:+ - sql: >-+ INSERT INTO transform_job_transform_tag(job_id, tag_id, entity_id, position)+ SELECT job.id, tag.id, job.entity_id, 0 AS position+ FROM transform_job AS job+ JOIN transform_tag AS tag ON job.built_in_type = tag.built_in_type+ WHERE job.built_in_type IS NOT NULL AND tag.built_in_type IS NOT NULL;+ rollback:+ - sql: >-+ DELETE FROM transform_job_transform_tag+ WHERE+ job_id IN (SELECT id FROM transform_job WHERE built_in_type IS NOT NULL) AND+ tag_id IN (SELECT id FROM transform_tag WHERE built_in_type IS NOT NULL);- changeSet:id: v57.2025-08-22T00:15:01@@ -1085,7 +1085,7 @@ databaseChangeLog:name: data_authorityremarks: Indicates the data authority status - unconfigured, authoritative, computed, or ingestedtype: varchar(20)- defaultValue: 'unconfigured'+ defaultValue: "unconfigured"constraints:nullable: false@@ -1444,6 +1444,27 @@ databaseChangeLog:constraints:nullable: false+ - changeSet:+ id: v57.2025-09-16T12:55:00+ author: stasgavrylov+ comment: Add content_html column to comment table for storing HTML-rendered content+ preConditions:+ - onFail: MARK_RAN+ - not:+ - columnExists:+ tableName: comment+ columnName: content_html+ changes:+ - addColumn:+ tableName: comment+ columns:+ - column:+ name: content_html+ type: ${text.type}+ remarks: HTML-rendered version of the comment content+ constraints:+ nullable: true+- changeSet:id: v57.2025-09-19T11:30:20author: ranquilddiff --git a/src/metabase/channel/email/_dashsub_alert_header.hbs b/src/metabase/channel/email/_dashsub_alert_header.hbsindex ec4fc1e6da9..275553b7e77 100644--- a/src/metabase/channel/email/_dashsub_alert_header.hbs+++ b/src/metabase/channel/email/_dashsub_alert_header.hbs@@ -31,6 +31,29 @@text-decoration: underline;}+ {{!-- Scoped reset for injected HTML blocks (e.g., rich-text comments) --}}+ .comment-row p {+ margin-top: 0;+ margin-bottom: 0;+ }++ .comment-row ul, .comment-row ol {+ margin-top: 0.5rem;+ margin-bottom: 0.5rem;+ padding-left: 1.5rem;+ }++ .comment-row pre {+ margin-top: 0;+ margin-bottom: 0;+ }++ .comment-row blockquote {+ margin-top: 0.5rem;+ margin-bottom: 0.5rem;+ margin-left: 1.5rem;+ }+{{!-- Formatting for header elements of Markdown cards --}}h1, h2, h3, h4, h5, h6 {color: {{payload.style.color_text_dark}};diff --git a/src/metabase/channel/email/comment_created.hbs b/src/metabase/channel/email/comment_created.hbsindex 7fe86e86814..5fb5038c241 100644--- a/src/metabase/channel/email/comment_created.hbs+++ b/src/metabase/channel/email/comment_created.hbs@@ -8,7 +8,7 @@<img width="35.55" height="45" src="{{context.application_logo_url}}" alt="Metabase logo"/></div>- <h1 style="text-align: center; font-size: 27px; line-height: 36px; font-weight: 400; margin: 0 0 12px 0; color: {{payload.style.color_text_dark}};">+ <h1 style="text-align: center; font-size: 27px; line-height: 36px; font-weight: 400; margin: 0 0 8px 0; color: #2F3C45;">{{#if payload.event_info.parent_comment}}{{payload.event_info.author}} replied to a thread{{else}}@@ -27,15 +27,45 @@</a></div>+ {{!-- Comment block --}}+ <div style="background-color: #FAFAFB; border-radius: 12px; padding: 24px; margin: 0 auto 32px auto;">+ <table role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;">+ {{#if payload.event_info.parent_comment}}+ <tr style="opacity: 0.5;" class="comment-row">+ <td width="40" valign="top" style="padding-right: 16px;">+ <div style="width: 36px; height: 36px; border-radius: 50%; background: #A989C5; color: #ffffff; font-weight: 700; font-size: 12px; line-height: 36px; text-align: center; text-transform: uppercase; overflow: hidden;">+ {{initials payload.event_info.parent_author}}+ </div>+ </td>+ <td valign="top" style="padding-bottom: 24px;">+ <div style="font-weight: 700; font-size: 0.875rem; color: #656F76; margin-bottom: 6px; padding-top: 9px;">{{payload.event_info.parent_author}}</div>+ <div style="font-size: 0.875rem; color: #656F76; line-height: 20px;">{{{payload.event_info.parent_comment}}}</div>+ </td>+ </tr>+ {{/if}}+ <tr class="comment-row">+ <td width="40" valign="top" style="padding-right: 16px;">+ <div style="width: 36px; height: 36px; border-radius: 50%; background: #A6CF57; color: #ffffff; font-weight: 700; font-size: 12px; line-height: 36px; text-align: center; text-transform: uppercase; overflow: hidden;">+ {{initials payload.event_info.author}}+ </div>+ </td>+ <td valign="top">+ <div style="font-weight: 700; font-size: 0.875rem; color: #2F3C45; margin-bottom: 6px; padding-top: 9px;">{{payload.event_info.author}}</div>+ <div style="font-size: 0.875rem; color: #2F3C45; line-height: 20px;">{{{payload.event_info.comment}}}</div>+ </td>+ </tr>+ </table>+ </div>+{{!-- CTA button --}}<div style="text-align: center; margin: 12px 0 32px 0;"><a href="{{context.site_url}}{{payload.event_info.comment_href}}"- style="display: inline-block; background-color: {{context.application_color}}; color: #ffffff !important; font-weight: 700; font-size: 14px; border-radius: 8px; padding: 12px 16px;">+ style="display: inline-block; background-color: {{context.application_color}}; color: #ffffff !important; font-weight: 700; font-size: 14px; border-radius: 8px; padding: 12px 16px; text-decoration: none;">Open in Metabase</a></div><hr style="margin-top: 32px; margin-bottom: 32px;">- <div class="footer" style="font-size: 12px; line-height: 16px; width: max-content; margin: 0 auto; color: {{payload.style.color_text_medium}};">+ <div style="font-size: 12px; line-height: 16px; width: max-content; margin: 0 auto; color: #656F76; text-align: center;">Sent from <a href="{{context.site_url}}" style="color: {{context.application_color}}">{{context.site_url}}</a>.</div></div>