Merge branch 'dev' into 6021-fix-orderPut
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Pako Natek 2024-04-16 15:44:02 +00:00
commit c1c6204eab
16 changed files with 185 additions and 128 deletions

View File

@ -33,16 +33,23 @@ module.exports = Self => {
// Schedule to remove current token // Schedule to remove current token
setTimeout(async() => { setTimeout(async() => {
try { try {
await Self.logout(token.id); const exists = await models.AccessToken.findById(token.id);
exists && await Self.logout(token.id);
} catch (err) { } catch (err) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(err); console.error(err);
} }
}, courtesyTime * 1000); }, courtesyTime * 1000);
// Get scopes
let createTokenOptions = {};
const {scopes} = token;
if (scopes)
createTokenOptions = {scopes: [scopes[0]]};
// Create new accessToken // Create new accessToken
const user = await Self.findById(token.userId); const user = await Self.findById(token.userId);
const accessToken = await user.createAccessToken(); const accessToken = await user.accessTokens.create(createTokenOptions);
return {id: accessToken.id, ttl: accessToken.ttl}; return {id: accessToken.id, ttl: accessToken.ttl};
}; };

View File

@ -33,6 +33,17 @@ describe('Renew Token', () => {
const {id} = await models.VnUser.renewToken(ctx); const {id} = await models.VnUser.renewToken(ctx);
expect(id).not.toEqual(ctx.req.accessToken.id); expect(id).not.toEqual(ctx.req.accessToken.id);
await models.VnUser.logout(ctx.req.accessToken.id);
jasmine.clock().tick(70 * 1000);
let tokenNotExists;
try {
tokenNotExists = await models.AccessToken.findById(ctx.req.accessToken.id);
} catch (e) {
error = e;
}
expect(tokenNotExists).toBeNull();
}); });
it('NOT should renew', async() => { it('NOT should renew', async() => {

View File

@ -1,6 +1,9 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
const TOKEN_MULTIMEDIA = 'read:multimedia';
describe('Share Token', () => { describe('Share Token', () => {
let ctx = null; let ctx = null;
const startingTime = Date.now();
let multimediaToken = null;
beforeAll(async() => { beforeAll(async() => {
const unAuthCtx = { const unAuthCtx = {
req: { req: {
@ -17,11 +20,45 @@ describe('Share Token', () => {
ctx = {req: {accessToken: accessToken}}; ctx = {req: {accessToken: accessToken}};
}); });
it('should renew token', async() => { beforeEach(async() => {
const multimediaToken = await models.VnUser.shareToken(ctx); multimediaToken = await models.VnUser.shareToken(ctx);
jasmine.clock().install();
jasmine.clock().mockDate(new Date(startingTime));
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('should generate token', async() => {
expect(Object.keys(multimediaToken).length).toEqual(1); expect(Object.keys(multimediaToken).length).toEqual(1);
expect(multimediaToken.multimediaToken.userId).toEqual(ctx.req.accessToken.userId); expect(multimediaToken.multimediaToken.userId).toEqual(ctx.req.accessToken.userId);
expect(multimediaToken.multimediaToken.scopes[0]).toEqual('read:multimedia'); expect(multimediaToken.multimediaToken.scopes[0]).toEqual(TOKEN_MULTIMEDIA);
});
it('NOT should renew', async() => {
let error;
let response;
try {
response = await models.VnUser.renewToken(ctx);
} catch (e) {
error = e;
}
expect(error).toBeUndefined();
expect(response.id).toEqual(ctx.req.accessToken.id);
});
it('should renew token', async() => {
const mockDate = new Date(startingTime + 26600000);
jasmine.clock().mockDate(mockDate);
const newShareToken = await models.VnUser.renewToken({req: {accessToken: multimediaToken.multimediaToken}});
const {id} = newShareToken;
expect(id).not.toEqual(ctx.req.accessToken.id);
const newMultimediaToken = await models.AccessToken.findById(id);
expect(newMultimediaToken.scopes[0]).toEqual(TOKEN_MULTIMEDIA);
}); });
}); });

View File

@ -147,7 +147,7 @@ proc:BEGIN
(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue, (@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue,
IFNULL(vItem, vDefaultEntry) itemFk, IFNULL(vItem, vDefaultEntry) itemFk,
e.qty stickers, e.qty stickers,
@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing, @pac := GREATEST(1, IFNULL(i.stemMultiplier * e.pac / @t, 0)) packing,
IFNULL(b.`grouping`, e.pac), IFNULL(b.`grouping`, e.pac),
@pac * e.qty, @pac * e.qty,
vForceToPacking, vForceToPacking,

View File

@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `hedera`.`order_doRecalc`
ON SCHEDULE EVERY 10 SECOND ON SCHEDULE EVERY 10 SECOND
STARTS '2019-08-29 14:18:04.000' STARTS '2019-08-29 14:18:04.000'
ON COMPLETION PRESERVE ON COMPLETION PRESERVE
ENABLE DISABLE
DO CALL order_doRecalc$$ DO CALL order_doRecalc$$
DELIMITER ; DELIMITER ;

View File

@ -10,6 +10,7 @@ proc: BEGIN
LEAVE proc; LEAVE proc;
END IF; END IF;
INSERT INTO orderRecalc SET orderFk = vSelf; -- #4409 Disable order recalc
-- INSERT INTO orderRecalc SET orderFk = vSelf;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -6,16 +6,24 @@ BEGIN
*/ */
DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log; DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log;
DECLARE vSqlLogBin INT DEFAULT @@SESSION.sql_log_bin; DECLARE vSqlLogBin INT DEFAULT @@SESSION.sql_log_bin;
DECLARE vLogExists BOOL;
SET sql_log_bin = OFF; SET sql_log_bin = OFF;
SET GLOBAL slow_query_log = OFF; SET GLOBAL slow_query_log = OFF;
RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`; SELECT COUNT(*) > 0 INTO vLogExists
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'slow_log';
DELETE FROM `mysql`.`slow_log_temp` IF vLogExists THEN
DROP TEMPORARY TABLE IF EXISTS mysql.slow_log_temp;
RENAME TABLE mysql.slow_log TO mysql.slow_log_temp;
END IF;
DELETE FROM mysql.slow_log_temp
WHERE start_time < TIMESTAMPADD(WEEK, -1, util.VN_NOW()); WHERE start_time < TIMESTAMPADD(WEEK, -1, util.VN_NOW());
RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`; RENAME TABLE mysql.slow_log_temp TO mysql.slow_log;
SET GLOBAL slow_query_log = vSlowQueryLog; SET GLOBAL slow_query_log = vSlowQueryLog;
SET sql_log_bin = vSqlLogBin; SET sql_log_bin = vSqlLogBin;

View File

@ -13,6 +13,7 @@ BEGIN
* @param vQuantity a dar de alta/baja * @param vQuantity a dar de alta/baja
* @param vAddressFk id address * @param vAddressFk id address
*/ */
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vClientFk INT; DECLARE vClientFk INT;
DECLARE vDefaultCompanyFk INT; DECLARE vDefaultCompanyFk INT;
@ -33,7 +34,7 @@ BEGIN
SELECT a.clientFk INTO vClientFk SELECT a.clientFk INTO vClientFk
FROM address a FROM address a
WHERE a.id = vAddressFk; WHERE a.id = vAddressShortage;
SELECT t.id INTO vTicketFk SELECT t.id INTO vTicketFk
FROM ticket t FROM ticket t
@ -65,7 +66,7 @@ BEGIN
INSERT INTO sale(ticketFk, itemFk, concept, quantity) INSERT INTO sale(ticketFk, itemFk, concept, quantity)
SELECT vTicketFk, SELECT vTicketFk,
vItemFk, vItemFk,
CONCAT(longName,' ', worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)), name,
vQuantity vQuantity
FROM item FROM item
WHERE id = vItemFk; WHERE id = vItemFk;

View File

@ -0,0 +1,4 @@
UPDATE salix.ACL SET principalId = "hr" WHERE property IN ('find','findById','findOne') AND model = "Worker";
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('Worker', '__get__summary', 'READ', 'ALLOW', 'ROLE', 'employee');

View File

@ -2,7 +2,6 @@ import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer'; import getBrowser from '../../helpers/puppeteer';
describe('Worker summary path', () => { describe('Worker summary path', () => {
const workerId = 3;
let browser; let browser;
let page; let page;
beforeAll(async() => { beforeAll(async() => {
@ -10,7 +9,7 @@ describe('Worker summary path', () => {
page = browser.page; page = browser.page;
await page.loginAndModule('employee', 'worker'); await page.loginAndModule('employee', 'worker');
const httpDataResponse = page.waitForResponse(response => { const httpDataResponse = page.waitForResponse(response => {
return response.status() === 200 && response.url().includes(`Workers/${workerId}`); return response.status() === 200 && response.url().includes(`Workers/summary`);
}); });
await page.accessToSearchResult('agencyNick'); await page.accessToSearchResult('agencyNick');
await httpDataResponse; await httpDataResponse;

View File

@ -19,7 +19,7 @@ module.exports = Self => {
if (ticket.ticketFk != claim.ticketFk) if (ticket.ticketFk != claim.ticketFk)
throw new UserError(`Cannot create a new claimBeginning from a different ticket`); throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
} }
// await claimIsEditable(ctx); await claimIsEditable(ctx);
}); });
Self.observe('before delete', async ctx => { Self.observe('before delete', async ctx => {
@ -36,7 +36,7 @@ module.exports = Self => {
if (ctx.options && ctx.options.transaction) if (ctx.options && ctx.options.transaction)
myOptions.transaction = ctx.options.transaction; myOptions.transaction = ctx.options.transaction;
const claimBeginning = await Self.findById(ctx.where.id); const claimBeginning = ctx.instance ?? await Self.findById(ctx.where.id);
const filter = { const filter = {
where: {id: claimBeginning.claimFk}, where: {id: claimBeginning.claimFk},

View File

@ -92,5 +92,87 @@
"model": "WorkerTeamCollegues", "model": "WorkerTeamCollegues",
"foreignKey": "workerFk" "foreignKey": "workerFk"
} }
},
"scopes":{
"summary": {
"include": [
{
"relation": "user",
"scope": {
"fields": ["email", "name", "nickname", "roleFk"],
"include": [
{
"relation": "role",
"scope": {
"fields": ["name"]
}
},
{
"relation": "emailUser",
"scope": {
"fields": ["email"]
}
}
]
}
}, {
"relation": "department",
"scope": {
"include": {
"relation": "department"
}
}
}, {
"relation": "boss"
}, {
"relation": "client",
"scope": {
"fields": [
"id",
"name",
"fi",
"socialName",
"contact",
"street",
"city",
"postcode",
"email",
"mobile",
"isActive",
"credit",
"creditInsurance",
"iban",
"dueDay",
"isEqualizated",
"isFreezed",
"hasToInvoiceByAddress",
"hasToInvoice",
"isToBeMailed",
"hasSepaVnl",
"hasLcr",
"hasCoreVnl",
"hasCoreVnh",
"hasIncoterms",
"isTaxDataChecked",
"eypbc",
"quality",
"isVies",
"isRelevant",
"accountingAccount",
"created",
"sageTaxTypeFk",
"sageTransactionTypeFk",
"businessTypeFk",
"salesPersonFk",
"hasElectronicInvoice",
"rating",
"recommendedCredit"
]
}
}, {
"relation": "sip"
}
]
}
} }
} }

View File

@ -4,37 +4,13 @@ import ModuleCard from 'salix/components/module-card';
class Controller extends ModuleCard { class Controller extends ModuleCard {
reload() { reload() {
const filter = { const filter = {
include: [ where: {
{ id: this.$params.id}
relation: 'user',
scope: {
fields: ['name', 'emailVerified'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}, {
relation: 'sip',
scope: {
fields: ['extension', 'secret']
}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
}; };
return Promise.all([ return Promise.all([
this.$http.get(`Workers/${this.$params.id}`, {filter}) this.$http.get(`Workers/summary`, {filter})
.then(res => this.worker = res.data), .then(res => this.worker = res.data[0]),
this.$http.get(`Workers/${this.$params.id}/activeContract`) this.$http.get(`Workers/${this.$params.id}/activeContract`)
.then(res => this.hasWorkCenter = res.data?.workCenterFk) .then(res => this.hasWorkCenter = res.data?.workCenterFk)
]); ]);

View File

@ -37,41 +37,11 @@ class Controller extends Descriptor {
loadData() { loadData() {
const filter = { const filter = {
include: [ where: {id: this.id},
{
relation: 'user',
scope: {
fields: ['name', 'emailVerified'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}, {
relation: 'client',
scope: {
fields: ['fi']
}
}, {
relation: 'sip',
scope: {
fields: ['extension']
}
}, {
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
}; };
return this.getData(`Workers/${this.id}`, {filter}) return this.getData(`Workers/summary`, {filter})
.then(res => this.entity = res.data); .then(res => this.entity = res.data[0]);
} }
getPassRequirements() { getPassRequirements() {

View File

@ -14,14 +14,14 @@ describe('vnWorkerDescriptor', () => {
describe('loadData()', () => { describe('loadData()', () => {
it(`should perform a get query to store the worker data into the controller`, () => { it(`should perform a get query to store the worker data into the controller`, () => {
const id = 1; const id = 1;
const response = 'foo'; const response = ['foo'];
$httpBackend.whenGET('UserConfigs/getUserConfig').respond({}); $httpBackend.whenGET('UserConfigs/getUserConfig').respond({});
$httpBackend.expectRoute('GET', `Workers/${id}`).respond(response); $httpBackend.expectRoute('GET', `Workers/summary`).respond(response);
controller.id = id; controller.id = id;
$httpBackend.flush(); $httpBackend.flush();
expect(controller.worker).toEqual(response); expect([controller.worker]).toEqual(response);
}); });
}); });

View File

@ -10,53 +10,14 @@ class Controller extends Summary {
this.$.worker = null; this.$.worker = null;
if (!value) return; if (!value) return;
const query = `Workers/${value.id}`;
const filter = { const filter = {
include: [ where: {
{ id: value.id
relation: 'user', }
scope: {
fields: ['name', 'roleFk'],
include: [{
relation: 'role',
scope: {
fields: ['name']
}
},
{
relation: 'emailUser',
scope: {
fields: ['email']
}
}]
}
},
{
relation: 'client',
scope: {fields: ['fi', 'phone']}
},
{
relation: 'boss',
scope: {fields: ['id', 'name']}
},
{
relation: 'sip',
scope: {fields: ['extension']}
},
{
relation: 'department',
scope: {
include: {
relation: 'department',
scope: {fields: ['id', 'code', 'name']}
}
}
}
]
}; };
this.$http.get(query, {params: {filter}}).then(res => { this.$http.get(`Workers/summary`, {filter}).then(res => {
this.$.worker = res.data; this.$.worker = res.data[0];
}); });
} }