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
Show table publisher and publish date in the Library (#81076)
Andersone354134858e4
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 88b24b589af..71a3f08720f 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -3266,10 +3266,12 @@permissionspremium-featuresutil}- :model-imports #{:model/Collection+ :model-imports #{:model/AuditLog+ :model/Collection:model/Dimension:model/Field- :model/Table}}+ :model/Table+ :model/User}}enterprise/database-replication{:team "Cloud"diff --git a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.cljindex a94802c5ac3..2a776a2fb2d 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj@@ -118,6 +118,39 @@[:map[:target_collection [:maybe (ms/InstanceOf :model/Collection)]]])+(def ^:private PublishingUser+ [:map {:closed true}+ [:id ms/PositiveInt]+ [:common_name :string]])++(def ^:private PublishingInfo+ [:map {:closed true}+ [:published_at ms/TemporalInstant]+ [:published_by [:maybe PublishingUser]]])++(defn- publishing-info+ [table-id]+ (when-let [{:keys [timestamp topic], user-id :user_id}+ ;; Serialization can restore `is_published` without a publish event, so a later unpublish+ ;; invalidates older publishing details.+ (data-studio.db/latest-table-publishing-event table-id)]+ (when (= topic :table-publish)+ {:published_at timestamp+ :published_by (when user-id+ (some-> (data-studio.db/user-name-and-email user-id)+ (select-keys [:id :common_name])))})))++(api.macros/defendpoint :get "/:id/publishing-info" :- [:maybe PublishingInfo]+ "Return the latest valid publishing information for a published table, or no content when unavailable."+ [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ _query-params+ _body+ _request]+ (api/check-data-analyst)+ (let [table (api/read-check :model/Table id)]+ (when (:is_published table)+ (publishing-info id))))+(defn- can-publish?"Publishing a table means that it's now query-able by a new set of people. So we should not allow you to publish atable if you don't *already* have permissions to query it - otherwise, maybe you can just publish it to circumvent yourdiff --git a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj b/enterprise/backend/src/metabase_enterprise/data_studio/db.cljindex 22ce0ba01fc..2362eb4ffcc 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/db.clj@@ -75,6 +75,20 @@[collection-id](t2/select-one :model/Collection collection-id))+(defn latest-table-publishing-event+ "The most recent publish or unpublish AuditLog event for `table-id`, or nil."+ [table-id]+ (t2/select-one [:model/AuditLog :timestamp :topic :user_id]+ :topic [:in [:table-publish :table-unpublish]]+ :model "Table"+ :model_id table-id+ {:order-by [[:timestamp :desc] [:id :desc]]}))++(defn user-name-and-email+ "The id, first name, last name, and email of the User with `user-id`, or nil."+ [user-id]+ (t2/select-one [:model/User :id :first_name :last_name :email] user-id))+(defn publish-tables!"Publish the Tables with `table-ids` into the Collection with `collection-id`."[table-ids collection-id]diff --git a/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj b/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.cljindex dbffba0f410..9a012c96ead 100644--- a/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj+++ b/enterprise/backend/test/metabase_enterprise/data_studio/api/table_test.clj@@ -101,6 +101,50 @@:is_published true}(t2/select-one :model/Table (mt/id :users)))))))))+(deftest publishing-info-test+ (mt/with-premium-features #{:library :audit-app}+ (let [older-timestamp (t/offset-date-time "2026-08-25T12:00:00Z")+ newer-timestamp (t/offset-date-time "2026-08-26T12:00:00Z")]+ (mt/with-temp [:model/Table {table-id :id} {:is_published true}+ :model/AuditLog _ {:topic :table-publish+ :model "Table"+ :model_id table-id+ :user_id (mt/user->id :rasta)+ :timestamp older-timestamp}+ :model/AuditLog _ {:topic :table-publish+ :model "Table"+ :model_id table-id+ :user_id (mt/user->id :crowberto)+ :timestamp newer-timestamp}]+ (testing "returns the latest publishing event"+ (is (=? {:published_at "2026-08-26T12:00:00Z"+ :published_by {:id (mt/user->id :crowberto)+ :common_name "Crowberto Corv"}}+ (mt/user-http-request :crowberto :get 200+ (format "ee/data-studio/table/%d/publishing-info" table-id))))))+ (testing "returns no content when there is no publishing event"+ (mt/with-temp [:model/Table {table-id :id} {:is_published true}]+ (is (nil? (mt/user-http-request :crowberto :get 204+ (format "ee/data-studio/table/%d/publishing-info" table-id))))))+ (testing "returns no content when the latest lifecycle event is an unpublish"+ (mt/with-temp [:model/Table {table-id :id} {:is_published true}+ :model/AuditLog _ {:topic :table-publish+ :model "Table"+ :model_id table-id+ :user_id (mt/user->id :rasta)+ :timestamp older-timestamp}+ :model/AuditLog _ {:topic :table-unpublish+ :model "Table"+ :model_id table-id+ :user_id (mt/user->id :crowberto)+ :timestamp newer-timestamp}]+ (is (nil? (mt/user-http-request :crowberto :get 204+ (format "ee/data-studio/table/%d/publishing-info" table-id))))))+ (testing "returns no content for an unpublished table"+ (mt/with-temp [:model/Table {table-id :id} {:is_published false}]+ (is (nil? (mt/user-http-request :crowberto :get 204+ (format "ee/data-studio/table/%d/publishing-info" table-id)))))))))+(deftest publish-tables-goes-through-toucan-hooks-test(testing "publish/unpublish update via the Toucan pipeline, so model hooks fire"(mt/with-premium-features #{:library}diff --git a/enterprise/frontend/src/metabase-enterprise/api/table.ts b/enterprise/frontend/src/metabase-enterprise/api/table.tsindex a22a37d0f47..044f6870991 100644--- a/enterprise/frontend/src/metabase-enterprise/api/table.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/table.ts@@ -1,13 +1,23 @@import type {BulkTableRequest,PublishTablesResponse,+ TableId,+ TablePublishingInfo,} from "metabase-types/api";import { EnterpriseApi } from "./api";-import { invalidateTags, tag } from "./tags";+import { idTag, invalidateTags, tag } from "./tags";export const tableApi = EnterpriseApi.injectEndpoints({endpoints: (builder) => ({+ getTablePublishingInfo: builder.query<TablePublishingInfo | null, TableId>({+ query: (tableId) => ({+ method: "GET",+ url: `/api/ee/data-studio/table/${tableId}/publishing-info`,+ }),+ providesTags: (_, error, tableId) =>+ error ? [] : [idTag("table", tableId)],+ }),publishTables: builder.mutation<PublishTablesResponse, BulkTableRequest>({query: (body) => ({method: "POST",@@ -29,5 +39,8 @@ export const tableApi = EnterpriseApi.injectEndpoints({}),});-export const { usePublishTablesMutation, useUnpublishTablesMutation } =- tableApi;+export const {+ useGetTablePublishingInfoQuery,+ usePublishTablesMutation,+ useUnpublishTablesMutation,+} = tableApi;diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/DescriptionSection/DescriptionSection.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/DescriptionSection/DescriptionSection.tsxindex 107b46f6d5c..f1199e08080 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/DescriptionSection/DescriptionSection.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/DescriptionSection/DescriptionSection.tsx@@ -28,6 +28,8 @@ import * as Urls from "metabase/urls";import { isNullOrUndefined } from "metabase/utils/types";import type { Table, TableDataSource, UserId } from "metabase-types/api";+import { PublishingInfo } from "../PublishingInfo";+import S from "./DescriptionSection.module.css";type DescriptionSectionProps = {@@ -272,6 +274,7 @@ export function DescriptionSection({ table }: DescriptionSectionProps) {{t`Owner`}</Text></Card.Section>+ <PublishingInfo table={table} /></Card>{/* Statistics */}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.tsxnew file mode 100644index 00000000000..9120e09d101--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.tsx@@ -0,0 +1,68 @@+import { c, t } from "ttag";++import { DateTime } from "metabase/common/components/DateTime";+import { Card, Group, Icon, Text, Tooltip } from "metabase/ui";+import { useGetTablePublishingInfoQuery } from "metabase-enterprise/api";+import type { Table, TablePublishingInfo } from "metabase-types/api";++type PublishingInfoProps = {+ table: Pick<Table, "id" | "is_published">;+};++export function PublishingInfo({ table }: PublishingInfoProps) {+ const { data: publishingInfo } = useGetTablePublishingInfoQuery(table.id, {+ skip: !table.is_published,+ });++ if (!table.is_published || publishingInfo == null) {+ return null;+ }++ // This component must be rendered inside a Card parent.+ return (+ <Card.Section withBorder p="md">+ <Group gap="sm" mb={4} wrap="nowrap">+ <Icon name="publish" c="core-brand" />+ <PublishingInfoValue+ publishedAt={publishingInfo.published_at}+ publishedBy={publishingInfo.published_by}+ />+ </Group>+ <Text size="sm" c="text-secondary" lh="1rem" ml="1.5rem">+ {t`Published`}+ </Text>+ </Card.Section>+ );+}++function PublishingInfoValue({+ publishedAt,+ publishedBy,+}: {+ publishedAt: string;+ publishedBy: TablePublishingInfo["published_by"];+}) {+ const publishedAtElement = (+ <Tooltip+ key="published-at"+ label={<DateTime value={publishedAt} />}+ offset={8}+ >+ <DateTime+ value={publishedAt}+ unit="day"+ data-testid="table-publishing-date"+ />+ </Tooltip>+ );++ return (+ <Text size="md" fw={600} lh="1rem">+ {publishedBy == null+ ? publishedAtElement+ : c(+ "Describes when a table was published. {0} is a date and {1} is a person's name",+ ).jt`${publishedAtElement} by ${publishedBy.common_name}`}+ </Text>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.unit.spec.tsxnew file mode 100644index 00000000000..7e1582a4bf1--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/PublishingInfo.unit.spec.tsx@@ -0,0 +1,100 @@+import fetchMock from "fetch-mock";++import {+ setupTablePublishingInfoEndpoint,+ setupTablePublishingInfoEndpointError,+} from "__support__/server-mocks";+import { act, renderWithProviders, screen } from "__support__/ui";+import { Card } from "metabase/ui";+import type { TablePublishingInfo } from "metabase-types/api";+import { createMockTable } from "metabase-types/api/mocks";++import { PublishingInfo } from "./PublishingInfo";++const PUBLISHING_INFO: TablePublishingInfo = {+ published_at: "2026-08-26T12:00:00Z",+ published_by: {+ id: 1,+ common_name: "Bobby Tables",+ },+};++function setup({+ isPublished = true,+ publishingInfo = PUBLISHING_INFO,+ isError = false,+}: {+ isPublished?: boolean;+ publishingInfo?: TablePublishingInfo | null;+ isError?: boolean;+} = {}) {+ const table = createMockTable({ is_published: isPublished });+ if (isError) {+ setupTablePublishingInfoEndpointError(table.id);+ } else {+ setupTablePublishingInfoEndpoint(table.id, publishingInfo);+ }++ renderWithProviders(+ <Card>+ <PublishingInfo table={table} />+ </Card>,+ );++ return { table };+}++describe("PublishingInfo", () => {+ it("shows when and by whom the table was published", async () => {+ setup();++ expect(+ await screen.findByTestId("table-publishing-date"),+ ).not.toBeEmptyDOMElement();+ expect(screen.getByText(/by Bobby Tables/)).toBeInTheDocument();+ expect(screen.getByText("Published")).toBeInTheDocument();+ });++ it("shows the publication date when the publisher is unavailable", async () => {+ setup({+ publishingInfo: {+ ...PUBLISHING_INFO,+ published_by: null,+ },+ });++ expect(+ await screen.findByTestId("table-publishing-date"),+ ).not.toBeEmptyDOMElement();+ expect(screen.queryByText(/by /)).not.toBeInTheDocument();+ });++ it("does not show publishing information when there is no publishing event", async () => {+ setup({ publishingInfo: null });++ await act(async () => {+ await fetchMock.callHistory.flush(true);+ });+ expect(screen.queryByText("Published")).not.toBeInTheDocument();+ });++ it("does not show publishing information when it cannot be loaded", async () => {+ setup({ isError: true });++ await act(async () => {+ await fetchMock.callHistory.flush(true);+ });+ expect(screen.queryByText("Published")).not.toBeInTheDocument();+ });++ it("does not request or show publishing information for an unpublished table", () => {+ const { table } = setup({ isPublished: false });++ expect(+ fetchMock.callHistory.calls(+ `path:/api/ee/data-studio/table/${table.id}/publishing-info`,+ ),+ ).toHaveLength(0);+ expect(screen.queryByText("Published")).not.toBeInTheDocument();+ });+});diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/index.tsnew file mode 100644index 00000000000..c70a3cf9fd5--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/tables/pages/TableOverviewPage/TableOverview/PublishingInfo/index.ts@@ -0,0 +1 @@+export * from "./PublishingInfo";diff --git a/frontend/src/metabase-types/api/table.ts b/frontend/src/metabase-types/api/table.tsindex e531b772de6..e1800aa56f0 100644--- a/frontend/src/metabase-types/api/table.ts+++ b/frontend/src/metabase-types/api/table.ts@@ -88,6 +88,11 @@ export type TableOwner = Pick<"id" | "email" | "first_name" | "last_name">;+export type TablePublishingInfo = {+ published_at: string;+ published_by: Pick<UserInfo, "id" | "common_name"> | null;+};+export type SchemaName = string;export interface Schema {diff --git a/frontend/test/__support__/server-mocks/data-studio.ts b/frontend/test/__support__/server-mocks/data-studio.tsindex 124a3155385..594f7162125 100644--- a/frontend/test/__support__/server-mocks/data-studio.ts+++ b/frontend/test/__support__/server-mocks/data-studio.ts@@ -1,10 +1,13 @@import fetchMock from "fetch-mock";+import type { TableId, TablePublishingInfo } from "metabase-types/api";import {createMockBulkTableSelectionInfo,createMockPublishTablesResponse,} from "metabase-types/api/mocks";+const TABLE_PUBLISHING_INFO_ROUTE = "table-publishing-info";+export function setupTableSelectionInfoEndpoint(response = createMockBulkTableSelectionInfo(),) {@@ -34,3 +37,24 @@ export function setupUnpublishTablesEndpointError() {status: 500,});}++export function setupTablePublishingInfoEndpoint(+ tableId: TableId,+ response: TablePublishingInfo | null,+) {+ fetchMock.removeRoute(TABLE_PUBLISHING_INFO_ROUTE);+ fetchMock.get(+ `path:/api/ee/data-studio/table/${tableId}/publishing-info`,+ response ?? { status: 204 },+ { name: TABLE_PUBLISHING_INFO_ROUTE },+ );+}++export function setupTablePublishingInfoEndpointError(tableId: TableId) {+ fetchMock.removeRoute(TABLE_PUBLISHING_INFO_ROUTE);+ fetchMock.get(+ `path:/api/ee/data-studio/table/${tableId}/publishing-info`,+ { status: 500 },+ { name: TABLE_PUBLISHING_INFO_ROUTE },+ );+}