Skip to content

Commit

Permalink
Merge pull request #9309 from RocketChat/hotfix/ldap-import
Browse files Browse the repository at this point in the history
[FIX] LDAP/AD is not importing all users
  • Loading branch information
rodrigok committed Jan 3, 2018
1 parent aa40d40 commit 5762032
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions packages/rocketchat-ldap/server/ldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = [];
}
});
Expand Down

0 comments on commit 5762032

Please sign in to comment.