Merge pull request #2847 from Budibase/fix/2665
Fix created by/updated by auto columns breaking public forms
This commit is contained in:
commit
5a203d7b7d
|
@ -7,14 +7,19 @@ if (env.POSTHOG_TOKEN && env.ENABLE_ANALYTICS && !env.SELF_HOSTED) {
|
||||||
posthogClient = new PostHog(env.POSTHOG_TOKEN)
|
posthogClient = new PostHog(env.POSTHOG_TOKEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.isEnabled = async function (ctx) {
|
exports.isEnabled = async ctx => {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
|
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.endUserPing = async (ctx, next) => {
|
exports.endUserPing = async ctx => {
|
||||||
if (!posthogClient) return next()
|
if (!posthogClient) {
|
||||||
|
ctx.body = {
|
||||||
|
ping: false,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
posthogClient.capture("budibase:end_user_ping", {
|
posthogClient.capture("budibase:end_user_ping", {
|
||||||
userId: ctx.user && ctx.user._id,
|
userId: ctx.user && ctx.user._id,
|
||||||
|
|
|
@ -3,7 +3,8 @@ const controller = require("../controllers/analytics")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router.get("/api/analytics", controller.isEnabled)
|
router
|
||||||
router.post("/api/analytics/ping", controller.endUserPing)
|
.get("/api/analytics", controller.isEnabled)
|
||||||
|
.post("/api/analytics/ping", controller.endUserPing)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -99,6 +99,7 @@ function processAutoColumn(
|
||||||
row,
|
row,
|
||||||
opts = { reprocessing: false, noAutoRelationships: false }
|
opts = { reprocessing: false, noAutoRelationships: false }
|
||||||
) {
|
) {
|
||||||
|
let noUser = !user || !user.userId
|
||||||
let now = new Date().toISOString()
|
let now = new Date().toISOString()
|
||||||
// if a row doesn't have a revision then it doesn't exist yet
|
// if a row doesn't have a revision then it doesn't exist yet
|
||||||
const creating = !row._rev
|
const creating = !row._rev
|
||||||
|
@ -108,7 +109,12 @@ function processAutoColumn(
|
||||||
}
|
}
|
||||||
switch (schema.subtype) {
|
switch (schema.subtype) {
|
||||||
case AutoFieldSubTypes.CREATED_BY:
|
case AutoFieldSubTypes.CREATED_BY:
|
||||||
if (creating && !opts.reprocessing && !opts.noAutoRelationships) {
|
if (
|
||||||
|
creating &&
|
||||||
|
!opts.reprocessing &&
|
||||||
|
!opts.noAutoRelationships &&
|
||||||
|
!noUser
|
||||||
|
) {
|
||||||
row[key] = [user.userId]
|
row[key] = [user.userId]
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -118,7 +124,7 @@ function processAutoColumn(
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case AutoFieldSubTypes.UPDATED_BY:
|
case AutoFieldSubTypes.UPDATED_BY:
|
||||||
if (!opts.reprocessing && !opts.noAutoRelationships) {
|
if (!opts.reprocessing && !opts.noAutoRelationships && !noUser) {
|
||||||
row[key] = [user.userId]
|
row[key] = [user.userId]
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue