Compare commits

...

13 Commits

Author SHA1 Message Date
Robert Ferrús 0e2dcbce0c Merge branch 'master' into 8108-itemTags
gitea/salix/pipeline/pr-master This commit looks good Details
2024-10-17 11:31:52 +00:00
Alex Moreno 76415e507d Merge pull request 'MASTER feat(Docuware): refs #8066 use oath' (!3084) from 8066-docuware_oauth into master
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3084
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2024-10-17 07:09:07 +00:00
Alex Moreno c355fcfece test(docuware_core): refs #8066 adapt
gitea/salix/pipeline/pr-master This commit looks good Details
2024-10-16 09:03:47 +02:00
Alex Moreno ccaec1a2cf Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 8066-docuware_oauth 2024-10-16 08:41:50 +02:00
Sergio De la torre 15622a3e68 Merge pull request 'fix: refs #6861 getTickets' (!3106) from 6861-itemShelvingSaleTickets into master
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-test This commit looks good Details
Reviewed-on: #3106
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
2024-10-16 05:58:52 +00:00
Sergio De la torre 12abca0a2d fix: refs #6861 getTickets
gitea/salix/pipeline/pr-master This commit looks good Details
2024-10-15 18:12:07 +02:00
Sergio De la torre 2adc424ccb fix: refs #6861 getTickets
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-15 17:07:35 +02:00
Sergio De la torre b592ccc162 fix: refs #6861 getTickets
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-15 17:01:09 +02:00
Alex Moreno b1b36a33a0 chore(docuware_core): refs #8066 add returns
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-15 09:47:39 +02:00
Alex Moreno 3c881d5e48 refactor(docuware): refs #8066 use Authorization
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-15 08:00:19 +02:00
Alex Moreno 394cf0d18b Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 8066-docuware_oauth
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-14 12:31:20 +02:00
Alex Moreno 9695fea48f feat(Docuware): refs #8066 add username and password
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-08 12:05:19 +02:00
Alex Moreno 952f8f3dfc feat(Docuware): refs #8066 use oath
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2024-10-07 15:14:03 +02:00
7 changed files with 134 additions and 100 deletions

View File

@ -62,7 +62,8 @@ module.exports = Self => {
p.code parkingCodePrevia, p.code parkingCodePrevia,
p.pickingOrder pickingOrderPrevia, p.pickingOrder pickingOrderPrevia,
iss.id itemShelvingSaleFk, iss.id itemShelvingSaleFk,
iss.isPicked iss.isPicked,
iss.itemShelvingFk
FROM ticketCollection tc FROM ticketCollection tc
LEFT JOIN collection c ON c.id = tc.collectionFk LEFT JOIN collection c ON c.id = tc.collectionFk
JOIN sale s ON s.ticketFk = tc.ticketFk JOIN sale s ON s.ticketFk = tc.ticketFk
@ -102,7 +103,8 @@ module.exports = Self => {
p.code, p.code,
p.pickingOrder, p.pickingOrder,
iss.id itemShelvingSaleFk, iss.id itemShelvingSaleFk,
iss.isPicked iss.isPicked,
iss.itemShelvingFk
FROM sectorCollection sc FROM sectorCollection sc
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
JOIN saleGroup sg ON sg.id = ss.saleGroupFk JOIN saleGroup sg ON sg.id = ss.saleGroupFk

View File

@ -4,21 +4,45 @@ module.exports = Self => {
/** /**
* Returns basic headers * Returns basic headers
* *
* @param {string} cookie - The docuware cookie
* @return {object} - The headers * @return {object} - The headers
*/ */
Self.getOptions = async() => { Self.getOptions = async() => {
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
const now = Date.vnNow();
let {url, username, password, token, expired} = docuwareConfig;
if (process.env.NODE_ENV && (!expired || expired < now + 60)) {
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
const {data} = await axios.post(token_endpoint, {
grant_type: 'password',
scope: 'docuware.platform',
client_id: 'docuware.platform.net.client',
username,
password
}, {headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}});
const newToken = data.access_token;
token = data.token_type + ' ' + newToken;
await docuwareConfig.updateAttributes({
token,
expired: now + data.expires_in
});
}
const headers = { const headers = {
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Cookie': docuwareConfig.cookie 'Authorization': token
} }
}; };
return { return {
url: docuwareConfig.url, url,
headers headers
}; };
}; };

View File

