8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
7 changed files with 80 additions and 1 deletions
Showing only changes of commit 38ee76f7c9 - Show all commits

View File

@ -0,0 +1,29 @@
module.exports = Self => {
Self.remoteMethodCtx('killSession', {
description: 'Kill session',
accepts: [{
arg: 'userId',
type: 'integer',
description: 'The user id',
required: true,
}, {
arg: 'created',
type: 'date',
description: 'The created time',
required: true,
}],
accessType: 'WRITE',
http: {
path: `/killSession`,
verb: 'POST'
}
});
Self.killSession = async function(ctx, userId, created) {
await Self.app.models.VnUser.userSecurity(ctx, ctx.req.accessToken.userId);
const tokens = await Self.app.models.AccessToken.find({where: {userId, created}});
if (!tokens?.length) return;
for (const token of tokens)
await Self.app.models.AccessToken.deleteById(token.id);
};
};

View File

@ -175,6 +175,9 @@
"ViaexpressConfig": {
"dataSource": "vn"
},
"VnToken": {
"dataSource": "vn"
},
"VnUser": {
"dataSource": "vn"
},

5
back/models/vn-token.js Normal file
View File

@ -0,0 +1,5 @@
const vnModel = require('vn-loopback/common/models/vn-model');
module.exports = function(Self) {
vnModel(Self);
require('../methods/vn-token/killSession')(Self);
};

22
back/models/vn-token.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "VnToken",
"base": "AccessToken",
"options": {
"mysql": {
"table": "salix.AccessToken"
}
},
"properties": {
"created": {
"type": "date"
}
},
"relations": {
"user": {
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userId"
}
},
"hidden": ["id"]
}

View File

@ -25,6 +25,9 @@
"isManaged": {
"type": "boolean"
},
"isDestiny": {
"type": "boolean"
},
"countryFk": {
"type": "number"
}

View File

@ -0,0 +1,13 @@
UPDATE `salix`.`ACL`
SET accessType='READ'
WHERE model = 'ACL';
UPDATE `salix`.`ACL`
SET principalId='developerBoss'
WHERE model = 'AccessToken';
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('VnToken', '*', 'READ', 'ALLOW', 'ROLE', 'developer'),
('VnToken', 'killSession', '*', 'ALLOW', 'ROLE', 'developer'),
('ACL', '*', 'WRITE', 'ALLOW', 'ROLE', 'developerBoss');

View File

@ -128,6 +128,9 @@ module.exports = Self => {
return {[param]: value};
}
});
if (ctx.req.query?.showBadDates === 'true')
where['fp.started'] = {gte: Date.vnNew()};
filter = mergeFilters(filter, {where});
const stmts = [];
@ -136,6 +139,7 @@ module.exports = Self => {
SELECT DISTINCT fp.id,
fp.itemFk,
fp.warehouseFk,
w.name warehouseName,
fp.rate2,
fp.rate3,
fp.started,
@ -159,6 +163,7 @@ module.exports = Self => {
FROM priceFixed fp
JOIN item i ON i.id = fp.itemFk
JOIN itemType it ON it.id = i.typeFk
JOIN warehouse w ON fp.warehouseFk = w.id
`);
if (ctx.args.tags) {
@ -184,7 +189,6 @@ module.exports = Self => {
}
stmt.merge(conn.makeSuffix(filter));
const fixedPriceIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);