Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(
agHelper.AddDsl("promisesBtnDsl", locators._buttonByText("Submit"));
});

it("10. Bug 23167 - Message field in PostMessage should accept all type of values", () => {
it("1. Bug 23167 - Message field in PostMessage should accept all type of values", () => {
EditorNavigation.SelectEntityByName("Page1", EntityType.Page);
EditorNavigation.SelectEntityByName("Button1", EntityType.Widget);

Expand Down Expand Up @@ -53,5 +53,23 @@ describe(
"{{{\n x: Input1.text \n}}}window*",
);
});

it("2. should logout user successfully using global logoutUser function and should redirect to the same app on login", () => {
agHelper.RefreshPage();
EditorNavigation.SelectEntityByName("Page1", EntityType.Page);
EditorNavigation.SelectEntityByName("Button1", EntityType.Widget);
propPane.EnterJSContext(
"onClick",
"{{logoutUser(appsmith.URL.pathname)}}",
true,
false,
);
propPane.ToggleJSMode("onClick", false);
propPane.UpdatePropertyFieldValue("Label", "");
propPane.TypeTextIntoField("Label", "LOGOUT GLOBAL");
agHelper.ClickButton("LOGOUT GLOBAL");
cy.LoginUser(Cypress.env("USERNAME"), Cypress.env("PASSWORD"), false);
Comment thread
rahulbarwal marked this conversation as resolved.
Outdated
agHelper.AssertElementVisibility(locators._buttonByText(""));
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
);
1 change: 1 addition & 0 deletions app/client/src/ce/constants/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ export const GET_GEO_LOCATION = () => `Get geolocation`;
export const WATCH_GEO_LOCATION = () => `Watch geolocation`;
export const STOP_WATCH_GEO_LOCATION = () => `Stop watching geolocation`;
export const POST_MESSAGE = () => `Post message`;
export const LOGOUT_USER = () => `Logout user`;

//js actions
export const JS_ACTION_COPY_SUCCESS = (actionName: string, pageName: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type { ActionDescription } from "ee/workers/Evaluation/fns";
import type { AppState } from "ee/reducers";
import { getAction } from "ee/selectors/entitiesSelector";
import { getSourceFromTriggerMeta } from "ee/entities/AppsmithConsole/utils";
import { globalFunctionLogoutUser } from "../userSagas";

export interface TriggerMeta {
source?: TriggerSource;
Expand Down Expand Up @@ -131,6 +132,9 @@ export function* executeActionTriggers(
case "POST_MESSAGE":
yield call(postMessageSaga, trigger);
break;
case "LOGOUT_USER_INIT":
yield call(globalFunctionLogoutUser, trigger);
break;
default:
log.error("Trigger type unknown", trigger, source);
throw Error("Trigger type unknown");
Expand Down
13 changes: 13 additions & 0 deletions app/client/src/ce/sagas/userSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,16 @@ export const setMessageConfig = (id: string, config: ProductAlertConfig) => {
JSON.stringify(updatedConfig),
);
};

export function* globalFunctionLogoutUser(
action: ReduxAction<{ redirectURL: string }>,
) {
const redirectURL = `${AUTH_LOGIN_URL}${action.payload?.redirectURL ? "?redirectUrl=" + action.payload?.redirectURL : ""}`;

yield call(logoutSaga, {
type: ReduxActionTypes.LOGOUT_USER_INIT,
payload: {
redirectURL,
},
});
}
9 changes: 9 additions & 0 deletions app/client/src/ce/utils/autocomplete/EntityDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ export const GLOBAL_FUNCTIONS = {
"Establish cross-origin communication between Window objects/page and iframes",
"!type": "fn(message: unknown, source: string, targetOrigin: string)",
},
logoutUser: {
"!url":
"https://docs.appsmith.com/reference/appsmith-framework/widget-actions/logout-user",
"!doc": "Logout user",
"!type": "fn(redirectURL: string) -> void",
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

// TODO: Fix this the next time the file is edited
Expand Down Expand Up @@ -329,6 +335,9 @@ export const ternDocsInfo: Record<string, any> = {
postWindowMessage: {
exampleArgs: ["message, 'Iframe1', '*'"],
},
logoutUser: {
exampleArgs: ["url"],
},
};

export type EntityDefinitionsOptions = keyof typeof entityDefinitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ describe("Test Field Group Config", () => {
expectedLabel: "Stop watching geolocation",
expectedFields: [],
},
{
index: 15,
input: AppsmithFunction.postWindowMessage,
expectedLabel: "Post message",
expectedFields: [
FieldType.MESSAGE_FIELD,
FieldType.SOURCE_FIELD,
FieldType.TARGET_ORIGIN_FIELD,
],
},
Comment thread
AmanAgarwal041 marked this conversation as resolved.
{
index: 15,
input: AppsmithFunction.logoutUser,
expectedLabel: "Logout user",
expectedFields: [FieldType.URL_FIELD],
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
];

test.each(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EXECUTE_A_QUERY,
EXECUTE_JS_FUNCTION,
GET_GEO_LOCATION,
LOGOUT_USER,
NAVIGATE_TO,
NO_ACTION,
SHOW_MODAL,
Expand Down Expand Up @@ -167,4 +168,10 @@ export const FIELD_GROUP_CONFIG: FieldGroupConfig = {
defaultParams: `"", "window", "*"`,
icon: "chat-upload-line",
},
[AppsmithFunction.logoutUser]: {
label: createMessage(LOGOUT_USER),
fields: [FieldType.URL_FIELD],
defaultParams: `""`,
icon: "logout",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum APPSMITH_GLOBAL_FUNCTIONS {
setInterval = "setInterval",
clearInterval = "clearInterval",
postWindowMessage = "postWindowMessage",
logoutUser = "logoutUser",
}

export enum APPSMITH_NAMESPACED_FUNCTIONS {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ export const chainableFns: TActionBlock["actionType"][] = [
AppsmithFunction.resetWidget,
AppsmithFunction.showModal,
AppsmithFunction.download,
AppsmithFunction.logoutUser,
];

export function actionToCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function GetIconForAction(
case AppsmithFunction.postWindowMessage:
return () => <Icon name="chat-upload-icon" />;

case AppsmithFunction.logoutUser:
return () => <Icon name="logout" />;

default:
return () => <Icon name="js" />;
}
Expand Down Expand Up @@ -205,6 +208,11 @@ function getActionHeading(
return (
FIELD_CONFIG[FieldType.MESSAGE_FIELD].getter(code) || "Add message"
);

case AppsmithFunction.logoutUser:
return (
FIELD_CONFIG[FieldType.URL_FIELD].getter(code) || "Add redirect url"
);
}

return "";
Expand Down
9 changes: 8 additions & 1 deletion app/client/src/workers/Evaluation/fns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
} from "./geolocationFns";
import { getFnWithGuards, isAsyncGuard } from "./utils/fnGuard";
import { isRunNClearFnQualifierEntity } from "ee/workers/Evaluation/fns/utils/isRunNClearFnQualifierEntity";
import { logoutUser, type TSLogoutActionType } from "./logout";

export const getPlatformFunctions = () => {
return platformFns;
Expand Down Expand Up @@ -114,6 +115,10 @@ const platformFns = [
name: "clearStore",
fn: clearStore,
},
{
name: "logoutUser",
fn: logoutUser,
},
];

const entityFns = [
Expand Down Expand Up @@ -215,6 +220,7 @@ const ActionTriggerFunctionNames: Record<string, string> = {
POST_MESSAGE: "postWindowMessage",
SET_TIMEOUT: "setTimeout",
CLEAR_TIMEOUT: "clearTimeout",
LOGOUT_USER_INIT: "logoutUser",
};

export type ActionDescription =
Expand All @@ -234,4 +240,5 @@ export type ActionDescription =
| TCopyToClipboardDescription
| TGetGeoLocationDescription
| TWatchGeoLocationDescription
| TStopWatchGeoLocationDescription;
| TStopWatchGeoLocationDescription
| TSLogoutActionType;
18 changes: 18 additions & 0 deletions app/client/src/workers/Evaluation/fns/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { promisify } from "./utils/Promisify";

function logoutFnDescriptor(redirectURL: string) {
return {
type: "LOGOUT_USER_INIT" as const,
payload: {
redirectURL,
},
};
}

export type TSLogoutActionType = ReturnType<typeof logoutFnDescriptor>;

export async function logoutUser(
...args: Parameters<typeof logoutFnDescriptor>
) {
return promisify(logoutFnDescriptor)(...args);
}