Skip to content
Snippets Groups Projects
Unverified Commit fb6921f8 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Do not fetch app settings when updating user-local setting (#39251)

* Create and use new action `updateUserSetting`

* Add E2E reproduction for #39221

Fixes #39221.
parent 100e3874
No related branches found
No related tags found
No related merge requests found
import { restore, startNewNativeQuestion, popover } from "e2e/support/helpers";
describe("issue 39221", () => {
beforeEach(() => {
cy.intercept("GET", "/api/setting").as("siteSettings");
cy.intercept("GET", "/api/session/properties").as("sessionProperties");
restore();
cy.signInAsAdmin();
cy.request("POST", "/api/database", {
engine: "sqlite",
name: "sqlite",
details: { db: "./resources/sqlite-fixture.db" },
});
});
["admin", "normal"].forEach(user => {
it(`${user.toUpperCase()}: updating user-specific setting should not result in fetching all site settings (metabase#39221)`, () => {
user === "normal" ? cy.signInAsNormalUser() : null;
startNewNativeQuestion();
popover().findByText("Sample Database").click();
cy.wait("@sessionProperties");
cy.get("@siteSettings").should("be.null");
});
});
});
import { createAction } from "redux-actions";
import { updateSetting } from "metabase/admin/settings/settings";
import Questions from "metabase/entities/questions";
import * as MetabaseAnalytics from "metabase/lib/analytics";
import { createThunkAction } from "metabase/lib/redux";
import { updateUserSetting } from "metabase/redux/settings";
import { getMetadata } from "metabase/selectors/metadata";
import type NativeQuery from "metabase-lib/queries/NativeQuery";
import type {
......@@ -197,7 +197,7 @@ export const setTemplateTagConfig = createThunkAction(
);
export const rememberLastUsedDatabase = (id: DatabaseId) =>
updateSetting({
updateUserSetting({
key: "last-used-native-database-id",
value: id,
});
import { createAsyncThunk, createReducer } from "@reduxjs/toolkit";
import { createThunkAction } from "metabase/lib/redux";
import MetabaseSettings from "metabase/lib/settings";
import { SessionApi } from "metabase/services";
import { SessionApi, SettingsApi } from "metabase/services";
export const REFRESH_SITE_SETTINGS = "metabase/settings/REFRESH_SITE_SETTINGS";
......@@ -32,3 +33,20 @@ export const settings = createReducer(
});
},
);
export const UPDATE_USER_SETTING = "metabase/settings/UPDATE_USER_SETTING";
export const updateUserSetting = createThunkAction(
UPDATE_USER_SETTING,
function (setting) {
return async function (dispatch) {
try {
await SettingsApi.put(setting);
} catch (error) {
console.error("error updating user setting", setting, error);
throw error;
} finally {
await dispatch(refreshSiteSettings({}));
}
};
},
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment