Fixing an issue with user metadata not always being present when user accessing app, causing weird issues.
This commit is contained in:
parent
b224b6bf45
commit
4794a5374e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue