WIP: #5770 - Sync Groups Samba #1946
|
@ -188,7 +188,8 @@ module.exports = Self => {
|
|||
|
||||
class SambaHelper {
|
||||
constructor(ctx) {
|
||||
Object.assign(this, ctx);
|
||||
const {sambaTool, verifyCert, adPassword, adController} = ctx;
|
||||
Object.assign(this, {...ctx, verifyCert, adPassword, adController, sambaTool});
|
||||
}
|
||||
async getRoles() {
|
||||
this.roles = (await app.models.VnRole.find({
|
||||
|
@ -255,6 +256,9 @@ class SambaHelper {
|
|||
addMembers(role, user) {
|
||||
return this.sambaTool('group', ['addmembers', role, user]);
|
||||
}
|
||||
editGroup(role, descriptrion = '') {
|
||||
return this.sambaTool('group', ['edit', `${role}`, '--editor=\'vi\'']);
|
||||
}
|
||||
|
||||
handleRoleMembers(users) {
|
||||
if (users.length === 0) return [];
|
||||
|
@ -309,14 +313,13 @@ class SambaHelper {
|
|||
for (const role of rolesKeys) {
|
||||
const exists = sambaCurrentGroups.get(role);
|
||||
if (!exists)
|
||||
this.rolesToHandler.toInsert.push(role);
|
||||
if (exists && exists.description !== this.roles.get(role).description)
|
||||
this.rolesToHandler.toUpdate.push(role);
|
||||
this.rolesToInsert.push(role);
|
||||
if (exists)
|
||||
this.rolesToUpdate.push(role);
|
||||
}
|
||||
// Encontrar elementos a eliminar
|
||||
this.rolesToDelete = differences(sambaRolesKeys, rolesKeys);
|
||||
|
||||
this.users.set('group1', ['employee']);
|
||||
if (this.rolesToDelete.length > 0) {
|
||||
// PROCEDIMIENTO PARA ELIMINAR ROLES
|
||||
const resultsRoleDelete = await Promise.all(
|
||||
|
@ -331,6 +334,7 @@ class SambaHelper {
|
|||
this.rolesToInsert.map(role => this.addRole(this.roles.get(role))));
|
||||
printResults(resultsRoleInsert);
|
||||
}
|
||||
// const edit = await this.editGroup('$developer');
|
||||
|
||||
if (this.rolesToUpdate.length > 0) {
|
||||
for await (const role of this.rolesToUpdate) {
|
||||
|
@ -344,26 +348,25 @@ class SambaHelper {
|
|||
const ldapMembersGroups = await this.getMembers();
|
||||
// OBTENER USUARIOS Y SUS ROLES
|
||||
if (
|
||||
this.rolesToDelete.length > 0 ||
|
||||
this.rolesToInsert.length > 0 ||
|
||||
this.rolesToInsert.length > 0 ||
|
||||
this.rolesToUpdate.length > 0)
|
||||
await this.getUsers();
|
||||
|
||||
// PROCEDIMIENTO PARA ELIMINAR USUARIOS ASOCIADOS AL ROL
|
||||
if (this.rolesToDelete.length > 0) {
|
||||
let usersToUngroup = this.rolesToDelete.flatMap(role => {
|
||||
const exist = this.users.get(role);
|
||||
// if (this.rolesToDelete.length > 0) {
|
||||
// let usersToUngroup = this.rolesToDelete.flatMap(role => {
|
||||
// const exist = this.users.get(role);
|
||||
|
||||
if (exist) {
|
||||
return this.users.get(role)?.map(
|
||||
user => this.removeMembers(role, user)
|
||||
);
|
||||
} else return [];
|
||||
}
|
||||
);
|
||||
const resultsUsersUngroup = await Promise.all(usersToUngroup);
|
||||
printResults(resultsUsersUngroup);
|
||||
}
|
||||
// if (exist) {
|
||||
// return this.users.get(role)?.map(
|
||||
// user => this.removeMembers(role, user)
|
||||
// );
|
||||
// } else return [];
|
||||
// }
|
||||
// );
|
||||
// const resultsUsersUngroup = await Promise.all(usersToUngroup);
|
||||
// printResults(resultsUsersUngroup);
|
||||
// }
|
||||
if (this.rolesToInsert.length > 0) {
|
||||
// PROCEDIMIENTO PARA INSERTAR USUARIOS ASOCIADOS AL ROL
|
||||
let usersToGroup = this.rolesToInsert.flatMap(role => this.users.get(role).map(
|
||||
|
|
Loading…
Reference in New Issue