[FIX] LDAP/AD is not importing all users

LDAP/AD is only importing multiple of 500 users, the internal pagination system is not processing the rest of the records.
pull/9309/head
Rodrigo Nascimento 8 years ago
parent d7e0e70c37
commit cfea5288d8
No known key found for this signature in database
GPG Key ID: CFCE33B7B01AC335
  1. 56
      packages/rocketchat-ldap/server/ldap.js

@ -371,6 +371,17 @@ export default class LDAP {
searchAllPaged(BaseDN, options, page) {
this.bindIfNecessary();
const processPage = ({entries, title, end, next}) => {
logger.search.info(title);
// Force LDAP idle to wait the record processing
this.client._updateIdle(true);
page(null, entries, {end, next: () => {
// Reset idle timer
this.client._updateIdle();
next && next();
}});
};
this.client.search(BaseDN, options, (error, res) => {
if (error) {
logger.search.error(error);
@ -392,33 +403,42 @@ export default class LDAP {
entries.push(this.extractLdapEntryData(entry));
if (entries.length >= internalPageSize) {
logger.search.info('Internal Page');
this.client._updateIdle(true);
page(null, entries, {end: false, next: () => {
// Reset idle timer
this.client._updateIdle();
}});
processPage({
entries,
title: 'Internal Page',
end: false
});
entries = [];
}
});
res.on('page', (result, next) => {
if (!next) {
logger.search.debug('Final Page');
this.client._updateIdle(true);
page(null, entries, {end: true, next: () => {
// Reset idle timer
this.client._updateIdle();
}});
processPage({
entries,
title: 'Final Page',
end: true
});
} else if (entries.length) {
logger.search.info('Page');
// Force LDAP idle to wait the record processing
this.client._updateIdle(true);
page(null, entries, {end: !next, next: () => {
// Reset idle timer
this.client._updateIdle();
next();
}});
processPage({
entries,
title: 'Page',
end: false,
next
});
entries = [];
}
});
res.on('end', () => {
if (entries.length) {
processPage({
entries,
title: 'Final Page',
end: true
});
entries = [];
}
});

Loading…
Cancel
Save