diff --git a/app/client/src/api/UserApi.tsx b/app/client/src/api/UserApi.tsx index 6101c0a8c5..2bc98de5d7 100644 --- a/app/client/src/api/UserApi.tsx +++ b/app/client/src/api/UserApi.tsx @@ -94,6 +94,7 @@ class UserApi extends Api { static adminSettingsURL = "v1/admin/env"; static restartServerURL = "v1/admin/restart"; static downloadConfigURL = "v1/admin/env/download"; + static sendTestEmailURL = "/v1/admin/send-test-email"; static createUser( request: CreateUserRequest, @@ -205,6 +206,10 @@ class UserApi extends Api { static restartServer(): AxiosPromise { return Api.post(UserApi.restartServerURL); } + + static sendTestEmail(): AxiosPromise { + return Api.post(UserApi.sendTestEmailURL); + } } export default UserApi; diff --git a/app/client/src/constants/ReduxActionConstants.tsx b/app/client/src/constants/ReduxActionConstants.tsx index 94dc9d92cc..26c46d2e9a 100644 --- a/app/client/src/constants/ReduxActionConstants.tsx +++ b/app/client/src/constants/ReduxActionConstants.tsx @@ -624,6 +624,7 @@ export const ReduxActionTypes = { UPDATE_JS_ACTION_BODY: "UPDATE_JS_ACTION_BODY", UPDATE_JS_ACTION_BODY_INIT: "UPDATE_JS_ACTION_BODY_INIT", UPDATE_JS_ACTION_BODY_SUCCESS: "UPDATE_JS_ACTION_BODY_SUCCESS", + SEND_TEST_EMAIL: "SEND_TEST_EMAIL", }; export type ReduxActionType = typeof ReduxActionTypes[keyof typeof ReduxActionTypes]; diff --git a/app/client/src/constants/messages.ts b/app/client/src/constants/messages.ts index 439239f5d7..1021a0337c 100644 --- a/app/client/src/constants/messages.ts +++ b/app/client/src/constants/messages.ts @@ -806,6 +806,10 @@ export const RESTART_ERROR_BODY = () => export const RESTART_ERROR_HEADER = () => "Restart failed"; export const INFO_VERSION_MISMATCH_FOUND_RELOAD_REQUEST = () => "Hey! There is a new version of Appsmith available. Please consider refreshing your window."; +export const TEST_EMAIL_SUCCESS = (email: string) => () => + `Test email sent, please check the inbox of ${email}`; +export const TEST_EMAIL_SUCCESS_TROUBLESHOOT = () => "Troubleshoot"; +export const TEST_EMAIL_FAILURE = () => "Sending Test Email Failed"; export const WELCOME_FORM_NON_SUPER_USER_ROLE_DROPDOWN = () => "Tell us more about what you do at work?"; diff --git a/app/client/src/constants/userConstants.ts b/app/client/src/constants/userConstants.ts index 6588bdcb79..ec4931eccb 100644 --- a/app/client/src/constants/userConstants.ts +++ b/app/client/src/constants/userConstants.ts @@ -19,6 +19,7 @@ export type User = { isSuperUser: boolean; role?: string; useCase?: string; + isConfigurable: boolean; }; export interface UserApplication { @@ -37,6 +38,7 @@ export const DefaultCurrentUserDetails: User = { username: ANONYMOUS_USERNAME, gender: "MALE", isSuperUser: false, + isConfigurable: false, }; // TODO keeping it here instead of the USER_API since it leads to cyclic deps errors during tests diff --git a/app/client/src/pages/Settings/SettingsConfig.ts b/app/client/src/pages/Settings/SettingsConfig.ts index bb608e07ab..2fc8f14f61 100644 --- a/app/client/src/pages/Settings/SettingsConfig.ts +++ b/app/client/src/pages/Settings/SettingsConfig.ts @@ -193,6 +193,24 @@ SettingsFactory.register("APPSMITH_MAIL_PASSWORD", { }, }); +SettingsFactory.register("APPSMITH_MAIL_TEST_EMAIL", { + action: (dispatch) => { + dispatch && + dispatch({ + type: ReduxActionTypes.SEND_TEST_EMAIL, + payload: true, + }); + }, + category: "email", + controlType: SettingTypes.BUTTON, + isVisible: (values: Record) => { + return ( + values && values["APPSMITH_MAIL_HOST"] && values["APPSMITH_MAIL_FROM"] + ); + }, + text: "Send Test Email", +}); + //General SettingsFactory.register("APPSMITH_INSTANCE_NAME", { category: "general", diff --git a/app/client/src/pages/Settings/WithSuperUserHoc.tsx b/app/client/src/pages/Settings/WithSuperUserHoc.tsx index d6de64f759..e07d3bb15f 100644 --- a/app/client/src/pages/Settings/WithSuperUserHoc.tsx +++ b/app/client/src/pages/Settings/WithSuperUserHoc.tsx @@ -10,7 +10,7 @@ export default function WithSuperUserHOC( return function Wrapped(props: RouteComponentProps) { const user = useSelector(getCurrentUser); - if (!user?.isSuperUser) { + if (!user?.isSuperUser || !user?.isConfigurable) { return ; } return ; diff --git a/app/client/src/pages/common/ProfileDropdown.tsx b/app/client/src/pages/common/ProfileDropdown.tsx index ecfab3c83c..097be61151 100644 --- a/app/client/src/pages/common/ProfileDropdown.tsx +++ b/app/client/src/pages/common/ProfileDropdown.tsx @@ -141,7 +141,7 @@ export default function ProfileDropdown(props: TagProps) { }} text="Edit Profile" /> - {user?.isSuperUser && isAdminSettingsEnabled && ( + {user?.isSuperUser && user?.isConfigurable && isAdminSettingsEnabled && ( +
+ window.open(EMAIL_SETUP_DOC, "blank")}> + {createMessage(TEST_EMAIL_SUCCESS_TROUBLESHOOT)} + + + ); + } + Toaster.show({ + actionElement, + text: createMessage( + response.data + ? TEST_EMAIL_SUCCESS(currentUser?.email) + : TEST_EMAIL_FAILURE, + ), + hideProgressBar: true, + variant: response.data ? Variant.info : Variant.danger, + }); + } catch (e) { + Toaster.show({ + text: createMessage(TEST_EMAIL_FAILURE), + hideProgressBar: true, + variant: Variant.danger, + }); + } +} + function* InitSuperUserSaga(action: ReduxAction) { const user = action.payload; if (user.isSuperUser) { @@ -102,6 +145,7 @@ function* InitSuperUserSaga(action: ReduxAction) { ), takeLatest(ReduxActionTypes.SAVE_ADMIN_SETTINGS, SaveAdminSettingsSaga), takeLatest(ReduxActionTypes.RESTART_SERVER_POLL, RestartServerPoll), + takeLatest(ReduxActionTypes.SEND_TEST_EMAIL, SendTestEmail), ]); } }