From 48a533e4a92b77d7441a339c32ae54f1d173006a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 29 Jan 2024 14:52:54 +0100 Subject: [PATCH] refs #5770 feat usersMap --- .../back/models/specs/samba-config.spec.js | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/account/back/models/specs/samba-config.spec.js b/modules/account/back/models/specs/samba-config.spec.js index b0588e9a3..7ccb32cf8 100644 --- a/modules/account/back/models/specs/samba-config.spec.js +++ b/modules/account/back/models/specs/samba-config.spec.js @@ -1,5 +1,6 @@ // const execFile = require('child_process').execFile; const app = require('vn-loopback/server/server'); +const SAMBA_TOOL = 'samba-tool'; // const RoleControlFlags = { // ACCOUNTDISABLE: 0x2 // }; @@ -42,25 +43,16 @@ async function sambaTool(command, args = []) { return ['employee', 'customer', 'agency', 'group1']; else if (args[0] === 'add') { return new Promise(resolve => { - resolve(`samba-tool add ${args[1]}`); + resolve(`${SAMBA_TOOL} add ${args[1]}`); }); - } else if (args[0] === 'delete') { + } else if (['delete', 'listmembers'].includes(args[0])) { return new Promise(resolve => { - resolve(`samba-tool ${args[0]} ${args[1]}`); + resolve(`${SAMBA_TOOL} ${args[0]} ${args[1]}`); }); - } else if (args[0] === 'listmembers') { + } else if (['addmembers', 'removemembers'].includes(args[0])) { return new Promise(resolve => { - resolve(`samba-tool ${args[0]} ${args[1]}`); + resolve(`${SAMBA_TOOL} ${args[0]} ${args[1]} ${args[2]}`); }); - } else if (args[0] === 'addmembers') { - return new Promise(resolve => { - resolve(`samba-tool ${args[0]} ${args[1]} ${args[2]}`); - }); - } else if (args[0] === 'removemembers') { - return new Promise(resolve => { - resolve(`samba-tool ${args[0]} ${args[1]} ${args[2]}`); - }); - // return `samba-tool ${args[0]} ${args[1]} ${args[2]}`; } break; @@ -95,6 +87,17 @@ async function syncRoles() { expect(rolesToInsert.length).toEqual(2); // OBTENER USUARIOS Y SUS ROLES if (rolesToDelete.length > 0 || rolesToInsert.length > 0) { + let users = await $.VnUser.find({ + + include: { + relation: 'role', + scope: {fields: ['name'], + where: {'name': {inq: rolesToInsert}} + } + }, + fields: ['name', 'roleFk'], + where: {'active': true} + }); let accounts = await $.Account.find({ fields: ['id'], include: { @@ -111,6 +114,12 @@ async function syncRoles() { } } }); + let userMap = toMap(users, user => { + let role = user.role(); + if (!role) return; + return {key: role.name, val: user.name}; + }); + console.log(userMap); let accountMap = toMap(accounts, e => { let user = e.user(); if (!user) return;