From eb25cf65ddace5b39f967480b73a9aa1fea4cc05 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 28 May 2015 22:42:57 +0200 Subject: [PATCH] acl.getCurrent() handles groups. --- src/api/acl.js | 2 +- src/xo.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/api/acl.js b/src/api/acl.js index d153f155c..96003a466 100644 --- a/src/api/acl.js +++ b/src/api/acl.js @@ -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 = '' diff --git a/src/xo.js b/src/xo.js index 8f87ec66a..9056af57e 100644 --- a/src/xo.js +++ b/src/xo.js @@ -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.