Moved ancestry setting responsibility to trusted code

This commit is contained in:
Stefan Zermatten
2021-04-11 12:15:30 +02:00
parent 0f37a49b95
commit 7d3a51de9d
2 changed files with 26 additions and 5 deletions

View File

@@ -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,

View File

@@ -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){