fix: Disallows entity name to be any extra library name (#8755)

Co-authored-by: sbalaji1192 <balaji@appsmith.com>
This commit is contained in:
Confidence Okoghenun 2021-11-10 14:59:24 +01:00 committed by GitHub
parent c14b0ac1bf
commit 014d1f17d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 6 deletions

View File

@ -996,7 +996,7 @@ Cypress.Commands.add("CreationOfUniqueAPIcheck", (apiname) => {
.type(apiname, { force: true, delay: 500 }) .type(apiname, { force: true, delay: 500 })
.should("have.value", apiname); .should("have.value", apiname);
cy.get(".error-message").should(($x) => { cy.get(".error-message").should(($x) => {
expect($x).contain(apiname.concat(" is already being used.")); expect($x).contain(apiname.concat(" is already being used or is a restricted keyword."));
}); });
cy.get(apiwidget.apiTxt).blur(); cy.get(apiwidget.apiTxt).blur();
}); });
@ -1081,7 +1081,7 @@ Cypress.Commands.add("CreateApiAndValidateUniqueEntityName", (apiname) => {
.type(apiname, { force: true }) .type(apiname, { force: true })
.should("have.value", apiname); .should("have.value", apiname);
cy.get(".t--nameOfApi .error-message").should(($x) => { cy.get(".t--nameOfApi .error-message").should(($x) => {
expect($x).contain(apiname.concat(" is already being used.")); expect($x).contain(apiname.concat(" is already being used or is a restricted keyword."));
}); });
}); });

View File

@ -120,7 +120,7 @@ export function ActionNameEditor(props: ActionNameEditorProps) {
name !== currentActionConfig?.name && name !== currentActionConfig?.name &&
hasActionNameConflict(name) hasActionNameConflict(name)
) { ) {
return `${name} is already being used.`; return `${name} is already being used or is a restricted keyword.`;
} }
return false; return false;
}, },

View File

@ -75,7 +75,7 @@ function FormTitle(props: FormTitleProps) {
if (!name || name.trim().length === 0) { if (!name || name.trim().length === 0) {
return "Please enter a valid name"; return "Please enter a valid name";
} else if (hasNameConflict(name)) { } else if (hasNameConflict(name)) {
return `${name} is already being used.`; return `${name} is already being used or is a restricted keyword.`;
} }
return false; return false;
}, },

View File

@ -107,7 +107,7 @@ export function JSObjectNameEditor(props: ActionNameEditorProps) {
name !== currentJSObjectConfig?.name && name !== currentJSObjectConfig?.name &&
hasNameConflict(name) hasNameConflict(name)
) { ) {
return `${name} is already being used.`; return `${name} is already being used or is a restricted keyword.`;
} }
return false; return false;
}, },

View File

@ -790,7 +790,7 @@ export function* updateWidgetNameSaga(
type: ReduxActionErrorTypes.UPDATE_WIDGET_NAME_ERROR, type: ReduxActionErrorTypes.UPDATE_WIDGET_NAME_ERROR,
payload: { payload: {
error: { error: {
message: `Entity name: ${action.payload.newName} is already being used.`, message: `Entity name: ${action.payload.newName} is already being used or is a restricted keyword.`,
}, },
}, },
}); });

View File

@ -192,6 +192,19 @@ export const extraLibraries: ExtraLibrary[] = [
}, },
]; ];
/**
* creates dynamic list of constants based on
* current list of extra libraries i.e lodash("_"), moment etc
* to be used in widget and entity name validations
*/
export const extraLibrariesNames = extraLibraries.reduce(
(prev: any, curr: any) => {
prev[curr.accessor] = curr.accessor;
return prev;
},
{},
);
export interface DynamicPath { export interface DynamicPath {
key: string; key: string;
value?: string; value?: string;

View File

@ -22,6 +22,7 @@ import { getAppsmithConfigs } from "configs";
import { sha256 } from "js-sha256"; import { sha256 } from "js-sha256";
import moment from "moment"; import moment from "moment";
import log from "loglevel"; import log from "loglevel";
import { extraLibrariesNames } from "./DynamicBindingUtils";
const { cloudHosting, intercomAppID } = getAppsmithConfigs(); const { cloudHosting, intercomAppID } = getAppsmithConfigs();
@ -286,6 +287,7 @@ export const isNameValid = (
name in GLOBAL_FUNCTIONS || name in GLOBAL_FUNCTIONS ||
name in WINDOW_OBJECT_PROPERTIES || name in WINDOW_OBJECT_PROPERTIES ||
name in WINDOW_OBJECT_METHODS || name in WINDOW_OBJECT_METHODS ||
name in extraLibrariesNames ||
name in invalidNames name in invalidNames
); );
}; };