Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
33289b3ac1
|
@ -25,9 +25,11 @@ pipeline {
|
||||||
switch (env.BRANCH_NAME) {
|
switch (env.BRANCH_NAME) {
|
||||||
case 'master':
|
case 'master':
|
||||||
env.NODE_ENV = 'production'
|
env.NODE_ENV = 'production'
|
||||||
|
env.BACK_REPLICAS = 4
|
||||||
break
|
break
|
||||||
case 'test':
|
case 'test':
|
||||||
env.NODE_ENV = 'test'
|
env.NODE_ENV = 'test'
|
||||||
|
env.BACK_REPLICAS = 2
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ module.exports = Self => {
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
if (process.env.NODE_ENV == 'test')
|
if (process.env.NODE_ENV == 'test')
|
||||||
throw new UserError(`You can't upload images on the test instance`);
|
throw new UserError(`You can't upload images on the test environment`);
|
||||||
|
|
||||||
// Upload file to temporary path
|
// Upload file to temporary path
|
||||||
const tempContainer = await TempContainer.container(args.collection);
|
const tempContainer = await TempContainer.container(args.collection);
|
||||||
|
|
|
@ -8,7 +8,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- 80
|
- 80
|
||||||
deploy:
|
deploy:
|
||||||
replicas: 3
|
replicas: 2
|
||||||
back:
|
back:
|
||||||
image: registry.verdnatura.es/salix-back:${BRANCH_NAME:?}
|
image: registry.verdnatura.es/salix-back:${BRANCH_NAME:?}
|
||||||
build: .
|
build: .
|
||||||
|
@ -30,7 +30,7 @@ services:
|
||||||
- /mnt/storage/dms:/var/lib/salix/dms
|
- /mnt/storage/dms:/var/lib/salix/dms
|
||||||
- /mnt/storage/image:/var/lib/salix/image
|
- /mnt/storage/image:/var/lib/salix/image
|
||||||
deploy:
|
deploy:
|
||||||
replicas: 6
|
replicas: ${BACK_REPLICAS:?}
|
||||||
configs:
|
configs:
|
||||||
datasources:
|
datasources:
|
||||||
external: true
|
external: true
|
||||||
|
|
|
@ -35,14 +35,13 @@ module.exports = Self => {
|
||||||
accountConfig
|
accountConfig
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
let newEntry;
|
let dn = `uid=${userName},${this.userDn}`;
|
||||||
|
|
||||||
if (info.hasAccount) {
|
if (info.hasAccount) {
|
||||||
let {user} = info;
|
let {user} = info;
|
||||||
|
|
||||||
let oldUser = await client.searchOne(this.userDn, {
|
let oldUser = await client.searchOne(this.userDn, {
|
||||||
scope: 'sub',
|
scope: 'sub',
|
||||||
attributes: ['userPassword', 'sambaNTPassword'],
|
|
||||||
filter: `&(uid=${userName})`
|
filter: `&(uid=${userName})`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ module.exports = Self => {
|
||||||
? nameArgs.splice(1).join(' ')
|
? nameArgs.splice(1).join(' ')
|
||||||
: '-';
|
: '-';
|
||||||
|
|
||||||
newEntry = {
|
let newEntry = {
|
||||||
uid: userName,
|
uid: userName,
|
||||||
objectClass: [
|
objectClass: [
|
||||||
'inetOrgPerson',
|
'inetOrgPerson',
|
||||||
|
@ -101,62 +100,115 @@ module.exports = Self => {
|
||||||
if (newEntry[prop] == null)
|
if (newEntry[prop] == null)
|
||||||
delete newEntry[prop];
|
delete newEntry[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldUser) {
|
||||||
|
let changes = [];
|
||||||
|
let skipProps = new Set([
|
||||||
|
'dn',
|
||||||
|
'controls'
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (let prop in oldUser) {
|
||||||
|
let deleteProp = !skipProps.has(prop)
|
||||||
|
&& !newEntry.hasOwnProperty(prop);
|
||||||
|
if (!deleteProp) continue;
|
||||||
|
changes.push(new ldap.Change({
|
||||||
|
operation: 'delete',
|
||||||
|
modification: {
|
||||||
|
[prop]: oldUser[prop]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for (let prop in newEntry) {
|
||||||
|
if (this.isEqual(oldUser[prop], newEntry[prop]))
|
||||||
|
continue;
|
||||||
|
changes.push(new ldap.Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: {
|
||||||
|
[prop]: newEntry[prop]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changes.length)
|
||||||
|
await client.modify(dn, changes);
|
||||||
|
} else
|
||||||
|
await client.add(dn, newEntry);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
await client.del(dn);
|
||||||
|
console.log(` -> User '${userName}' removed from LDAP`);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name !== 'NoSuchObjectError') throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Remove and recreate (if applicable) user
|
isEqual(a, b) {
|
||||||
|
if (Array.isArray(a) && Array.isArray(b)) {
|
||||||
let dn = `uid=${userName},${this.userDn}`;
|
if (a.length !== b.length)
|
||||||
let operation;
|
return false;
|
||||||
|
for (let element of a) {
|
||||||
try {
|
if (b.indexOf(element) === -1)
|
||||||
await client.del(dn);
|
return false;
|
||||||
operation = 'delete';
|
}
|
||||||
} catch (e) {
|
return true;
|
||||||
if (e.name !== 'NoSuchObjectError') throw e;
|
} else
|
||||||
}
|
return a == b;
|
||||||
|
|
||||||
if (info.hasAccount) {
|
|
||||||
await client.add(dn, newEntry);
|
|
||||||
operation = 'add';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operation === 'delete')
|
|
||||||
console.log(` -> User '${userName}' removed from LDAP`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async syncUserGroups(userName, info) {
|
async syncUserGroups(userName, info) {
|
||||||
let {client} = this;
|
let {client} = this;
|
||||||
|
let {user} = info;
|
||||||
|
let groupDn = this.groupDn;
|
||||||
|
|
||||||
let opts = {
|
let opts = {
|
||||||
scope: 'sub',
|
scope: 'sub',
|
||||||
attributes: ['dn'],
|
attributes: ['dn', 'cn'],
|
||||||
filter: `&(memberUid=${userName})(objectClass=posixGroup)`
|
filter: `&(memberUid=${userName})(objectClass=posixGroup)`
|
||||||
};
|
};
|
||||||
let oldGroups = await client.searchAll(this.groupDn, opts);
|
let oldGroups = await client.searchAll(groupDn, opts);
|
||||||
|
|
||||||
let reqs = [];
|
let deleteGroups = [];
|
||||||
for (let oldGroup of oldGroups) {
|
let addGroups = [];
|
||||||
let change = new ldap.Change({
|
|
||||||
operation: 'delete',
|
if (info.hasAccount) {
|
||||||
modification: {memberUid: userName}
|
let oldSet = new Set();
|
||||||
});
|
oldGroups.forEach(e => oldSet.add(e.cn));
|
||||||
reqs.push(client.modify(oldGroup.dn, change));
|
|
||||||
|
let newSet = new Set();
|
||||||
|
user.roles().forEach(e => newSet.add(e.inherits().name));
|
||||||
|
|
||||||
|
for (let group of oldGroups) {
|
||||||
|
if (!newSet.has(group.cn))
|
||||||
|
deleteGroups.push(group.cn);
|
||||||
|
}
|
||||||
|
for (let role of user.roles()) {
|
||||||
|
if (!oldSet.has(role.inherits().name))
|
||||||
|
addGroups.push(role.inherits().name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let group of oldGroups)
|
||||||
|
deleteGroups.push(group.cn);
|
||||||
}
|
}
|
||||||
await Promise.all(reqs);
|
|
||||||
|
|
||||||
if (!info.hasAccount) return;
|
async function applyOperations(groups, operation) {
|
||||||
|
for (let group of groups) {
|
||||||
reqs = [];
|
try {
|
||||||
for (let role of info.user.roles()) {
|
let dn = `cn=${group},${groupDn}`;
|
||||||
let change = new ldap.Change({
|
await client.modify(dn, new ldap.Change({
|
||||||
operation: 'add',
|
operation,
|
||||||
modification: {memberUid: userName}
|
modification: {memberUid: userName}
|
||||||
});
|
}));
|
||||||
let roleName = role.inherits().name;
|
} catch (err) {
|
||||||
let dn = `cn=${roleName},${this.groupDn}`;
|
if (err.name !== 'NoSuchObjectError')
|
||||||
reqs.push(client.modify(dn, change));
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(reqs);
|
|
||||||
|
await applyOperations(deleteGroups, 'delete');
|
||||||
|
await applyOperations(addGroups, 'add');
|
||||||
},
|
},
|
||||||
|
|
||||||
async getUsers(usersToSync) {
|
async getUsers(usersToSync) {
|
||||||
|
|
|
@ -7,4 +7,4 @@ FROM client c
|
||||||
JOIN company AS cny
|
JOIN company AS cny
|
||||||
JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk
|
JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk
|
||||||
JOIN bankEntity be ON be.id = sa.bankEntityFk
|
JOIN bankEntity be ON be.id = sa.bankEntityFk
|
||||||
WHERE c.id = ? AND cny.id = ?`
|
WHERE c.id = ? AND cny.id = ?
|
Loading…
Reference in New Issue