2020-10-31 20:16:58 +00:00
|
|
|
|
|
|
|
const SyncEngine = require('../../util/sync-engine');
|
2020-10-30 23:02:27 +00:00
|
|
|
|
|
|
|
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`,
|
2020-10-30 23:02:27 +00:00
|
|
|
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-10-30 23:02:27 +00:00
|
|
|
|
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-30 23:02:27 +00:00
|
|
|
|
2020-10-31 20:16:58 +00:00
|
|
|
for (let user of usersToSync) {
|
2020-10-30 23:02:27 +00:00
|
|
|
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`);
|
2020-10-30 23:02:27 +00:00
|
|
|
} catch (err) {
|
2020-10-31 20:16:58 +00:00
|
|
|
console.error(` -> '${user}' synchronization error:`, err.message);
|
2020-10-30 23:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
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();
|
2020-10-30 23:02:27 +00:00
|
|
|
};
|
|
|
|
};
|