@ -2,87 +2,54 @@ const axios = require('axios');
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('Docuware core', () => { describe('Docuware core', () => {
beforeAll(() => { const fileCabinetCode = 'deliveryNote';
beforeAll(async() => {
process.env.NODE_ENV = 'testing'; process.env.NODE_ENV = 'testing';
});
afterAll(() => { const docuwareInfo = await models.Docuware.findOne({
delete process.env.NODE_ENV; where: {
}); code: fileCabinetCode
}
describe('getOptions()', () => {
it('should return url and headers', async() => {
const result = await models.Docuware.getOptions();
expect(result.url).toBeDefined();
expect(result.headers).toBeDefined();
}); });
});
describe('getDialog()', () => { spyOn(axios, 'get').and.callFake(url => {
it('should return dialogId', async() => { if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}};
const dialogs = { if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}};
data: { if (url.includes('dialogs')) {
Dialog: [ return {
{ data: {
DisplayName: 'find', Dialog: [
Id: 'getDialogTest' {
} DisplayName: 'find',
] Id: 'getDialogTest'
} }
}; ]
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); }
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); };
}
expect(result).toEqual('getDialogTest'); if (url.includes('FileCabinets')) {
}); return {data: {
});
describe('getFileCabinet()', () => {
it('should return fileCabinetId', async() => {
const code = 'deliveryNote';
const docuwareInfo = await models.Docuware.findOne({
where: {
code
}
});
const dialogs = {
data: {
FileCabinet: [ FileCabinet: [
{ {
Name: docuwareInfo.fileCabinetName, Name: docuwareInfo.fileCabinetName,
Id: 'getFileCabinetTest' Id: 'getFileCabinetTest'
} }
] ]
} }};
}; }
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
const result = await models.Docuware.getFileCabinet(code);
expect(result).toEqual('getFileCabinetTest');
});
});
describe('get()', () => {
it('should return data without parse', async() => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
const data = {
data: {
id: 1
}
};
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const result = await models.Docuware.get('deliveryNote');
expect(result.id).toEqual(1);
}); });
it('should return data with parse', async() => { spyOn(axios, 'post').and.callFake(url => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); if (url.includes('token_endpoint')) {
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); return {data: {
const data = { access_token: 'access_token',
data: { token_type: 'bearer',
expires_in: 10000
}};
}
if (url.includes('DialogExpression')) {
return {data: {
Items: [{ Items: [{
Fields: [ Fields: [
{ {
@ -103,12 +70,52 @@ describe('Docuware core', () => {
] ]
}] }]
} }
}; };
}
});
});
afterAll(() => {
delete process.env.NODE_ENV;
});
describe('getOptions()', () => {
it('should return url and headers', async() => {
const result = await models.Docuware.getOptions();
expect(result.url).toBeDefined();
expect(result.headers).toBeDefined();
});
});
describe('Dialog()', () => {
it('should return dialogId', async() => {
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
expect(result).toEqual('getDialogTest');
});
});
describe('getFileCabinet()', () => {
it('should return fileCabinetId', async() => {
const result = await models.Docuware.getFileCabinet(fileCabinetCode);
expect(result).toEqual('getFileCabinetTest');
});
});
describe('get()', () => {
it('should return data without parse', async() => {
const [result] = await models.Docuware.get('deliveryNote');
expect(result.firstRequiredField).toEqual(1);
});
it('should return data with parse', async() => {
const parse = { const parse = {
'firstRequiredField': 'id', 'firstRequiredField': 'id',
'secondRequiredField': 'name', 'secondRequiredField': 'name',
}; };
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const [result] = await models.Docuware.get('deliveryNote', null, parse); const [result] = await models.Docuware.get('deliveryNote', null, parse);
expect(result.id).toEqual(1); expect(result.id).toEqual(1);
@ -119,17 +126,14 @@ describe('Docuware core', () => {
describe('getById()', () => { describe('getById()', () => {
it('should return data', async() => { it('should return data', async() => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(models.Docuware, 'get');
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); await models.Docuware.getById('deliveryNote', 1);
const data = {
data: {
id: 1
}
};
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const result = await models.Docuware.getById('deliveryNote', 1);
expect(result.id).toEqual(1); expect(models.Docuware.get).toHaveBeenCalledWith(
'deliveryNote',
{condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]},
undefined
);
}); });
}); });
}); });

View File

@ -143,7 +143,7 @@ module.exports = Self => {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
'X-File-ModifiedDate': Date.vnNew(), 'X-File-ModifiedDate': Date.vnNew(),
'Cookie': docuwareOptions.headers.headers.Cookie, 'Authorization': docuwareOptions.headers.headers.Authorization,
...data.getHeaders() ...data.getHeaders()
}, },
}; };

View File

@ -16,17 +16,17 @@
"url": { "url": {
"type": "string" "type": "string"
}, },
"cookie": { "token": {
"type": "string" "type": "string"
},
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"expired":{
"type": "number"
} }
}, }
"acls": [
{
"property": "*",
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
} }

View File

@ -3,10 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterI
AFTER INSERT ON `itemShelvingSale` AFTER INSERT ON `itemShelvingSale`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
UPDATE sale s UPDATE sale s
JOIN operator o ON o.workerFk = account.myUser_getId() JOIN operator o ON o.workerFk = account.myUser_getId()
SET s.isPicked = IF(o.isOnReservationMode, s.isPicked, TRUE) JOIN sector se ON se.id = o.sectorFk
WHERE id = NEW.saleFk; SET s.isPicked = IF(IFNULL(se.isOnReservationMode, o.isOnReservationMode), s.isPicked, TRUE)
WHERE s.id = NEW.saleFk;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,4 @@
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL;