feat: antes de bloquear comprobar que no existe un bloqueo previo
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-11-23 10:41:32 +01:00
parent 9cfab2b3f4
commit 6a2af344aa
4 changed files with 40 additions and 2 deletions

View File

@ -2735,4 +2735,4 @@ INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`
INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`)
VALUES
('com', 'master', NULL, NULL),
('ent', 'test', NULL, NULL);
('ent', 'test', 9, util.VN_NOW());

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('lock', {
description: 'Lock an app for the user',
@ -26,6 +28,7 @@ module.exports = Self => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
const $t = ctx.req.__; // $translate
let tx;
@ -39,6 +42,12 @@ module.exports = Self => {
try {
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
const message = $t('App locked', {
userId: mdbApp.userFk
});
if (mdbApp.locked) throw new UserError(message);
const updatedMdbApp = await mdbApp.updateAttributes({
userFk: userId,
locked: new Date()

View File

@ -1,6 +1,35 @@
const models = require('vn-loopback/server/server').models;
describe('MdbApp lock()', () => {
it('should throw an error if the app is already locked', async() => {
const tx = await models.MdbApp.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const appName = 'ent';
const developerId = 9;
const ctx = {
req: {
accessToken: {userId: developerId},
__: () => {}
}
};
const result = await models.MdbApp.lock(ctx, appName, options);
expect(result.locked).not.toBeNull();
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error).toBeDefined();
});
it(`should lock a mdb `, async() => {
const tx = await models.MdbApp.beginTransaction({});

View File

@ -65,7 +65,7 @@ module.exports = Self => {
try {
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
const message = $t('App locked', {
userId: userId
userId: mdbApp.userFk
});
if (mdbApp.locked && mdbApp.userFk != userId) throw new UserError(message);