From 3e00a69108e2476b9e7996487315d94a368f4523 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sat, 11 May 2024 22:21:54 +0200 Subject: [PATCH] test(samba): refs #5770 solid concept(2) --- modules/account/back/models/samba-config.js | 43 +++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/account/back/models/samba-config.js b/modules/account/back/models/samba-config.js index 0344d467ba..810102f5ba 100644 --- a/modules/account/back/models/samba-config.js +++ b/modules/account/back/models/samba-config.js @@ -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(