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,
|
...metadata,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
let response
|
||||||
// user didn't exist in app, don't pretend they do
|
// user didn't exist in app, don't pretend they do
|
||||||
if (user.roleId === BUILTIN_ROLE_IDS.PUBLIC) {
|
if (user.roleId === BUILTIN_ROLE_IDS.PUBLIC) {
|
||||||
ctx.body = {}
|
response = {}
|
||||||
}
|
}
|
||||||
// user has a role of some sort, return them
|
// user has a role of some sort, return them
|
||||||
else {
|
else if (err.status === 404) {
|
||||||
ctx.body = user
|
const metadata = {
|
||||||
|
_id: userId,
|
||||||
|
}
|
||||||
|
const dbResp = await db.put(metadata)
|
||||||
|
user._rev = dbResp.rev
|
||||||
|
response = user
|
||||||
|
} else {
|
||||||
|
response = user
|
||||||
}
|
}
|
||||||
|
ctx.body = response
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.body = user
|
ctx.body = user
|
||||||
|
|
|
@ -81,7 +81,9 @@ async function getFullLinkedDocs(ctx, appId, links) {
|
||||||
row => row.doc
|
row => row.doc
|
||||||
)
|
)
|
||||||
// convert the unique db rows back to a full list of linked rows
|
// 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
|
// need to handle users as specific cases
|
||||||
let [users, other] = partition(linked, linkRow =>
|
let [users, other] = partition(linked, linkRow =>
|
||||||
linkRow._id.startsWith(USER_METDATA_PREFIX)
|
linkRow._id.startsWith(USER_METDATA_PREFIX)
|
||||||
|
@ -172,13 +174,18 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
|
||||||
row[link.fieldName] = []
|
row[link.fieldName] = []
|
||||||
}
|
}
|
||||||
const linkedRow = linked.find(row => row._id === link.id)
|
const linkedRow = linked.find(row => row._id === link.id)
|
||||||
const linkedTableId =
|
if (linkedRow) {
|
||||||
linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
|
const linkedTableId =
|
||||||
const linkedTable = await getLinkedTable(db, linkedTableId, linkedTables)
|
linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
|
||||||
if (!linkedRow || !linkedTable) {
|
const linkedTable = await getLinkedTable(
|
||||||
continue
|
db,
|
||||||
|
linkedTableId,
|
||||||
|
linkedTables
|
||||||
|
)
|
||||||
|
if (linkedTable) {
|
||||||
|
row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
|
|
Loading…
Reference in New Issue