refs #6427 feat: not update phone when is not owner
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
f0eeb2e28b
commit
a1a6e483cf
|
@ -355,5 +355,7 @@
|
||||||
"No results found": "No se han encontrado resultados",
|
"No results found": "No se han encontrado resultados",
|
||||||
"Phone not valid": "Teléfono no es válido",
|
"Phone not valid": "Teléfono no es válido",
|
||||||
"User not valid": "Usuario no válido",
|
"User not valid": "Usuario no válido",
|
||||||
"Credentials not valid": "Credenciales no válidas"
|
"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"
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
const validateTin = require('vn-loopback/util/validateTin');
|
const validateTin = require('vn-loopback/util/validateTin');
|
||||||
require('../methods/worker/filter')(Self);
|
require('../methods/worker/filter')(Self);
|
||||||
|
@ -42,24 +43,23 @@ module.exports = Self => {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx, next) {
|
||||||
// if (ctx.isNewInstance) return;
|
if (ctx.isNewInstance) return;
|
||||||
// const isOwner = await checkModifyPermission(ctx);
|
const isOwner = await checkModifyPermission(ctx);
|
||||||
|
const phoneHasChanged = !!ctx.data.user?.recoveryPhone;
|
||||||
|
|
||||||
// const worker = await Self.findById(ctx.currentInstance.id, {
|
const {models} = Self.app;
|
||||||
// include: {relation: 'user', scope: {
|
if (!isOwner) {
|
||||||
// fields: ['name', 'emailVerified', 'recoveryPhone']}}
|
if (phoneHasChanged)
|
||||||
// });
|
throw new UserError('Phone can\'t be updated');
|
||||||
|
else {
|
||||||
// || ctx.data.user.recoveryPhone !== worker.user().recoveryPhone;
|
const {recoveryPhone} = ctx.data.user;
|
||||||
// const phoneHasChanged = !!ctx.data.user?.recoveryPhone;
|
const {id} = ctx.currentInstance;
|
||||||
// if (!isOwner && phoneHasChanged)
|
await models.VnUser.updateAll({id}, {recoveryPhone});
|
||||||
// throw new UserError('This worker cant be modified');
|
ctx.data.code = ctx.currentInstance.code;
|
||||||
|
}
|
||||||
// const {models} = Self.app;
|
}
|
||||||
// if (phoneHasChanged)
|
delete ctx.data.user;
|
||||||
// await models.VnUser.updateAll({id: ctx.currentInstance.id}, {recoveryPhone: ctx.data.user.recoveryPhone});
|
|
||||||
// return;
|
|
||||||
});
|
});
|
||||||
async function checkModifyPermission(ctx) {
|
async function checkModifyPermission(ctx) {
|
||||||
const instanceId = ctx.currentInstance.id;
|
const instanceId = ctx.currentInstance.id;
|
||||||
|
|
Loading…
Reference in New Issue