From 9cf4ef04c5a013a25746ead10fca1840bc947f67 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 6 May 2024 14:53:41 +0200 Subject: [PATCH] feat(salix): refs #6427 #6427 Use UserSecurity instead validation --- .../components/recover-password/index.html | 7 ---- .../components/recover-password/locale/es.yml | 2 +- loopback/locale/es.json | 7 ++-- modules/worker/back/models/worker.js | 36 ++++++++++--------- modules/worker/front/basic-data/index.html | 1 - 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/front/salix/components/recover-password/index.html b/front/salix/components/recover-password/index.html index 4348cb1eb..935ab497c 100644 --- a/front/salix/components/recover-password/index.html +++ b/front/salix/components/recover-password/index.html @@ -4,13 +4,6 @@ ng-model="$ctrl.user" vn-focus> - { Self.observe('before save', async function(ctx, next) { if (ctx.isNewInstance) return; - const isOwner = await checkModifyPermission(ctx); + const instanceId = ctx.currentInstance.id; + const userId = ctx.options.accessToken.userId; + const isOwner = instanceId === userId; const phoneHasChanged = !!ctx.data.user?.recoveryPhone; - - const {models} = Self.app; + try { + await Self.app.models.VnUser.userSecurity(ctx, ctx.where.id); + } catch (error) { + throw new UserError('Phone can\'t be updated'); + } if (!isOwner) { - if (phoneHasChanged) - throw new UserError('Phone can\'t be updated'); - else { + if (phoneHasChanged) { const {recoveryPhone} = ctx.data.user; const {id} = ctx.currentInstance; - await models.VnUser.updateAll({id}, {recoveryPhone}); + await Self.app.models.VnUser.updateAll({id}, {recoveryPhone}); ctx.data.code = ctx.currentInstance.code; } } delete ctx.data.user; }); - async function checkModifyPermission(ctx) { - const instanceId = ctx.currentInstance.id; - const userId = ctx.options.accessToken.userId; - try { - return (instanceId == userId); - } catch (error) { - throw new UserError(error); - } - } +// async function checkModifyPermission(ctx) { +// const instanceId = ctx.currentInstance.id; +// const userId = ctx.options.accessToken.userId; +// try { +// if (instanceId === userId) return true; +// return +// } catch (error) { +// throw new UserError(error); +// } +// } }; diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index a8b404da6..f764b3137 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -79,7 +79,6 @@ vn-one label="Recovery phone" ng-model="$ctrl.worker.user.recoveryPhone" - disabled="$root.user.id !== $ctrl.worker.id" >