Added basic permissions

This commit is contained in:
Thaum
2015-02-02 12:11:57 +00:00
parent 786e7cd769
commit 18a870171a
2 changed files with 18 additions and 1 deletions

View File

@@ -184,7 +184,11 @@ Schemas.Character = new SimpleSchema({
deathSave: { type: Schemas.DeathSave },
time: { type: Number, min: 0, decimal: true, defaultValue: 0},
initiativeRoll: { type: Number, min: 0, max: 1, decimal: true, defaultValue: 0},
//TODO add permission stuff for owner, readers and writers
//permissions
owner: { type: String, regEx: SimpleSchema.RegEx.Id },
readers: { type: [String], regEx: SimpleSchema.RegEx.Id },
writers: { type: [String], regEx: SimpleSchema.RegEx.Id }
//TODO add per-character settings
});

View File

@@ -0,0 +1,13 @@
canEditCharacter = function(charId, userId){
userId = userId || Meteor.userId();
var char = Characters.findOne(charId, {fields: {owner: 1, writers: 1}});
if (!char) return false;
return (userId === char.owner || _.contains(char.writers, userId));
};
canViewCharacter = function(charId, userId){
userId = userId || Meteor.userId();
var char = Characters.findOne(charId, {fields: {owner: 1, writers: 1, readers: 1}});
if (!char) return false;
return (userId === char.owner || _.contains(char.writers, userId) || _.contains(char.readers, userId));
};