Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 1x 1x 1x 1x 1x 1x 1x 1x | const _ = require('underscore');
const defaultAttributes = require('../configs/config.defaultAttributes');
const Group = require('../models/group');
const pickAttributes = require('./internal/service.pickAttributes');
const getGroupMembershipForDN = require('./service.getGroupMembershipForDn');
const getUserDistinguishedName = require('./internal/service.getUserDistinguishedName');
const log = require('./internal/service.log');
/**
* For the specified username, get all of the groups that the user is a member of.
*
* @public
* @param {Object} [opts] Optional LDAP query string parameters to execute. { scope: '', filter: '', attributes: [ '', '', ... ], sizeLimit: 0, timelimit: 0 }
* @param {String} username The username to retrieve membership information about.
* @param {Function} [callback] The callback to execute when completed. callback(err: {Object}, groups: {Array[Group]})
*/
function getGroupMembershipForUser(opts, username, callback) {
var self = this;
return new Promise((resolve, reject) => {
if (typeof (username) === 'function') {
callback = username;
username = opts;
opts = undefined;
}
log.trace('getGroupMembershipForUser(%j,%s)', opts, username);
getUserDistinguishedName.call(self, opts, username, function (err, dn) {
if (err) {
if (callback){
callback(err);
}
return reject(err);
}
if (!dn) {
log.warn('Could not find a distinguishedName for the specified username: "%s"', username);
if (callback){
callback();
}
return resolve([]);
}
getGroupMembershipForDN.call(self, opts, dn, function (err, groups) {
if (err) {
if (callback){
callback(err);
}
return reject(err);
}
var results = [];
_.each(groups, function (group) {
var result = new Group(pickAttributes(group, (opts || {}).attributes || defaultAttributes.group));
self.emit(result);
results.push(result);
});
if (callback){
callback(err, results);
}
return resolve(results);
});
});
});
};
module.exports = getGroupMembershipForUser; |