Merge pull request #1094 from Budibase/bug/user-row-issues
Fixing issues with user row updates + removing an error log from self hosting
This commit is contained in:
commit
6719e26d77
|
@ -57,13 +57,15 @@ exports.patch = async function(ctx) {
|
||||||
let row = await db.get(ctx.params.id)
|
let row = await db.get(ctx.params.id)
|
||||||
const table = await db.get(row.tableId)
|
const table = await db.get(row.tableId)
|
||||||
const patchfields = ctx.request.body
|
const patchfields = ctx.request.body
|
||||||
row = coerceRowValues(row, table)
|
|
||||||
|
|
||||||
|
// need to build up full patch fields before coerce
|
||||||
for (let key of Object.keys(patchfields)) {
|
for (let key of Object.keys(patchfields)) {
|
||||||
if (!table.schema[key]) continue
|
if (!table.schema[key]) continue
|
||||||
row[key] = patchfields[key]
|
row[key] = patchfields[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
row = coerceRowValues(row, table)
|
||||||
|
|
||||||
const validateResult = await validate({
|
const validateResult = await validate({
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
@ -89,6 +91,8 @@ exports.patch = async function(ctx) {
|
||||||
|
|
||||||
// Creation of a new user goes to the user controller
|
// Creation of a new user goes to the user controller
|
||||||
if (row.tableId === ViewNames.USERS) {
|
if (row.tableId === ViewNames.USERS) {
|
||||||
|
// the row has been updated, need to put it into the ctx
|
||||||
|
ctx.request.body = row
|
||||||
await usersController.update(ctx)
|
await usersController.update(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -157,6 +161,8 @@ exports.save = async function(ctx) {
|
||||||
|
|
||||||
// Creation of a new user goes to the user controller
|
// Creation of a new user goes to the user controller
|
||||||
if (row.tableId === ViewNames.USERS) {
|
if (row.tableId === ViewNames.USERS) {
|
||||||
|
// the row has been updated, need to put it into the ctx
|
||||||
|
ctx.request.body = row
|
||||||
await usersController.create(ctx)
|
await usersController.create(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,15 +64,13 @@ exports.create = async function(ctx) {
|
||||||
exports.update = async function(ctx) {
|
exports.update = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.user.appId)
|
const db = new CouchDB(ctx.user.appId)
|
||||||
const user = ctx.request.body
|
const user = ctx.request.body
|
||||||
const dbUser = await db.get(ctx.request.body._id)
|
|
||||||
if (user.password) {
|
if (user.password) {
|
||||||
user.password = await bcrypt.hash(user.password)
|
user.password = await bcrypt.hash(user.password)
|
||||||
} else {
|
} else {
|
||||||
delete user.password
|
delete user.password
|
||||||
}
|
}
|
||||||
const newData = { ...dbUser, ...user }
|
|
||||||
|
|
||||||
const response = await db.put(newData)
|
const response = await db.put(user)
|
||||||
user._rev = response.rev
|
user._rev = response.rev
|
||||||
|
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
|
|
@ -53,7 +53,8 @@ server.on("close", () => console.log("Server Closed"))
|
||||||
module.exports = server.listen(env.PORT || 4001, async () => {
|
module.exports = server.listen(env.PORT || 4001, async () => {
|
||||||
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
||||||
automations.init()
|
automations.init()
|
||||||
if (env.SELF_HOSTED) {
|
// only init the self hosting DB info in the Pouch, not needed in self hosting prod
|
||||||
|
if (!env.CLOUD) {
|
||||||
await selfhost.init()
|
await selfhost.init()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue