Added basic permissions
This commit is contained in:
@@ -184,7 +184,11 @@ Schemas.Character = new SimpleSchema({
|
|||||||
deathSave: { type: Schemas.DeathSave },
|
deathSave: { type: Schemas.DeathSave },
|
||||||
time: { type: Number, min: 0, decimal: true, defaultValue: 0},
|
time: { type: Number, min: 0, decimal: true, defaultValue: 0},
|
||||||
initiativeRoll: { type: Number, min: 0, max: 1, 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
|
//TODO add per-character settings
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
13
rpg-docs/lib/functions/permissions.js
Normal file
13
rpg-docs/lib/functions/permissions.js
Normal 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));
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user