Merge pull request #2323 from Budibase/fix/martin-fixes
ensure user metadata is created before link documents are created
This commit is contained in:
commit
77b97d4105
|
@ -13,8 +13,9 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
value = e.detail
|
const isoString = e.detail.toISOString()
|
||||||
dispatch("change", e.detail)
|
value = isoString
|
||||||
|
dispatch("change", isoString)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
const CouchDB = require("../index")
|
const CouchDB = require("../index")
|
||||||
const { IncludeDocs, getLinkDocuments } = require("./linkUtils")
|
const { IncludeDocs, getLinkDocuments } = require("./linkUtils")
|
||||||
const { generateLinkID } = require("../utils")
|
const {
|
||||||
|
generateLinkID,
|
||||||
|
InternalTables,
|
||||||
|
getUserMetadataParams,
|
||||||
|
} = require("../utils")
|
||||||
const Sentry = require("@sentry/node")
|
const Sentry = require("@sentry/node")
|
||||||
const { FieldTypes, RelationshipTypes } = require("../../constants")
|
const { FieldTypes, RelationshipTypes } = require("../../constants")
|
||||||
|
|
||||||
|
@ -208,6 +212,19 @@ class LinkController {
|
||||||
const linkedTable = await this._db.get(field.tableId)
|
const linkedTable = await this._db.get(field.tableId)
|
||||||
const linkedSchema = linkedTable.schema[field.fieldName]
|
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
|
// iterate through the link IDs in the row field, see if any don't exist already
|
||||||
for (let linkId of rowField) {
|
for (let linkId of rowField) {
|
||||||
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
|
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
|
||||||
|
|
Loading…
Reference in New Issue