add endpoint to add spells

This commit is contained in:
Andrew Zhu
2019-02-05 13:59:55 -08:00
parent 612575d0e6
commit fedda62c7c
3 changed files with 32 additions and 6 deletions

View File

@@ -12,19 +12,20 @@ Meteor.methods({
CHARACTER_SUBSCHEMA_ALLOW = {
// the user must be logged in, and the user must be a writer of the character
// or we must be the server
insert: function(userId, doc) {
var char = Characters.findOne(
doc.charId,
{fields: {owner: 1, writers: 1}}
);
return (userId && char.owner === userId || _.contains(char.writers, userId));
return (userId && char.owner === userId || _.contains(char.writers, userId) || Meteor.isServer);
},
update: function(userId, doc, fields, modifier) {
var char = Characters.findOne(
doc.charId,
{fields: {owner: 1, writers: 1}}
);
return (userId && char.owner === userId || _.contains(char.writers, userId));
return (userId && char.owner === userId || _.contains(char.writers, userId) || Meteor.isServer);
},
remove: function(userId, doc) {
var char = Characters.findOne(
@@ -32,7 +33,7 @@ CHARACTER_SUBSCHEMA_ALLOW = {
{fields: {owner: 1, writers: 1}}
);
if (!char) return true;
return userId && char.owner === userId || _.contains(char.writers, userId);
return userId && char.owner === userId || _.contains(char.writers, userId) || Meteor.isServer;
},
fetch: ["charId"],
};

View File

@@ -132,6 +132,9 @@ makeParent = function(collection, donatedKeys){
};
var checkPermission = function(userId, charId){
if (Meteor.isServer) { // we always trust server
return true;
}
var char = Characters.findOne(charId, {fields: {owner: 1, writers: 1}});
if (!char)
throw new Meteor.Error("Access Denied, no charId",