test(samba): refs #5770 solid concept(2)

This commit is contained in:
Javier Segarra 2024-05-11 22:21:54 +02:00
parent 084a54fd2f
commit 3e00a69108
1 changed files with 23 additions and 20 deletions

View File

@ -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.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(