added update method to library nodes
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import schema from '/imports/api/schema.js';
|
import schema from '/imports/api/schema.js';
|
||||||
import ChildSchema from '/imports/api/creature/parenting/ChildSchema.js';
|
import ChildSchema from '/imports/api/creature/parenting/ChildSchema.js';
|
||||||
import librarySchemas from '/imports/api/library/librarySchemas.js';
|
import librarySchemas from '/imports/api/library/librarySchemas.js';
|
||||||
|
import Libraries from '/imports/api/library/Libraries.js';
|
||||||
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import getModifierFields from '/imports/api/getModifierFields.js';
|
||||||
|
|
||||||
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
||||||
|
|
||||||
@@ -50,3 +53,31 @@ for (let key in librarySchemas){
|
|||||||
|
|
||||||
export default LibraryNodes;
|
export default LibraryNodes;
|
||||||
export { LibraryNodeSchema };
|
export { LibraryNodeSchema };
|
||||||
|
|
||||||
|
function getLibrary(node){
|
||||||
|
if (!node) throw new Meteor.Error('No node provided');
|
||||||
|
return Libraries.findOne(node.ancestors[0].id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertNodeEditPermission(node, userId){
|
||||||
|
let lib = getLibrary(node);
|
||||||
|
return assertEditPermission(lib, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateNode = new ValidatedMethod({
|
||||||
|
name: 'LibraryNodes.methods.update',
|
||||||
|
validate({_id, update}){
|
||||||
|
let fields = getModifierFields(update);
|
||||||
|
return !fields.hasAny([
|
||||||
|
'libraryNodeType',
|
||||||
|
'order',
|
||||||
|
'parent',
|
||||||
|
'ancestors',
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
run({_id, update}) {
|
||||||
|
let node = LibraryNodes.findOne(_id);
|
||||||
|
assertNodeEditPermission(node, this.userId);
|
||||||
|
return LibraryNodes.update(_id, update);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ function assertIdValid(userId){
|
|||||||
throw new Meteor.Error("Permission denied",
|
throw new Meteor.Error("Permission denied",
|
||||||
"No user ID given for edit permission check");
|
"No user ID given for edit permission check");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function assertdocExists(doc){
|
function assertdocExists(doc){
|
||||||
if (!doc){
|
if (!doc){
|
||||||
throw new Meteor.Error("Edit permission denied",
|
throw new Meteor.Error("Edit permission denied",
|
||||||
`No doc exists with the given id: ${charId}`);
|
`No doc exists with the given id: ${charId}`);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function assertOwnership(doc, userId){
|
export function assertOwnership(doc, userId){
|
||||||
assertIdValid(userId);
|
assertIdValid(userId);
|
||||||
@@ -34,7 +34,7 @@ export function assertEditPermission(doc, userId) {
|
|||||||
throw new Meteor.Error("Edit permission denied",
|
throw new Meteor.Error("Edit permission denied",
|
||||||
`You do not have permission to edit this character`);
|
`You do not have permission to edit this character`);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function assertViewPermission(doc, userId) {
|
export function assertViewPermission(doc, userId) {
|
||||||
assertIdValid(userId);
|
assertIdValid(userId);
|
||||||
@@ -50,4 +50,4 @@ export function assertViewPermission(doc, userId) {
|
|||||||
throw new Meteor.Error("View permission denied",
|
throw new Meteor.Error("View permission denied",
|
||||||
`You do not have permission to view this character`);
|
`You do not have permission to view this character`);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user