1
0
Fork 0
mirror of synced 2024-08-23 14:01:34 +12:00

Merge pull request #13857 from Budibase/fix/10062-role-js

Quick fix for roles binding in JS
This commit is contained in:
Michael Drury 2024-06-05 12:10:24 +01:00 committed by GitHub
commit 2497d60431
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View file

@ -728,7 +728,7 @@ const getRoleBindings = () => {
return (get(rolesStore) || []).map(role => {
return {
type: "context",
runtimeBinding: `trim "${role._id}"`,
runtimeBinding: `'${role._id}'`,
readableBinding: `Role.${role.name}`,
category: "Role",
icon: "UserGroup",

View file

@ -33,7 +33,12 @@ const removeSquareBrackets = (value: string) => {
// Our context getter function provided to JS code as $.
// Extracts a value from context.
const getContextValue = (path: string, context: any) => {
const literalStringRegex = /^(["'`]).*\1$/
let data = context
// check if it's a literal string - just return path if its quoted
if (literalStringRegex.test(path)) {
return path.substring(1, path.length - 1)
}
path.split(".").forEach(key => {
if (data == null || typeof data !== "object") {
return null

View file

@ -149,4 +149,11 @@ describe("Javascript", () => {
expect(output).toMatch(UUID_REGEX)
})
})
describe("JS literal strings", () => {
it("should be able to handle a literal string that is quoted (like role IDs)", () => {
const output = processJS(`return $("'Custom'")`)
expect(output).toBe("Custom")
})
})
})