Merge branch 'dev' into 6501-procMigration
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-02-09 10:39:47 +00:00
commit 0cea80ad46
14 changed files with 215 additions and 153 deletions

View File

@ -0,0 +1,3 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('Supplier', 'updateAllFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'administrative'),
('Supplier', 'updateFiscalData', 'WRITE', 'ALLOW', 'ROLE', 'buyer');

View File

@ -18,11 +18,13 @@ services:
memory: 1G memory: 1G
back: back:
image: registry.verdnatura.es/salix-back:${VERSION:?} image: registry.verdnatura.es/salix-back:${VERSION:?}
build: . build:
context: .
dockerfile: back/Dockerfile
environment: environment:
- TZ
- NODE_ENV - NODE_ENV
- DEBUG - DEBUG
- TZ
ports: ports:
- 3000 - 3000
configs: configs:

View File

@ -1,7 +1,9 @@
/* eslint-disable no-console */
require('@babel/register')({presets: ['@babel/env']}); require('@babel/register')({presets: ['@babel/env']});
require('core-js/stable'); require('core-js/stable');
require('regenerator-runtime/runtime'); require('regenerator-runtime/runtime');
require('vn-loopback/server/boot/date')(); require('vn-loopback/server/boot/date')();
const getopts = require('getopts');
const path = require('path'); const path = require('path');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
@ -18,12 +20,16 @@ process.on('warning', warning => {
}); });
async function test() { async function test() {
if (process.argv[2] === 'show') const opts = getopts(process.argv.slice(2), {
process.env.E2E_SHOW = true; boolean: ['show']
});
process.env.E2E_SHOW = opts.show;
console.log('Building and running DB container.');
const myt = new Myt(); const myt = new Myt();
await myt.init({workspace: path.join(__dirname, '../..')}); await myt.init({workspace: path.join(__dirname, '../..')});
await myt.run(Run); await myt.run(Run);
await myt.deinit();
const Jasmine = require('jasmine'); const Jasmine = require('jasmine');
const jasmine = new Jasmine(); const jasmine = new Jasmine();
@ -70,12 +76,10 @@ async function test() {
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
await jasmine.execute(); await jasmine.execute();
await myt.deinit();
} }
async function backendStatus() { async function backendStatus() {
log('Awaiting backend connection...'); log('Awaiting backend connection.');
const milliseconds = 1000; const milliseconds = 1000;
const maxAttempts = 10; const maxAttempts = 10;

View File

@ -1,19 +1,19 @@
import 'angular'; import 'angular';
import 'angular-mocks'; import 'angular-mocks';
import core from './front/core/module.js'; import core from './core/module.js';
import './front/salix/components/app/app.js'; import './salix/components/app/app.js';
import './modules/zone/front/module.js'; import '../modules/zone/front/module.js';
import './modules/claim/front/module.js'; import '../modules/claim/front/module.js';
import './modules/client/front/module.js'; import '../modules/client/front/module.js';
import './modules/invoiceOut/front/module.js'; import '../modules/invoiceOut/front/module.js';
import './modules/invoiceIn/front/module.js'; import '../modules/invoiceIn/front/module.js';
import './modules/item/front/module.js'; import '../modules/item/front/module.js';
import './modules/order/front/module.js'; import '../modules/order/front/module.js';
import './modules/route/front/module.js'; import '../modules/route/front/module.js';
import './modules/ticket/front/module.js'; import '../modules/ticket/front/module.js';
import './modules/travel/front/module.js'; import '../modules/travel/front/module.js';
import './modules/worker/front/module.js'; import '../modules/worker/front/module.js';
import './modules/shelving/front/module.js'; import '../modules/shelving/front/module.js';
import 'vn-loopback/server/boot/date'; import 'vn-loopback/server/boot/date';
// Set NODE_ENV // Set NODE_ENV

View File

@ -2,7 +2,6 @@
require('require-yaml'); require('require-yaml');
const gulp = require('gulp'); const gulp = require('gulp');
const PluginError = require('plugin-error'); const PluginError = require('plugin-error');
const argv = require('minimist')(process.argv.slice(2));
const log = require('fancy-log'); const log = require('fancy-log');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
@ -12,9 +11,6 @@ const Start = require('@verdnatura/myt/myt-start');
let isWindows = /^win/.test(process.platform); let isWindows = /^win/.test(process.platform);
if (argv.NODE_ENV)
process.env.NODE_ENV = argv.NODE_ENV;
let langs = ['es', 'en']; let langs = ['es', 'en'];
let srcDir = './front'; let srcDir = './front';
let modulesDir = './modules'; let modulesDir = './modules';

View File

@ -10,7 +10,7 @@ module.exports = {
}, },
testEnvironment: 'jsdom', testEnvironment: 'jsdom',
setupFilesAfterEnv: [ setupFilesAfterEnv: [
'./jest-front.js' './front/jest-setup.js'
], ],
testMatch: [ testMatch: [
'**/front/**/*.spec.js', '**/front/**/*.spec.js',
@ -37,7 +37,7 @@ module.exports = {
], ],
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy', '\\.(css|scss)$': 'identity-obj-proxy',
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/fileMock.js', '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/front/jest-mock.js',
}, },
testURL: 'http://localhost', testURL: 'http://localhost',
verbose: false, verbose: false,

View File

@ -206,6 +206,5 @@
"Incorrect pin": "Incorrect pin.", "Incorrect pin": "Incorrect pin.",
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified",
"Name should be uppercase": "Name should be uppercase", "Name should be uppercase": "Name should be uppercase",
"Fecha fuera de rango": "Fecha fuera de rango", "You cannot update these fields": "You cannot update these fields"
"There is no zone for these parameters 34": "There is no zone for these parameters 34" }
}

