Skip to content

Commit

Permalink
Fixing issue introduced by fix for #7683 - encoding the query string …
Browse files Browse the repository at this point in the history
…caused handlebars statements to break, this rectifies that.
  • Loading branch information
mike12345567 committed Sep 15, 2022
1 parent e0cf125 commit d35864b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/bbui/src/Tooltip/TooltipWrapper.svelte
Expand Up @@ -47,7 +47,7 @@
display: flex;
justify-content: center;
top: 15px;
z-index: 100;
z-index: 200;
width: 160px;
}
.icon {
Expand Down
12 changes: 5 additions & 7 deletions packages/builder/src/builderStore/dataBinding.js
Expand Up @@ -9,14 +9,14 @@ import {
import { store } from "builderStore"
import {
queries as queriesStores,
tables as tablesStore,
roles as rolesStore,
tables as tablesStore,
} from "stores/backend"
import {
makePropSafe,
isJSBinding,
decodeJSBinding,
encodeJSBinding,
isJSBinding,
makePropSafe,
} from "@budibase/string-templates"
import { TableNames } from "../constants"
import { JSONUtils } from "@budibase/frontend-core"
Expand Down Expand Up @@ -118,8 +118,7 @@ export const readableToRuntimeMap = (bindings, ctx) => {
return {}
}
return Object.keys(ctx).reduce((acc, key) => {
let parsedQuery = readableToRuntimeBinding(bindings, ctx[key])
acc[key] = parsedQuery
acc[key] = readableToRuntimeBinding(bindings, ctx[key])
return acc
}, {})
}
Expand All @@ -132,8 +131,7 @@ export const runtimeToReadableMap = (bindings, ctx) => {
return {}
}
return Object.keys(ctx).reduce((acc, key) => {
let parsedQuery = runtimeToReadableBinding(bindings, ctx[key])
acc[key] = parsedQuery
acc[key] = runtimeToReadableBinding(bindings, ctx[key])
return acc
}, {})
}
Expand Down
18 changes: 16 additions & 2 deletions packages/builder/src/helpers/data/utils.js
@@ -1,4 +1,5 @@
import { IntegrationTypes } from "constants/backend"
import { findHBSBlocks } from "@budibase/string-templates"

export function schemaToFields(schema) {
const response = {}
Expand Down Expand Up @@ -31,7 +32,8 @@ export function breakQueryString(qs) {
let paramObj = {}
for (let param of params) {
const split = param.split("=")
paramObj[split[0]] = split.slice(1).join("=")
console.log(split[1])
paramObj[split[0]] = decodeURIComponent(split.slice(1).join("="))
}
return paramObj
}
Expand All @@ -46,7 +48,19 @@ export function buildQueryString(obj) {
if (str !== "") {
str += "&"
}
str += `${key}=${encodeURIComponent(value || "")}`
const bindings = findHBSBlocks(value)
let count = 0
const bindingMarkers = {}
bindings.forEach(binding => {
const marker = `BINDING...${count++}`
value = value.replace(binding, marker)
bindingMarkers[marker] = binding
})
let encoded = encodeURIComponent(value || "")
Object.entries(bindingMarkers).forEach(([marker, binding]) => {
encoded = encoded.replace(marker, binding)
})
str += `${key}=${encoded}`
}
}
return str
Expand Down
Expand Up @@ -347,6 +347,7 @@
const datasourceUrl = datasource?.config.url
const qs = query?.fields.queryString
breakQs = restUtils.breakQueryString(qs)
console.log(breakQs)
breakQs = runtimeToReadableMap(mergedBindings, breakQs)
const path = query.fields.path
Expand Down Expand Up @@ -708,6 +709,7 @@
.url-block {
display: flex;
gap: var(--spacing-s);
z-index: 200;
}
.verb {
flex: 1;
Expand Down
31 changes: 14 additions & 17 deletions packages/worker/src/api/controllers/global/self.js
Expand Up @@ -80,16 +80,15 @@ const addSessionAttributesToUser = ctx => {
ctx.body.csrfToken = ctx.user.csrfToken
}

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

exports.getSelf = async ctx => {
Expand Down Expand Up @@ -117,25 +116,23 @@ exports.updateSelf = async ctx => {
const db = getGlobalDB()
const user = await db.get(ctx.user._id)
let passwordChange = false
if (ctx.request.body.password) {

const userUpdateObj = sanitiseUserUpdate(ctx)
if (userUpdateObj.password) {
// changing password
passwordChange = true
ctx.request.body.password = await hash(ctx.request.body.password)
userUpdateObj.password = await hash(userUpdateObj.password)
// Log all other sessions out apart from the current one
await platformLogout({
ctx,
userId: ctx.user._id,
keepActiveSession: true,
})
}
// don't allow sending up an ID/Rev, always use the existing one
delete ctx.request.body._id
delete ctx.request.body._rev
removeSessionAttributesFromUser(ctx)

const response = await db.put({
...user,
...ctx.request.body,
...userUpdateObj,
})
await userCache.invalidateUser(user._id)
ctx.body = {
Expand Down
5 changes: 1 addition & 4 deletions packages/worker/src/api/controllers/global/users.ts
Expand Up @@ -14,7 +14,6 @@ import {
errors,
events,
tenancy,
users as usersCore,
} from "@budibase/backend-core"
import { checkAnyUserExists } from "../../../utilities/users"
import { groups as groupUtils } from "@budibase/pro"
Expand Down Expand Up @@ -148,9 +147,7 @@ export const bulkDelete = async (ctx: any) => {
}

try {
let response = await users.bulkDelete(userIds)

ctx.body = response
ctx.body = await users.bulkDelete(userIds)
} catch (err) {
ctx.throw(err)
}
Expand Down

0 comments on commit d35864b

Please sign in to comment.