group model

This commit is contained in:
Ritchie Martori
2011-11-24 00:37:31 -08:00
parent 1b7f0a5d4e
commit b6f77dd18f

View File

@@ -135,7 +135,7 @@ Model = module.exports = emitter.spawn({
remove: 'root',
create: 'root',
special: {
_id: 'root'
_id: {read: 'root', write: 'root'}
}
},
@@ -143,6 +143,7 @@ Model = module.exports = emitter.spawn({
if(action === 'write' && this.isNew()) action = 'create';
var permissions = this.allowed
, special = permissions.special
, rights = permissions[action]
, requiresUser = action === 'create' && rights === 'user'
, actor = this.actor()
@@ -150,6 +151,24 @@ Model = module.exports = emitter.spawn({
, model = this
;
if(special) {
Object.getOwnPropertyNames(special).forEach(function(key) {
var perms = special[key]
, right = perms[action]
, allowed = group === 'public' || group === right || root
;
if(!allowed) {
if(action === 'read') {
// TODO build select object where {key: 0}
delete model.attributes[key];
} else {
model.error('The current user cannot ' + action + ' the key: ', key, 'Not Allowed');
}
}
})
}
if(requiresUser && !actor) {
model.error('Only logged in users can ' + action);
fn();