View File

@ -338,6 +338,7 @@
"The alias cant be modified": "Este alias de correo no puede ser modificado", "The alias cant be modified": "Este alias de correo no puede ser modificado",
"No tickets to invoice": "No hay tickets para facturar", "No tickets to invoice": "No hay tickets para facturar",
"Name should be uppercase": "El nombre debe ir en mayúscula", "Name should be uppercase": "El nombre debe ir en mayúscula",
"Bank entity must be specified": "La entidad bancaria es obligatoria", "Bank entity must be specified": "La entidad bancaria es obligatoria",
"An email is necessary": "Es necesario un email" "An email is necessary": "Es necesario un email",
} "You cannot update these fields": "No puedes actualizar estos campos"
}

View File

@ -1,92 +1,142 @@
const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('Supplier updateFiscalData', () => { describe('Supplier updateFiscalData()', () => {
const supplierId = 1; const supplierId = 1;
const administrativeId = 5; const administrativeId = 5;
const employeeId = 1; const buyerId = 35;
const defaultData = {
name: 'PLANTS SL',
nif: '06089160W',
account: '4100000001',
sageTaxTypeFk: 4,
sageWithholdingFk: 1,
sageTransactionTypeFk: 1,
postCode: '15214',
city: 'PONTEVEDRA',
provinceFk: 1,
countryFk: 1,
};
it('should return an error if the user is not administrative', async() => { const name = 'NEW PLANTS';
const ctx = {req: {accessToken: {userId: employeeId}}}; const city = 'PONTEVEDRA';
ctx.args = {}; const nif = 'A68446004';
const account = '4000000005';
const sageTaxTypeFk = 5;
const sageWithholdingFk = 2;
const sageTransactionTypeFk = 2;
const postCode = '46460';
const phone = 456129367;
const street = ' Fake address 12 3 flat';
const provinceFk = 2;
const countryFk = 1;
const supplierActivityFk = 'animals';
const healthRegister = '400664487H';
let error; let ctx;
await app.models.Supplier.updateFiscalData(ctx, supplierId) let options;
.catch(e => { let tx;
error = e;
});
expect(error.message).toBeDefined(); beforeEach(async() => {
}); ctx = {
req: {
it('should check that the supplier fiscal data is untainted', async() => { accessToken: {userId: buyerId},
const supplier = await app.models.Supplier.findById(supplierId); headers: {origin: 'http://localhost'},
__: value => value
expect(supplier.name).toEqual(defaultData.name); },
expect(supplier.nif).toEqual(defaultData.nif); args: {}
expect(supplier.account).toEqual(defaultData.account);
expect(supplier.sageTaxTypeFk).toEqual(defaultData.sageTaxTypeFk);
expect(supplier.sageWithholdingFk).toEqual(defaultData.sageWithholdingFk);
expect(supplier.sageTransactionTypeFk).toEqual(defaultData.sageTransactionTypeFk);
expect(supplier.postCode).toEqual(defaultData.postCode);
expect(supplier.city).toEqual(defaultData.city);
expect(supplier.provinceFk).toEqual(defaultData.provinceFk);
expect(supplier.countryFk).toEqual(defaultData.countryFk);
});
it('should update the supplier fiscal data and return the count if changes made', async() => {
const activeCtx = {
accessToken: {userId: administrativeId},
}; };
const ctx = {req: activeCtx};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx active: ctx.req
}); });
ctx.args = { options = {transaction: tx};
name: 'WEAPON DEALER', tx = await models.Sale.beginTransaction({});
nif: 'A68446004', options.transaction = tx;
account: '4000000005', });
sageTaxTypeFk: 5,
sageWithholdingFk: 2,
sageTransactionTypeFk: 2,
postCode: '46460',
city: 'VALENCIA',
provinceFk: 2,
countryFk: 1,
supplierActivityFk: 'animals',
healthRegister: '400664487H'
};
const result = await app.models.Supplier.updateFiscalData(ctx, supplierId); afterEach(async() => {
await tx.rollback();
});
expect(result.name).toEqual('WEAPON DEALER'); it('should throw an error if it is a buyer and tries to update forbidden fiscal data', async() => {
expect(result.nif).toEqual('A68446004'); try {
expect(result.account).toEqual('4000000005'); await models.Supplier.updateFiscalData(ctx,
expect(result.sageTaxTypeFk).toEqual(5); supplierId,
expect(result.sageWithholdingFk).toEqual(2); name,
expect(result.sageTransactionTypeFk).toEqual(2); nif,
expect(result.postCode).toEqual('46460'); account,
expect(result.city).toEqual('VALENCIA'); undefined,
expect(result.provinceFk).toEqual(2); sageTaxTypeFk,
expect(result.countryFk).toEqual(1); undefined,
expect(result.supplierActivityFk).toEqual('animals'); sageTransactionTypeFk,
expect(result.healthRegister).toEqual('400664487H'); undefined,
undefined,
undefined,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
undefined,
undefined,
options);
} catch (e) {
expect(e.message).toEqual('You cannot update these fields');
}
});
// Restores it('should update the granted fiscal data if it is a buyer', async() => {
ctx.args = defaultData; const supplier = await models.Supplier.updateFiscalData(ctx,
await app.models.Supplier.updateFiscalData(ctx, supplierId); supplierId,
undefined,
undefined,
account,
phone,
undefined,
undefined,
undefined,
postCode,
street,
city,
provinceFk,
undefined,
undefined,
undefined,
undefined,
undefined,
options);
expect(supplier.account).toEqual(account);
expect(supplier.phone).toEqual(phone);
expect(supplier.postCode).toEqual(postCode);
expect(supplier.account).toEqual(account);
expect(supplier.city).toEqual(city);
expect(supplier.provinceFk).toEqual(provinceFk);
});
it('should update all fiscalData if it is an administative', async() => {
const supplier = await models.Supplier.updateFiscalData(ctx,
supplierId,
name,
nif,
account,
phone,
sageTaxTypeFk,
sageWithholdingFk,
sageTransactionTypeFk,
postCode,
street,
city,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
undefined,
undefined,
options);
expect(supplier.name).toEqual(name);
expect(supplier.nif).toEqual(nif);
expect(supplier.account).toEqual(account);
expect(supplier.phone).toEqual(phone);
expect(supplier.sageTaxTypeFk).toEqual(sageTaxTypeFk);
expect(supplier.sageWithholdingFk).toEqual(sageWithholdingFk);
expect(supplier.sageTransactionTypeFk).toEqual(sageTransactionTypeFk);
expect(supplier.postCode).toEqual(postCode);
expect(supplier.street).toEqual(street);
expect(supplier.city).toEqual(city);
expect(supplier.provinceFk).toEqual(provinceFk);
expect(supplier.countryFk).toEqual(countryFk);
expect(supplier.supplierActivityFk).toEqual(supplierActivityFk);
expect(supplier.healthRegister).toEqual(healthRegister);
}); });
}); });

