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