## Description Adding analytics event for general setting changes under admin settings #### PR fixes following issue(s) Fixes [#24418](https://github.com/appsmithorg/appsmith/issues/24418) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
199 lines
5.6 KiB
TypeScript
199 lines
5.6 KiB
TypeScript
import type { SendTestEmailPayload } from "@appsmith/api/UserApi";
|
|
import UserApi from "@appsmith/api/UserApi";
|
|
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
|
import {
|
|
ReduxActionErrorTypes,
|
|
ReduxActionTypes,
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
|
import { APPLICATIONS_URL } from "constants/routes";
|
|
import type { User } from "constants/userConstants";
|
|
import { call, put, delay, select } from "redux-saga/effects";
|
|
import history from "utils/history";
|
|
import { validateResponse } from "sagas/ErrorSagas";
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
|
|
|
import type { ApiResponse } from "api/ApiResponses";
|
|
import {
|
|
APPSMITH_DISPLAY_VERSION,
|
|
createMessage,
|
|
TEST_EMAIL_FAILURE,
|
|
TEST_EMAIL_SUCCESS,
|
|
TEST_EMAIL_SUCCESS_TROUBLESHOOT,
|
|
} from "@appsmith/constants/messages";
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
import { EMAIL_SETUP_DOC } from "constants/ThirdPartyConstants";
|
|
import { getCurrentTenant } from "@appsmith/actions/tenantActions";
|
|
import { toast } from "design-system";
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
import {
|
|
RESTART_POLL_INTERVAL,
|
|
RESTART_POLL_TIMEOUT,
|
|
} from "@appsmith/constants/tenantConstants";
|
|
|
|
export function* FetchAdminSettingsSaga() {
|
|
const response: ApiResponse = yield call(UserApi.fetchAdminSettings);
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
|
|
|
if (isValidResponse) {
|
|
const { appVersion, cloudHosting } = getAppsmithConfigs();
|
|
const settings = {
|
|
//@ts-expect-error: response is of type unknown
|
|
...response.data,
|
|
APPSMITH_CURRENT_VERSION: createMessage(
|
|
APPSMITH_DISPLAY_VERSION,
|
|
appVersion.edition,
|
|
appVersion.id,
|
|
cloudHosting,
|
|
),
|
|
};
|
|
|
|
// Converting empty values to boolean false
|
|
Object.keys(settings).forEach((key) => {
|
|
if ((settings[key] as string).trim() === "") {
|
|
settings[key] = false;
|
|
}
|
|
});
|
|
|
|
yield put({
|
|
type: ReduxActionTypes.FETCH_ADMIN_SETTINGS_SUCCESS,
|
|
payload: settings,
|
|
});
|
|
} else {
|
|
yield put({
|
|
type: ReduxActionTypes.FETCH_ADMIN_SETTINGS_ERROR,
|
|
payload: response,
|
|
});
|
|
}
|
|
}
|
|
|
|
export function* FetchAdminSettingsErrorSaga() {
|
|
history.push(APPLICATIONS_URL);
|
|
}
|
|
|
|
export function* SaveAdminSettingsSaga(
|
|
action: ReduxAction<{
|
|
settings: Record<string, any>;
|
|
needsRestart: boolean;
|
|
}>,
|
|
) {
|
|
const { needsRestart = true, settings } = action.payload;
|
|
|
|
try {
|
|
const { appVersion } = getAppsmithConfigs();
|
|
const hasDisableTelemetrySetting = settings.hasOwnProperty(
|
|
"APPSMITH_DISABLE_TELEMETRY",
|
|
);
|
|
const hasHideWatermarkSetting = settings.hasOwnProperty(
|
|
"APPSMITH_HIDE_WATERMARK",
|
|
);
|
|
const response: ApiResponse = yield call(
|
|
UserApi.saveAdminSettings,
|
|
settings,
|
|
);
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
|
|
|
if (isValidResponse) {
|
|
toast.show("Successfully saved", {
|
|
kind: "success",
|
|
});
|
|
|
|
if (settings["APPSMITH_DISABLE_TELEMETRY"]) {
|
|
AnalyticsUtil.logEvent("TELEMETRY_DISABLED", {
|
|
version: appVersion.id,
|
|
});
|
|
}
|
|
|
|
if (hasDisableTelemetrySetting || hasHideWatermarkSetting) {
|
|
AnalyticsUtil.logEvent("GENERAL_SETTINGS_UPDATE", {
|
|
version: appVersion.id,
|
|
...(hasDisableTelemetrySetting
|
|
? { telemetry_disabled: settings["APPSMITH_DISABLE_TELEMETRY"] }
|
|
: {}),
|
|
...(hasHideWatermarkSetting
|
|
? { watermark_disabled: settings["APPSMITH_HIDE_WATERMARK"] }
|
|
: {}),
|
|
});
|
|
}
|
|
|
|
yield put({
|
|
type: ReduxActionTypes.SAVE_ADMIN_SETTINGS_SUCCESS,
|
|
});
|
|
|
|
yield put(getCurrentTenant());
|
|
|
|
yield put({
|
|
type: ReduxActionTypes.FETCH_ADMIN_SETTINGS_SUCCESS,
|
|
payload: settings,
|
|
});
|
|
|
|
if (needsRestart) {
|
|
yield put({
|
|
type: ReduxActionTypes.RESTART_SERVER_POLL,
|
|
});
|
|
}
|
|
} else {
|
|
yield put({
|
|
type: ReduxActionTypes.SAVE_ADMIN_SETTINGS_ERROR,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
yield put({
|
|
type: ReduxActionTypes.SAVE_ADMIN_SETTINGS_ERROR,
|
|
});
|
|
}
|
|
}
|
|
|
|
export function* RestartServerPoll() {
|
|
yield call(UserApi.restartServer);
|
|
yield call(RestryRestartServerPoll);
|
|
}
|
|
|
|
export function* RestryRestartServerPoll() {
|
|
let pollCount = 0;
|
|
const maxPollCount = RESTART_POLL_TIMEOUT / RESTART_POLL_INTERVAL;
|
|
while (pollCount < maxPollCount) {
|
|
pollCount++;
|
|
yield delay(RESTART_POLL_INTERVAL);
|
|
try {
|
|
const response: ApiResponse = yield call(UserApi.getCurrentUser);
|
|
if (response.responseMeta.status === 200) {
|
|
window.location.reload();
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
yield put({
|
|
type: ReduxActionErrorTypes.RESTART_SERVER_ERROR,
|
|
});
|
|
}
|
|
|
|
export function* SendTestEmail(action: ReduxAction<SendTestEmailPayload>) {
|
|
try {
|
|
const response: ApiResponse = yield call(
|
|
UserApi.sendTestEmail,
|
|
action.payload,
|
|
);
|
|
const currentUser: User | undefined = yield select(getCurrentUser);
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
|
|
|
if (isValidResponse) {
|
|
if (response.data) {
|
|
}
|
|
toast.show(
|
|
createMessage(
|
|
response.data
|
|
? // @ts-expect-error: currentUser can be undefined
|
|
TEST_EMAIL_SUCCESS(currentUser?.email)
|
|
: TEST_EMAIL_FAILURE,
|
|
),
|
|
{
|
|
kind: response.data ? "info" : "error",
|
|
action: {
|
|
text: createMessage(TEST_EMAIL_SUCCESS_TROUBLESHOOT),
|
|
effect: () => window.open(EMAIL_SETUP_DOC, "blank"),
|
|
},
|
|
},
|
|
);
|
|
}
|
|
} catch (e) {}
|
|
}
|