Skip to content

Commit d35864b

Browse files
committed
Fixing issue introduced by fix for #7683 - encoding the query string caused handlebars statements to break, this rectifies that.
1 parent e0cf125 commit d35864b

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

packages/bbui/src/Tooltip/TooltipWrapper.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
display: flex;
4848
justify-content: center;
4949
top: 15px;
50-
z-index: 100;
50+
z-index: 200;
5151
width: 160px;
5252
}
5353
.icon {

packages/builder/src/builderStore/dataBinding.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
import { store } from "builderStore"
1010
import {
1111
queries as queriesStores,
12-
tables as tablesStore,
1312
roles as rolesStore,
13+
tables as tablesStore,
1414
} from "stores/backend"
1515
import {
16-
makePropSafe,
17-
isJSBinding,
1816
decodeJSBinding,
1917
encodeJSBinding,
18+
isJSBinding,
19+
makePropSafe,
2020
} from "@budibase/string-templates"
2121
import { TableNames } from "../constants"
2222
import { JSONUtils } from "@budibase/frontend-core"
@@ -118,8 +118,7 @@ export const readableToRuntimeMap = (bindings, ctx) => {
118118
return {}
119119
}
120120
return Object.keys(ctx).reduce((acc, key) => {
121-
let parsedQuery = readableToRuntimeBinding(bindings, ctx[key])
122-
acc[key] = parsedQuery
121+
acc[key] = readableToRuntimeBinding(bindings, ctx[key])
123122
return acc
124123
}, {})
125124
}
@@ -132,8 +131,7 @@ export const runtimeToReadableMap = (bindings, ctx) => {
132131
return {}
133132
}
134133
return Object.keys(ctx).reduce((acc, key) => {
135-
let parsedQuery = runtimeToReadableBinding(bindings, ctx[key])
136-
acc[key] = parsedQuery
134+
acc[key] = runtimeToReadableBinding(bindings, ctx[key])
137135
return acc
138136
}, {})
139137
}

packages/builder/src/helpers/data/utils.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IntegrationTypes } from "constants/backend"
2+
import { findHBSBlocks } from "@budibase/string-templates"
23

34
export function schemaToFields(schema) {
45
const response = {}
@@ -31,7 +32,8 @@ export function breakQueryString(qs) {
3132
let paramObj = {}
3233
for (let param of params) {
3334
const split = param.split("=")
34-
paramObj[split[0]] = split.slice(1).join("=")
35+
console.log(split[1])
36+
paramObj[split[0]] = decodeURIComponent(split.slice(1).join("="))
3537
}
3638
return paramObj
3739
}
@@ -46,7 +48,19 @@ export function buildQueryString(obj) {
4648
if (str !== "") {
4749
str += "&"
4850
}
49-
str += `${key}=${encodeURIComponent(value || "")}`
51+
const bindings = findHBSBlocks(value)
52+
let count = 0
53+
const bindingMarkers = {}
54+
bindings.forEach(binding => {
55+
const marker = `BINDING...${count++}`
56+
value = value.replace(binding, marker)
57+
bindingMarkers[marker] = binding
58+
})
59+
let encoded = encodeURIComponent(value || "")
60+
Object.entries(bindingMarkers).forEach(([marker, binding]) => {
61+
encoded = encoded.replace(marker, binding)
62+
})
63+
str += `${key}=${encoded}`
5064
}
5165
}
5266
return str

packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
const datasourceUrl = datasource?.config.url
348348
const qs = query?.fields.queryString
349349
breakQs = restUtils.breakQueryString(qs)
350+
console.log(breakQs)
350351
breakQs = runtimeToReadableMap(mergedBindings, breakQs)
351352
352353
const path = query.fields.path
@@ -708,6 +709,7 @@
708709
.url-block {
709710
display: flex;
710711
gap: var(--spacing-s);
712+
z-index: 200;
711713
}
712714
.verb {
713715
flex: 1;

packages/worker/src/api/controllers/global/self.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,15 @@ const addSessionAttributesToUser = ctx => {
8080
ctx.body.csrfToken = ctx.user.csrfToken
8181
}
8282

83-
/**
84-
* Remove the attributes that are session based from the current user,
85-
* so that stale values are not written to the db
86-
*/
87-
const removeSessionAttributesFromUser = ctx => {
88-
delete ctx.request.body.csrfToken
89-
delete ctx.request.body.account
90-
delete ctx.request.body.accountPortalAccess
91-
delete ctx.request.body.budibaseAccess
92-
delete ctx.request.body.license
83+
const sanitiseUserUpdate = ctx => {
84+
const allowed = ["firstName", "lastName", "password", "forceResetPassword"]
85+
const resp = {}
86+
for (let [key, value] of Object.entries(ctx.request.body)) {
87+
if (allowed.includes(key)) {
88+
resp[key] = value
89+
}
90+
}
91+
return resp
9392
}
9493

9594
exports.getSelf = async ctx => {
@@ -117,25 +116,23 @@ exports.updateSelf = async ctx => {
117116
const db = getGlobalDB()
118117
const user = await db.get(ctx.user._id)
119118
let passwordChange = false
120-
if (ctx.request.body.password) {
119+
120+
const userUpdateObj = sanitiseUserUpdate(ctx)
121+
if (userUpdateObj.password) {
121122
// changing password
122123
passwordChange = true
123-
ctx.request.body.password = await hash(ctx.request.body.password)
124+
userUpdateObj.password = await hash(userUpdateObj.password)
124125
// Log all other sessions out apart from the current one
125126
await platformLogout({
126127
ctx,
127128
userId: ctx.user._id,
128129
keepActiveSession: true,
129130
})
130131
}
131-
// don't allow sending up an ID/Rev, always use the existing one
132-
delete ctx.request.body._id
133-
delete ctx.request.body._rev
134-
removeSessionAttributesFromUser(ctx)
135132

136133
const response = await db.put({
137134
...user,
138-
...ctx.request.body,
135+
...userUpdateObj,
139136
})
140137
await userCache.invalidateUser(user._id)
141138
ctx.body = {

packages/worker/src/api/controllers/global/users.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
errors,
1515
events,
1616
tenancy,
17-
users as usersCore,
1817
} from "@budibase/backend-core"
1918
import { checkAnyUserExists } from "../../../utilities/users"
2019
import { groups as groupUtils } from "@budibase/pro"
@@ -148,9 +147,7 @@ export const bulkDelete = async (ctx: any) => {
148147
}
149148

150149
try {
151-
let response = await users.bulkDelete(userIds)
152-
153-
ctx.body = response
150+
ctx.body = await users.bulkDelete(userIds)
154151
} catch (err) {
155152
ctx.throw(err)
156153
}

0 commit comments

Comments
 (0)