Moved ancestry setting responsibility to trusted code
This commit is contained in:
@@ -7,6 +7,7 @@ import { reorderDocs } from '/imports/api/parenting/order.js';
|
|||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import { getAncestry } from '/imports/api/parenting/parenting.js';
|
||||||
|
|
||||||
const insertProperty = new ValidatedMethod({
|
const insertProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.insert',
|
name: 'creatureProperties.insert',
|
||||||
@@ -16,9 +17,24 @@ const insertProperty = new ValidatedMethod({
|
|||||||
numRequests: 5,
|
numRequests: 5,
|
||||||
timeInterval: 5000,
|
timeInterval: 5000,
|
||||||
},
|
},
|
||||||
run({creatureProperty}) {
|
run({creatureProperty, parentRef}) {
|
||||||
let rootCreature = getRootCreatureAncestor(creatureProperty);
|
// 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);
|
assertEditPermission(rootCreature, this.userId);
|
||||||
|
|
||||||
|
creatureProperty.parent = parentRef;
|
||||||
|
creatureProperty.ancestors = ancestors;
|
||||||
|
|
||||||
return insertPropertyWork({
|
return insertPropertyWork({
|
||||||
property: creatureProperty,
|
property: creatureProperty,
|
||||||
creature: rootCreature,
|
creature: rootCreature,
|
||||||
|
|||||||
@@ -10,9 +10,14 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted(){
|
mounted(){
|
||||||
if (this.$refs.focusFirst && this.$refs.focusFirst.focus){
|
// Don't autofocus on mobile, it brings up the on-screen keyboard
|
||||||
setTimeout(() => this.$refs.focusFirst.focus(), 300);
|
if (this.$vuetify.breakpoint.smAndDown) return;
|
||||||
}
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.$refs.focusFirst && this.$refs.focusFirst.focus){
|
||||||
|
this.$refs.focusFirst.focus()
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
change(path, value, ack){
|
change(path, value, ack){
|
||||||
|
|||||||
Reference in New Issue
Block a user