View File

@ -1,75 +1,59 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('updateFiscalData', { Self.remoteMethodCtx('updateFiscalData', {
description: 'Updates fiscal data of a supplier', description: 'Updates fiscal data of a supplier',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
},
{
arg: 'id', arg: 'id',
type: 'Number', type: 'Number',
description: 'The supplier id', description: 'The supplier id',
http: {source: 'path'} http: {source: 'path'}
}, }, {
{
arg: 'name', arg: 'name',
type: 'string' type: 'string'
}, }, {
{
arg: 'nif', arg: 'nif',
type: 'string' type: 'string'
}, }, {
{
arg: 'account', arg: 'account',
type: 'any' type: 'any'
}, }, {
{ arg: 'phone',
type: 'string'
}, {
arg: 'sageTaxTypeFk', arg: 'sageTaxTypeFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'sageWithholdingFk', arg: 'sageWithholdingFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'sageTransactionTypeFk', arg: 'sageTransactionTypeFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'postCode', arg: 'postCode',
type: 'any' type: 'any'
}, }, {
{
arg: 'street', arg: 'street',
type: 'any' type: 'any'
}, }, {
{
arg: 'city', arg: 'city',
type: 'string' type: 'string'
}, }, {
{
arg: 'provinceFk', arg: 'provinceFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'countryFk', arg: 'countryFk',
type: 'any' type: 'any'
}, }, {
{
arg: 'supplierActivityFk', arg: 'supplierActivityFk',
type: 'string' type: 'string'
}, }, {
{
arg: 'healthRegister', arg: 'healthRegister',
type: 'string' type: 'string'
}, }, {
{
arg: 'isVies', arg: 'isVies',
type: 'boolean' type: 'boolean'
}, }, {
{
arg: 'isTrucker', arg: 'isTrucker',
type: 'boolean' type: 'boolean'
}], }],
@ -84,15 +68,42 @@ module.exports = Self => {
} }
}); });
Self.updateFiscalData = async(ctx, supplierId) => { Self.updateFiscalData = async(ctx, supplierId, name, nif, account, phone, sageTaxTypeFk, sageWithholdingFk, sageTransactionTypeFk, postCode, street, city, provinceFk, countryFk, supplierActivityFk, healthRegister, isVies, isTrucker, options) => {
const models = Self.app.models; const models = Self.app.models;
const args = ctx.args; const {args} = ctx;
const myOptions = {};
const supplier = await models.Supplier.findById(supplierId); const supplier = await models.Supplier.findById(supplierId);
// Remove unwanted properties if (typeof options == 'object') Object.assign(myOptions, options);
delete args.ctx; delete args.ctx;
delete args.id; delete args.id;
return supplier.updateAttributes(args); const updateAllFiscalData = await models.ACL.checkAccessAcl(ctx, 'Supplier', 'updateAllFiscalData', 'WRITE');
if (!updateAllFiscalData) {
for (const arg in args) {
if (args[arg] && !['street', 'postCode', 'city', 'provinceFk', 'phone'].includes(arg))
throw new UserError('You cannot update these fields');
}
}
return supplier.updateAttributes({
name,
nif,
account,
phone,
sageTaxTypeFk,
sageWithholdingFk,
sageTransactionTypeFk,
postCode,
street,
city,
provinceFk,
countryFk,
supplierActivityFk,
healthRegister,
isVies,
isTrucker
}, myOptions);
}; };
}; };

View File

@ -90,7 +90,6 @@
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"json-loader": "^0.5.7", "json-loader": "^0.5.7",
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"minimist": "^1.2.5",
"node-sass": "^9.0.0", "node-sass": "^9.0.0",
"nodemon": "^2.0.16", "nodemon": "^2.0.16",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",

View File

@ -232,9 +232,6 @@ devDependencies:
merge-stream: merge-stream:
specifier: ^1.0.1 specifier: ^1.0.1
version: 1.0.1 version: 1.0.1
minimist:
specifier: ^1.2.5
version: 1.2.8
node-sass: node-sass:
specifier: ^9.0.0 specifier: ^9.0.0
version: 9.0.0 version: 9.0.0