diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index ddaae8548..437ff9f84 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -20,6 +20,10 @@ module.exports = Self => { arg: 'email', type: 'string', description: 'The user email' + }, { + arg: 'recoveryPhone', + type: 'string', + description: 'The user email' }, { arg: 'lang', type: 'string', @@ -32,8 +36,8 @@ module.exports = Self => { } }); - Self.updateUser = async(ctx, id, name, nickname, email, lang) => { + Self.updateUser = async(ctx, id, name, nickname, email, recoveryPhone, lang) => { await Self.userSecurity(ctx, id); - await Self.upsertWithWhere({id}, {name, nickname, email, lang}); + await Self.upsertWithWhere({id}, {name, nickname, email, recoveryPhone, lang}); }; }; diff --git a/back/models/vn-user.js b/back/models/vn-user.js index dc1d6dfae..dbd323f30 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -232,6 +232,8 @@ module.exports = function(Self) { const user = await models.VnUser.findById(userId, {fields: ['id', 'emailVerified']}, myOptions); if (!user.emailVerified && hasMediumPrivileges) return; + if (ctx.args.recoveryPhone) throw new ForbiddenError(); + throw new ForbiddenError(); }; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 2115c5997..d95ba6d70 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -359,12 +359,5 @@ "It was not able to create the invoice": "No se pudo crear la factura", "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", "This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario", - "You can only have one PDA": "Solo puedes tener un PDA", - "Phone not valid": "Teléfono no es válido", - "User not valid": "Usuario no válido", - "Credentials not valid": "Credenciales no válidas", - "This worker cant be modified": "This worker cant be modified", - "Phone can't be updated": "Phone can't be updated", - "ReferenceError: models is not defined": "ReferenceError: models is not defined" - + "You can only have one PDA": "Solo puedes tener un PDA" } diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index dab486333..0b0e043f2 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -1,4 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { const validateTin = require('vn-loopback/util/validateTin'); require('../methods/worker/filter')(Self); @@ -39,22 +38,4 @@ module.exports = Self => { err(); done(); } - - Self.observe('before save', async function(ctx, next) { - if (ctx.isNewInstance) return; - const instanceId = ctx.currentInstance.id; - const userId = ctx.options.accessToken.userId; - const isOwner = instanceId === userId; - const phoneHasChanged = !!ctx.data.user?.recoveryPhone; - - if (!isOwner) { - if (phoneHasChanged) { - const {recoveryPhone} = ctx.data.user; - const {id} = ctx.currentInstance; - await Self.app.models.VnUser.updateAll({id}, {recoveryPhone}); - ctx.data.code = ctx.currentInstance.code; - } - } - delete ctx.data.user; - }); };