Merge pull request #2323 from Budibase/fix/martin-fixes

ensure user metadata is created before link documents are created
This commit is contained in:
Kevin Åberg Kultalahti 2021-08-13 10:01:05 +02:00 committed by GitHub
commit 2a3a5956a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -13,8 +13,9 @@
const dispatch = createEventDispatcher()
const onChange = e => {
value = e.detail
dispatch("change", e.detail)
const isoString = e.detail.toISOString()
value = isoString
dispatch("change", isoString)
}
</script>

View File

@ -1,6 +1,10 @@
const CouchDB = require("../index")
const { IncludeDocs, getLinkDocuments } = require("./linkUtils")
const { generateLinkID } = require("../utils")
const {
generateLinkID,
InternalTables,
getUserMetadataParams,
} = require("../utils")
const Sentry = require("@sentry/node")
const { FieldTypes, RelationshipTypes } = require("../../constants")
@ -208,6 +212,19 @@ class LinkController {
const linkedTable = await this._db.get(field.tableId)
const linkedSchema = linkedTable.schema[field.fieldName]
// We need to map the global users to metadata in each app for relationships
if (field.tableId === InternalTables.USER_METADATA) {
const users = await this._db.allDocs(getUserMetadataParams(null, {}))
const metadataRequired = rowField.filter(
userId => !users.rows.some(user => user.id === userId)
)
// ensure non-existing user metadata is created in the app DB
await this._db.bulkDocs(
metadataRequired.map(userId => ({ _id: userId }))
)
}
// iterate through the link IDs in the row field, see if any don't exist already
for (let linkId of rowField) {
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {