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
[GHY-4755] Only follow a discovered remote sync task the current user started (#83579)
Tyler Pludee2369cc1d408
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.tsindex 64252324590..d6af5f818ba 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts@@ -2,6 +2,7 @@ import type { ThunkDispatch, UnknownAction } from "@reduxjs/toolkit";import { createListenerMiddleware } from "@reduxjs/toolkit";import { Api } from "metabase/api";+import { getUserId } from "metabase/current-user";import type { State } from "metabase/redux/store";import { EnterpriseApi } from "metabase-enterprise/api/api";import { remoteSyncApi } from "metabase-enterprise/api/remote-sync";@@ -114,20 +115,25 @@ const terminalTaskStates: RemoteSyncTaskStatus[] = [remoteSyncListenerMiddleware.startListening({matcher: remoteSyncApi.endpoints.getRemoteSyncCurrentTask.matchFulfilled,- effect: async (action, { dispatch, getOriginalState }) => {+ effect: async (action, { dispatch, getState, getOriginalState }) => {const task = action.payload;if (task) {// The query is subscribed whenever remote sync is enabled, so a fetch made while nothing is being- // watched is discovery, not an event: a task still running elsewhere is picked up so this tab can- // follow it, while a finished one is history and is left alone. Treating history as an event would- // replay an old conflict on every page load and, since the terminal handling invalidates this- // query's own tag, refetch forever.+ // watched is discovery, not an event: the current user's own running task is picked up so this tab+ // can follow it, while a finished one is history and is left alone. Treating history as an event+ // would replay an old conflict on every page load and, since the terminal handling invalidates this+ // query's own tag, refetch forever. Another user's task (or an auto-import) is not followed: the+ // blocking progress modal would otherwise open for every admin, offering to cancel a sync they did+ // not start.const previous = getCurrentTask(getOriginalState());const wasRunning = previous !== null && previous.ended_at === null;if (!wasRunning) {- if (task.ended_at === null) {+ if (+ task.ended_at === null &&+ task.initiated_by === getUserId(getState())+ ) {dispatch(taskUpdated(task));}return;diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.tsindex 6abc1fc3f70..b5f6385d4da 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts@@ -21,6 +21,7 @@ import type { EnterpriseSettings } from "metabase-types/api";import {createMockCollection,createMockSettings,+ createMockUser,} from "metabase-types/api/mocks";import {@@ -31,6 +32,9 @@ import {import { remoteSyncListenerMiddleware } from "./remote-sync-listener-middleware";+const CURRENT_USER_ID = 1;+const OTHER_USER_ID = 2;+const createTestStore = (settingsOverrides: Partial<EnterpriseSettings> = {},) => {@@ -52,6 +56,10 @@ const createTestStore = (...settingsOverrides,}),},+ {+ endpointName: "getCurrentUser",+ value: createMockUser({ id: CURRENT_USER_ID, is_superuser: true }),+ },]),},middleware: (getDefaultMiddleware) =>@@ -327,7 +335,7 @@ describe("remote-sync-listener-middleware", () => {const CURRENT_TASK = "path:/api/ee/remote-sync/current-task";const settle = () => new Promise((resolve) => setTimeout(resolve, 100));- it("follows a task found running on load so the tab can watch it", async () => {+ it("follows the current user's task found running on load so the tab can watch it", async () => {fetchMock.get(CURRENT_TASK, {status: 200,body: {@@ -336,6 +344,7 @@ describe("remote-sync-listener-middleware", () => {sync_task_type: "import",progress: 0.4,ended_at: null,+ initiated_by: CURRENT_USER_ID,},});const store = createTestStore();@@ -352,6 +361,84 @@ describe("remote-sync-listener-middleware", () => {expect(store.getState().plugins.remoteSyncPlugin.showModal).toBe(true);});+ it.each([+ ["another user", OTHER_USER_ID],+ ["no user (auto-import)", null],+ ])(+ "does not follow or show a running task started by %s",+ async (_description, initiatedBy) => {+ fetchMock.get(CURRENT_TASK, {+ status: 200,+ body: {+ id: 5,+ status: "running",+ sync_task_type: "export",+ progress: 0.3,+ ended_at: null,+ initiated_by: initiatedBy,+ },+ });+ const store = createTestStore();++ store.dispatch(+ remoteSyncApi.endpoints.getRemoteSyncCurrentTask.initiate(),+ );++ await waitForCondition(() => fetchMock.callHistory.done(CURRENT_TASK));+ await settle();++ expect(+ store.getState().plugins.remoteSyncPlugin.currentTask,+ ).toBeNull();+ expect(store.getState().plugins.remoteSyncPlugin.showModal).toBe(false);+ },+ );++ it("does not route another user's import conflict to the setup modal", async () => {+ const responses = [+ {+ id: 5,+ status: "running",+ sync_task_type: "import",+ progress: 0.3,+ ended_at: null,+ initiated_by: OTHER_USER_ID,+ },+ {+ id: 5,+ status: "conflict",+ sync_task_type: "import",+ ended_at: "2026-01-01T00:00:01Z",+ initiated_by: OTHER_USER_ID,+ },+ ];+ fetchMock.get(CURRENT_TASK, () => ({+ status: 200,+ body: responses.shift() ?? responses[0],+ }));+ const store = createTestStore();++ store.dispatch(+ remoteSyncApi.endpoints.getRemoteSyncCurrentTask.initiate(),+ );+ await waitForCondition(() => fetchMock.callHistory.done(CURRENT_TASK));+ await settle();+ store.dispatch(+ remoteSyncApi.endpoints.getRemoteSyncCurrentTask.initiate(undefined, {+ forceRefetch: true,+ }),+ );+ await waitFor(() => {+ expect(fetchMock.callHistory.calls(CURRENT_TASK)).toHaveLength(2);+ });+ await settle();++ expect(+ store.getState().plugins.remoteSyncPlugin.syncConflictVariant,+ ).toBeNull();+ expect(store.getState().plugins.remoteSyncPlugin.showModal).toBe(false);+ });+it("leaves a finished task found on load alone", async () => {fetchMock.get(CURRENT_TASK, {status: 200,