test ok
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2021-04-22 09:06:08 +02:00
parent 2630fa8c43
commit 4a7a4f6dcf
2 changed files with 7 additions and 12 deletions

View File

@ -1,16 +1,13 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const LoopBackContext = require('loopback-context');
module.exports = Self => { module.exports = Self => {
Self.observe('before save', async ctx => { Self.observe('before save', async ctx => {
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = {req: loopBackContext.active};
const models = Self.app.models; const models = Self.app.models;
let changes = ctx.currentInstance || ctx.instance; let changes = ctx.currentInstance || ctx.instance;
if (changes) { if (changes) {
let ticketId = changes.ticketFk; let ticketId = changes.ticketFk;
let isEditable = await models.Ticket.isEditable(httpCtx, ticketId); let isLocked = await models.Ticket.isLocked(ticketId);
if (!isEditable) if (isLocked)
throw new UserError(`The current ticket can't be modified`); throw new UserError(`The current ticket can't be modified`);
if (changes.ticketServiceTypeFk) { if (changes.ticketServiceTypeFk) {
@ -21,13 +18,11 @@ module.exports = Self => {
}); });
Self.observe('before delete', async ctx => { Self.observe('before delete', async ctx => {
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = {req: loopBackContext.active};
const models = Self.app.models; const models = Self.app.models;
const service = await models.TicketService.findById(ctx.where.id); const service = await models.TicketService.findById(ctx.where.id);
const isEditable = await models.Ticket.isEditable(httpCtx, service.ticketFk); const isLocked = await models.Ticket.isLocked(service.ticketFk);
if (!isEditable) if (isLocked)
throw new UserError(`The current ticket can't be modified`); throw new UserError(`The current ticket can't be modified`);
}); });
}; };

6
package-lock.json generated
View File

@ -17073,9 +17073,9 @@
} }
}, },
"ssri": { "ssri": {
"version": "6.0.1", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz",
"integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", "integrity": "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"figgy-pudding": "^3.5.1" "figgy-pudding": "^3.5.1"