diff --git a/rpg-docs/Model/Character/Effects.js b/rpg-docs/Model/Character/Effects.js index cdf794fe..7a5c5620 100644 --- a/rpg-docs/Model/Character/Effects.js +++ b/rpg-docs/Model/Character/Effects.js @@ -5,8 +5,8 @@ Effects = new Mongo.Collection("effects"); * that modify their final value or presentation in some way */ Schemas.Effect = new SimpleSchema({ - charId: { - type: String, + charId: { + type: String, regEx: SimpleSchema.RegEx.Id }, name: { @@ -26,7 +26,7 @@ Schemas.Effect = new SimpleSchema({ }, calculation: { type: String, - optional: true, + optional: true, trim: false }, //indicates what the effect originated from @@ -52,57 +52,55 @@ Schemas.Effect = new SimpleSchema({ Effects.attachSchema(Schemas.Effect); -Characters.after.insert(function (userId, char) { - if(Meteor.isServer){ - Effects.insert({ - charId: char._id, - type: "inate", - name: "Constitution modifier for each level", - stat: "hitPoints", - operation: "add", - calculation: "level * constitutionMod", - parent: { - id: char._id, - collection: "Characters" - } - }); - Effects.insert({ - charId: char._id, - type: "inate", - name: "Proficiency bonus by level", - stat: "proficiencyBonus", - operation: "add", - calculation: "floor(level / 4 + 1.75)", - parent: { - id: char._id, - collection: "Characters" - } - }); - Effects.insert({ - charId: char._id, - type: "inate", - name: "Dexterity Armor Bonus", - stat: "armor", - operation: "add", - calculation: "dexterityArmor", - parent: { - id: char._id, - collection: "Characters" - } - }); - Effects.insert({ - charId: char._id, - type: "inate", - name: "Natural Armor", - stat: "armor", - operation: "base", - value: 10, - parent: { - id: char._id, - collection: "Characters" - } - }); - } +if(Meteor.isServer) Characters.after.insert(function (userId, char) { + Effects.insert({ + charId: char._id, + type: "inate", + name: "Constitution modifier for each level", + stat: "hitPoints", + operation: "add", + calculation: "level * constitutionMod", + parent: { + id: char._id, + collection: "Characters" + } + }); + Effects.insert({ + charId: char._id, + type: "inate", + name: "Proficiency bonus by level", + stat: "proficiencyBonus", + operation: "add", + calculation: "floor(level / 4 + 1.75)", + parent: { + id: char._id, + collection: "Characters" + } + }); + Effects.insert({ + charId: char._id, + type: "inate", + name: "Dexterity Armor Bonus", + stat: "armor", + operation: "add", + calculation: "dexterityArmor", + parent: { + id: char._id, + collection: "Characters" + } + }); + Effects.insert({ + charId: char._id, + type: "inate", + name: "Natural Armor", + stat: "armor", + operation: "base", + value: 10, + parent: { + id: char._id, + collection: "Characters" + } + }); }); Effects.attachBehaviour('softRemovable'); diff --git a/rpg-docs/client/views/character/effects/effectEdit/effectEdit.html b/rpg-docs/client/views/character/effects/effectEdit/effectEdit.html index 8c048760..eacd65a1 100644 --- a/rpg-docs/client/views/character/effects/effectEdit/effectEdit.html +++ b/rpg-docs/client/views/character/effects/effectEdit/effectEdit.html @@ -1,8 +1,8 @@ \ No newline at end of file + diff --git a/rpg-docs/lib/constants/characterAssetAllowDeny.js b/rpg-docs/lib/constants/characterAssetAllowDeny.js index c6069db6..4d97e487 100644 --- a/rpg-docs/lib/constants/characterAssetAllowDeny.js +++ b/rpg-docs/lib/constants/characterAssetAllowDeny.js @@ -16,9 +16,16 @@ CHARACTER_SUBSCHEMA_ALLOW = { }; CHARACTER_SUBSCHEMA_DENY = { - update: function (userId, docs, fields, modifier) { - // can't change character - return _.contains(fields, 'charId'); + update: function (userId, doc, fields, modifier) { + if(modifier && modifier.$set && modifier.$set.charId){ + var id1 = doc.charId; + var char1 = Characters.findOne( id1, { fields: {owner: 1, writers: 1} } ) || {}; + var char1Allowed = ( userId && char1.owner === userId || _.contains(char1.writers, userId) ); + var id2 = modifier.$set.charId; + var char2 = Characters.findOne( id2, { fields: {owner: 1, writers: 1} } ) || {}; + var char2Allowed = ( userId && char1.owner === userId || _.contains(char1.writers, userId) ); + return (!char1Allowed || !char2Allowed); + } }, fetch: ["charId"] }; diff --git a/rpg-docs/lib/functions/parenting.js b/rpg-docs/lib/functions/parenting.js index 9b472c20..fad540d3 100644 --- a/rpg-docs/lib/functions/parenting.js +++ b/rpg-docs/lib/functions/parenting.js @@ -130,7 +130,7 @@ var checkPermission = function(userId, charId){ var cascadeSoftRemove = function(id, removedWithId){ _.each(childCollections, function(treeCollection){ - treeCollection.update({"parent.id": id}, {$set: {removed: true, removedWith: removedWithId}}); + treeCollection.update({"parent.id": id}, {$set: {removed: true, removedWith: removedWithId}}, {multi: true}); treeCollection.find({"parent.id": id}).forEach(function(doc){ cascadeSoftRemove(doc._id, removedWithId); }); @@ -158,7 +158,7 @@ Meteor.methods({ var collection = Mongo.Collection.get(collectionName); collection.restore(id); _.each(childCollections, function(treeCollection){ - treeCollection.update({removedWith: id, removed: true}, { $unset: {removed: true, removedWith: ""} }); + treeCollection.update({removedWith: id, removed: true}, { $unset: {removed: true, removedWith: ""} }, {multi: true}); }); }, updateChildren: function (parent, modifier, limitToInheritance) {