Merge pull request #13857 from Budibase/fix/10062-role-js
Quick fix for roles binding in JS
This commit is contained in:
commit
2497d60431
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue