Formatting.

This commit is contained in:
mike12345567 2021-06-08 16:11:46 +01:00
parent 33184be064
commit b05c67e8b5
3 changed files with 23 additions and 21 deletions

View File

@ -4,9 +4,7 @@ const {
getUserMetadataParams,
} = require("../../db/utils")
const { InternalTables } = require("../../db/utils")
const {
addAppRoleToUser,
} = require("../../utilities/workerRequests")
const { addAppRoleToUser } = require("../../utilities/workerRequests")
const { getGlobalUsers, getGlobalUser } = require("../../utilities/global")
const { getFullUser } = require("../../utilities/users")

View File

@ -11,10 +11,7 @@ const {
const { flatten } = require("lodash")
const CouchDB = require("../../db")
const { FieldTypes } = require("../../constants")
const {
getMultiIDParams,
USER_METDATA_PREFIX,
} = require("../../db/utils")
const { getMultiIDParams, USER_METDATA_PREFIX } = require("../../db/utils")
const { partition } = require("lodash")
const { getGlobalUsers } = require("../../utilities/global")
@ -70,20 +67,21 @@ async function getFullLinkedDocs(appId, links) {
row => row.doc
)
// need to handle users as specific cases
let [users, other] = partition(linked, linkRow => linkRow._id.startsWith(USER_METDATA_PREFIX))
let [users, other] = partition(linked, linkRow =>
linkRow._id.startsWith(USER_METDATA_PREFIX)
)
const globalUsers = await getGlobalUsers(appId, users)
users = users.map(user => {
const globalUser = globalUsers.find(globalUser => globalUser && user._id.includes(globalUser._id))
const globalUser = globalUsers.find(
globalUser => globalUser && user._id.includes(globalUser._id)
)
return {
...globalUser,
// doing user second overwrites the id and rev (always metadata)
...user,
}
})
return [
...other,
...users,
]
return [...other, ...users]
}
/**

View File

@ -43,11 +43,17 @@ exports.getGlobalUsers = async (appId = null, users = null) => {
row => row.doc
)
} else {
globalUsers = (await db.allDocs(getGlobalUserParams(null,{
globalUsers = (
await db.allDocs(
getGlobalUserParams(null, {
include_docs: true,
}))).rows.map(row => row.doc)
})
)
).rows.map(row => row.doc)
}
globalUsers = globalUsers.filter(user => user != null).map(user => {
globalUsers = globalUsers
.filter(user => user != null)
.map(user => {
delete user.password
return user
})