mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-23 12:57:26 +08:00
group model
This commit is contained in:
21
lib/model.js
21
lib/model.js
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user