1
0
Fork 0
mirror of synced 2024-09-28 15:21:28 +12:00

Fixing an issue with user metadata not always being present when user accessing app, causing weird issues.

This commit is contained in:
mike12345567 2021-10-21 17:23:10 +01:00
parent b224b6bf45
commit 4794a5374e
2 changed files with 26 additions and 10 deletions

View file

@ -28,14 +28,23 @@ exports.fetchSelf = async ctx => {
...metadata,
})
} catch (err) {
let response
// user didn't exist in app, don't pretend they do
if (user.roleId === BUILTIN_ROLE_IDS.PUBLIC) {
ctx.body = {}
response = {}
}
// user has a role of some sort, return them
else {
ctx.body = user
else if (err.status === 404) {
const metadata = {
_id: userId,
}
const dbResp = await db.put(metadata)
user._rev = dbResp.rev
response = user
} else {
response = user
}
ctx.body = response
}
} else {
ctx.body = user

View file

@ -81,7 +81,9 @@ async function getFullLinkedDocs(ctx, appId, links) {
row => row.doc
)
// convert the unique db rows back to a full list of linked rows
const linked = linkedRowIds.map(id => dbRows.find(row => row._id === id))
const linked = linkedRowIds
.map(id => dbRows.find(row => row && row._id === id))
.filter(row => row != null)
// need to handle users as specific cases
let [users, other] = partition(linked, linkRow =>
linkRow._id.startsWith(USER_METDATA_PREFIX)
@ -172,13 +174,18 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
row[link.fieldName] = []
}
const linkedRow = linked.find(row => row._id === link.id)
const linkedTableId =
linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
const linkedTable = await getLinkedTable(db, linkedTableId, linkedTables)
if (!linkedRow || !linkedTable) {
continue
if (linkedRow) {
const linkedTableId =
linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
const linkedTable = await getLinkedTable(
db,
linkedTableId,
linkedTables
)
if (linkedTable) {
row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
}
}
row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
}
}
return rows