From 7d3a51de9d8f68dfae638bdcd44ddc1466e4ad88 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sun, 11 Apr 2021 12:15:30 +0200 Subject: [PATCH] Moved ancestry setting responsibility to trusted code --- .../methods/insertProperty.js | 20 +++++++++++++++++-- .../forms/shared/propertyFormMixin.js | 11 +++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/imports/api/creature/creatureProperties/methods/insertProperty.js b/app/imports/api/creature/creatureProperties/methods/insertProperty.js index 010bbd2d..521b35e7 100644 --- a/app/imports/api/creature/creatureProperties/methods/insertProperty.js +++ b/app/imports/api/creature/creatureProperties/methods/insertProperty.js @@ -7,6 +7,7 @@ import { reorderDocs } from '/imports/api/parenting/order.js'; import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js'; import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js'; import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js'; +import { getAncestry } from '/imports/api/parenting/parenting.js'; const insertProperty = new ValidatedMethod({ name: 'creatureProperties.insert', @@ -16,9 +17,24 @@ const insertProperty = new ValidatedMethod({ numRequests: 5, timeInterval: 5000, }, - run({creatureProperty}) { - let rootCreature = getRootCreatureAncestor(creatureProperty); + run({creatureProperty, parentRef}) { + // get the new ancestry for the properties + let {parentDoc, ancestors} = getAncestry({parentRef}); + + // Check permission to edit + let rootCreature; + if (parentRef.collection === 'creatures'){ + rootCreature = parentDoc; + } else if (parentRef.collection === 'creatureProperties'){ + rootCreature = getRootCreatureAncestor(parentDoc); + } else { + throw `${parentRef.collection} is not a valid parent collection` + } assertEditPermission(rootCreature, this.userId); + + creatureProperty.parent = parentRef; + creatureProperty.ancestors = ancestors; + return insertPropertyWork({ property: creatureProperty, creature: rootCreature, diff --git a/app/imports/ui/properties/forms/shared/propertyFormMixin.js b/app/imports/ui/properties/forms/shared/propertyFormMixin.js index 389e40dd..7d5bd384 100644 --- a/app/imports/ui/properties/forms/shared/propertyFormMixin.js +++ b/app/imports/ui/properties/forms/shared/propertyFormMixin.js @@ -10,9 +10,14 @@ export default { }, }, mounted(){ - if (this.$refs.focusFirst && this.$refs.focusFirst.focus){ - setTimeout(() => this.$refs.focusFirst.focus(), 300); - } + // Don't autofocus on mobile, it brings up the on-screen keyboard + if (this.$vuetify.breakpoint.smAndDown) return; + + setTimeout(() => { + if (this.$refs.focusFirst && this.$refs.focusFirst.focus){ + this.$refs.focusFirst.focus() + } + }, 300); }, methods: { change(path, value, ack){