Merge branch 'dev' into 4033-route
gitea/salix/pipeline/head Something is wrong with the build of this commit
Details
gitea/salix/pipeline/head Something is wrong with the build of this commit
Details
This commit is contained in:
commit
8f3e09b88f
|
@ -41,11 +41,14 @@ async function test() {
|
|||
}
|
||||
}));
|
||||
|
||||
jasmine.exitOnCompletion = false;
|
||||
|
||||
if (isCI) {
|
||||
const JunitReporter = require('jasmine-reporters');
|
||||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
jasmine.exitOnCompletion = true;
|
||||
}
|
||||
|
||||
const backSpecs = [
|
||||
|
@ -60,11 +63,10 @@ async function test() {
|
|||
helpers: [],
|
||||
});
|
||||
|
||||
jasmine.exitOnCompletion = false;
|
||||
await jasmine.execute();
|
||||
if (app) await app.disconnect();
|
||||
if (container) await container.rm();
|
||||
console.log('app disconnected & container removed');
|
||||
console.log('App disconnected & container removed');
|
||||
}
|
||||
|
||||
test();
|
||||
|
|
22
db/docker.js
22
db/docker.js
|
@ -19,8 +19,9 @@ module.exports = class Docker {
|
|||
* to avoid a bug with OverlayFS driver on MacOS.
|
||||
*
|
||||
* @param {Boolean} ci continuous integration environment argument
|
||||
* @param {String} networkName Name of the container network
|
||||
*/
|
||||
async run(ci) {
|
||||
async run(ci, networkName = 'jenkins') {
|
||||
let d = new Date();
|
||||
let pad = v => v < 10 ? '0' + v : v;
|
||||
let stamp = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||
|
@ -42,8 +43,16 @@ module.exports = class Docker {
|
|||
|
||||
let runChown = process.platform != 'linux';
|
||||
|
||||
let network = '';
|
||||
if (ci) network = `--network="${networkName}"`;
|
||||
|
||||
log('Starting container...');
|
||||
const container = await this.execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`);
|
||||
const container = await this.execP(`
|
||||
docker run \
|
||||
${network} \
|
||||
--env RUN_CHOWN=${runChown} \
|
||||
-d ${dockerArgs} salix-db
|
||||
`);
|
||||
this.id = container.stdout.trim();
|
||||
|
||||
try {
|
||||
|
@ -51,10 +60,11 @@ module.exports = class Docker {
|
|||
let inspect = await this.execP(`docker inspect -f "{{json .NetworkSettings}}" ${this.id}`);
|
||||
let netSettings = JSON.parse(inspect.stdout);
|
||||
|
||||
if (ci)
|
||||
this.dbConf.host = netSettings.Gateway;
|
||||
|
||||
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
||||
if (ci) {
|
||||
this.dbConf.host = netSettings.Networks[networkName].IPAddress;
|
||||
this.dbConf.port = 3306;
|
||||
} else
|
||||
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
||||
}
|
||||
|
||||
await this.wait();
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('Client Edit web access path', () => {
|
|||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('employee', 'client');
|
||||
await page.loginAndModule('salesPerson', 'client');
|
||||
await page.accessToSearchResult('max');
|
||||
await page.accessToSection('client.card.webAccess');
|
||||
});
|
||||
|
|
|
@ -131,5 +131,6 @@
|
|||
"Fichadas impares": "Odd signs",
|
||||
"Descanso diario 9h.": "Daily rest 9h.",
|
||||
"Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.",
|
||||
"Password does not meet requirements": "Password does not meet requirements"
|
||||
"Password does not meet requirements": "Password does not meet requirements",
|
||||
"Not enough privileges to edit a client": "Not enough privileges to edit a client"
|
||||
}
|
|
@ -232,5 +232,8 @@
|
|||
"Fichadas impares": "Fichadas impares",
|
||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||
"Dirección incorrecta": "Dirección incorrecta"
|
||||
"Dirección incorrecta": "Dirección incorrecta",
|
||||
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
|
||||
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
|
||||
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente"
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('setPassword', {
|
||||
Self.remoteMethodCtx('setPassword', {
|
||||
description: 'Sets the password of a non-worker client',
|
||||
accepts: [
|
||||
{
|
||||
|
@ -20,13 +21,21 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.setPassword = async function(id, newPassword) {
|
||||
Self.setPassword = async function(ctx, id, newPassword) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const isWorker = await models.Worker.findById(id);
|
||||
if (isWorker)
|
||||
throw new Error(`Can't change the password of another worker`);
|
||||
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||
|
||||
await models.Account.setPassword(id, newPassword);
|
||||
if (!isSalesPerson)
|
||||
throw new UserError(`Not enough privileges to edit a client`);
|
||||
|
||||
const isClient = await models.Client.findById(id, null);
|
||||
const isUserAccount = await models.UserAccount.findById(id, null);
|
||||
|
||||
if (isClient && !isUserAccount)
|
||||
await models.Account.setPassword(id, newPassword);
|
||||
else
|
||||
throw new UserError(`Modifiable password only via recovery or by an administrator`);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,23 +1,43 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Client setPassword', () => {
|
||||
it('should throw an error the setPassword target is not just a client but a worker', async() => {
|
||||
let error;
|
||||
const salesPersonId = 19;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: salesPersonId}}
|
||||
};
|
||||
|
||||
it(`should throw an error if you don't have enough permissions`, async() => {
|
||||
let error;
|
||||
const employeeId = 1;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: employeeId}}
|
||||
};
|
||||
try {
|
||||
await models.Client.setPassword(1106, 'newPass?');
|
||||
await models.Client.setPassword(ctx, 1, 't0pl3v3l.p455w0rd!');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Can't change the password of another worker`);
|
||||
expect(error.message).toEqual(`Not enough privileges to edit a client`);
|
||||
});
|
||||
|
||||
it('should throw an error the setPassword target is not just a client but a worker', async() => {
|
||||
let error;
|
||||
|
||||
try {
|
||||
await models.Client.setPassword(ctx, 1, 't0pl3v3l.p455w0rd!');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Modifiable password only via recovery or by an administrator`);
|
||||
});
|
||||
|
||||
it('should change the password of the client', async() => {
|
||||
let error;
|
||||
|
||||
try {
|
||||
await models.Client.setPassword(1101, 't0pl3v3l.p455w0rd!');
|
||||
await models.Client.setPassword(ctx, 1101, 't0pl3v3l.p455w0rd!');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ describe('Client updateUser', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
const salesPersonId = 19;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: employeeId}},
|
||||
req: {accessToken: {userId: salesPersonId}},
|
||||
args: {name: 'test', active: true}
|
||||
};
|
||||
|
||||
|
@ -21,8 +22,13 @@ describe('Client updateUser', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should throw an error the target user is not just a client but a worker', async() => {
|
||||
it(`should throw an error if you don't have enough permissions`, async() => {
|
||||
let error;
|
||||
const employeeId = 1;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: employeeId}},
|
||||
args: {name: 'test', active: true}
|
||||
};
|
||||
try {
|
||||
const clientID = 1106;
|
||||
await models.Client.updateUser(ctx, clientID);
|
||||
|
@ -30,7 +36,19 @@ describe('Client updateUser', () => {
|
|||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Can't update the user details of another worker`);
|
||||
expect(error.message).toEqual(`Not enough privileges to edit a client`);
|
||||
});
|
||||
|
||||
it('should throw an error the target user is not just a client but a worker', async() => {
|
||||
let error;
|
||||
try {
|
||||
const clientID = 1;
|
||||
await models.Client.updateUser(ctx, clientID);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Modifiable user details only by an administrator`);
|
||||
});
|
||||
|
||||
it('should update the user data', async() => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateUser', {
|
||||
description: 'Updates the user information',
|
||||
|
@ -5,8 +6,7 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
description: 'The user id',
|
||||
http: {source: 'path'}
|
||||
description: 'The user id'
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
type: 'any',
|
||||
description: 'the user email'
|
||||
},
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ module.exports = Self => {
|
|||
|
||||
Self.updateUser = async function(ctx, id, options) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
|
@ -44,13 +45,19 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const isWorker = await models.Worker.findById(id, null, myOptions);
|
||||
if (isWorker)
|
||||
throw new Error(`Can't update the user details of another worker`);
|
||||
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions);
|
||||
|
||||
const user = await models.Account.findById(id, null, myOptions);
|
||||
if (!isSalesPerson)
|
||||
throw new UserError(`Not enough privileges to edit a client`);
|
||||
|
||||
await user.updateAttributes(ctx.args, myOptions);
|
||||
const isClient = await models.Client.findById(id, null, myOptions);
|
||||
const isUserAccount = await models.UserAccount.findById(id, null, myOptions);
|
||||
|
||||
if (isClient && !isUserAccount) {
|
||||
const user = await models.Account.findById(id, null, myOptions);
|
||||
await user.updateAttributes(ctx.args, myOptions);
|
||||
} else
|
||||
throw new UserError(`Modifiable user details only by an administrator`);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const {Report, storage} = require('vn-print');
|
||||
const print = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('createPdf', {
|
||||
|
@ -52,7 +52,7 @@ module.exports = Self => {
|
|||
hasPdf: true
|
||||
}, myOptions);
|
||||
|
||||
const invoiceReport = new Report('invoice', {
|
||||
const invoiceReport = new print.Report('invoice', {
|
||||
reference: invoiceOut.ref,
|
||||
recipientId: invoiceOut.clientFk
|
||||
});
|
||||
|
@ -66,7 +66,7 @@ module.exports = Self => {
|
|||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||
|
||||
// Store invoice
|
||||
storage.write(stream, {
|
||||
print.storage.write(stream, {
|
||||
type: 'invoice',
|
||||
path: `${year}/${month}/${day}`,
|
||||
fileName: fileName
|
||||
|
|
|
@ -62,8 +62,14 @@ module.exports = Self => {
|
|||
name: fileName
|
||||
};
|
||||
|
||||
await fs.access(file.path);
|
||||
let stream = fs.createReadStream(file.path);
|
||||
try {
|
||||
await fs.access(file.path);
|
||||
} catch (error) {
|
||||
await Self.createPdf(ctx, id);
|
||||
}
|
||||
|
||||
const stream = fs.createReadStream(file.path);
|
||||
|
||||
return [stream, file.contentType, `filename="${file.name}"`];
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT')
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
const fs = require('fs-extra');
|
||||
const axios = require('axios');
|
||||
const print = require('vn-print');
|
||||
|
||||
describe('InvoiceOut createPdf()', () => {
|
||||
const userId = 1;
|
||||
|
@ -16,22 +15,15 @@ describe('InvoiceOut createPdf()', () => {
|
|||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
const response = {
|
||||
data: {
|
||||
pipe: () => {},
|
||||
on: () => {},
|
||||
|
||||
spyOn(print, 'Report').and.returnValue({
|
||||
toPdfStream: () => {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response)));
|
||||
spyOn(models.InvoiceContainer, 'container').and.returnValue({
|
||||
client: {root: '/path'}
|
||||
});
|
||||
spyOn(fs, 'mkdir').and.returnValue(true);
|
||||
spyOn(fs, 'createWriteStream').and.returnValue({
|
||||
on: (event, cb) => cb(),
|
||||
end: () => {}
|
||||
});
|
||||
|
||||
spyOn(print.storage, 'write').and.returnValue(true);
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,7 +20,7 @@
|
|||
"juice": "^5.2.0",
|
||||
"mysql2": "^1.7.0",
|
||||
"nodemailer": "^4.7.0",
|
||||
"puppeteer": "^2.0.0",
|
||||
"puppeteer": "^18.0.5",
|
||||
"qrcode": "^1.4.2",
|
||||
"strftime": "^0.10.0",
|
||||
"vue": "^2.6.10",
|
||||
|
|
Loading…
Reference in New Issue