salix/modules/account/back/methods/user-account/sync-all.js

37 lines
1011 B
JavaScript
Raw Normal View History

2020-10-31 20:16:58 +00:00
const SyncEngine = require('../../util/sync-engine');
module.exports = Self => {
Self.remoteMethod('syncAll', {
description: 'Synchronizes user database with LDAP and Samba',
http: {
2020-10-31 20:16:58 +00:00
path: `/syncAll`,
verb: 'PATCH'
}
});
Self.syncAll = async function() {
let $ = Self.app.models;
2020-11-02 18:58:07 +00:00
let engine = new SyncEngine();
await engine.init($);
2020-11-02 18:58:07 +00:00
let usersToSync = await engine.getUsers();
2020-10-31 20:16:58 +00:00
usersToSync = Array.from(usersToSync.values())
.sort((a, b) => a.localeCompare(b));
2020-10-31 20:16:58 +00:00
for (let user of usersToSync) {
try {
2020-10-31 20:16:58 +00:00
console.log(`Synchronizing user '${user}'`);
2020-11-02 18:58:07 +00:00
await engine.sync(user);
2020-10-31 20:16:58 +00:00
console.log(` -> '${user}' sinchronized`);
} catch (err) {
2020-10-31 20:16:58 +00:00
console.error(` -> '${user}' synchronization error:`, err.message);
}
}
2020-10-31 20:16:58 +00:00
2020-11-02 18:58:07 +00:00
await engine.deinit();
2020-10-31 20:16:58 +00:00
await $.RoleInherit.sync();
};
};