acl.getCurrent() handles groups.

This commit is contained in:
Julien Fontanet 2015-05-28 22:42:57 +02:00
parent aa1ca3be64
commit eb25cf65dd
2 changed files with 18 additions and 3 deletions

View File

@ -9,7 +9,7 @@ get.description = 'get existing ACLs'
// -------------------------------------------------------------------
export async function getCurrent () {
return await this.getAclsForSubject(this.session.get('user_id'))
return await this.getAclsForUser(this.session.get('user_id'))
}
getCurrent.permission = ''

View File

@ -165,8 +165,23 @@ export default class Xo extends EventEmitter {
await this._acls.delete(subjectId, objectId, action)
}
async getAclsForSubject (subjectId) {
return this._acls.get({ subject: subjectId })
async getAclsForUser (userId) {
const subjects = (await this.getUser(userId)).groups.concat(userId)
const acls = []
const pushAcls = (function (push) {
return function (entries) {
push.apply(acls, entries)
}
})(acls.push)
const {_acls: collection} = this
await Promise.all(map(
subjects,
subject => collection.get({subject}).then(pushAcls)
))
return acls
}
// TODO: remove when new collection.