From ee1ce21bb988fdefd67d7d00c6908cef6da76a28 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 23 Jan 2023 15:24:00 +0100 Subject: [PATCH] refactor(account): account model refactor --- back/methods/chat/send.js | 2 +- back/methods/chat/sendCheckingPresence.js | 4 +- back/methods/chat/sendQueued.js | 4 +- back/methods/{account => vn-user}/acl.js | 2 +- .../{account => vn-user}/change-password.js | 0 .../{account => vn-user}/privileges.js | 15 +- .../{account => vn-user}/recover-password.js | 0 .../{account => vn-user}/set-password.js | 0 .../{account/login.js => vn-user/signIn.js} | 15 +- .../{account/logout.js => vn-user/signOut.js} | 8 +- .../specs/change-password.spec.js | 2 +- .../{account => vn-user}/specs/login.spec.js | 10 +- .../{account => vn-user}/specs/logout.spec.js | 8 +- .../specs/privileges.spec.js | 26 ++-- .../specs/set-password.spec.js | 6 +- .../{account => vn-user}/validate-token.js | 0 back/model-config.json | 6 +- back/models/account.js | 139 ------------------ back/models/dms-type.js | 4 +- back/models/image-collection.js | 4 +- back/models/specs/user.spec.js | 6 +- .../{account.spec.js => vn-user.spec.js} | 6 +- back/models/user.js | 2 +- back/models/user.json | 22 +-- back/models/vn-user.js | 92 ++++++++++++ back/models/{account.json => vn-user.json} | 36 ++--- db/changes/230401/00-ACL.sql | 17 +++ front/core/directives/specs/acl.spec.js | 2 +- front/core/lib/specs/acl-service.spec.js | 2 +- front/core/services/acl-service.js | 2 +- front/core/services/auth.js | 4 +- front/salix/components/layout/index.js | 2 +- front/salix/components/layout/index.spec.js | 2 +- .../components/recover-password/index.js | 2 +- loopback/common/models/vn-model.js | 2 +- .../back/methods/user-account/sync-by-id.js | 2 +- .../account/back/methods/user-account/sync.js | 2 +- modules/account/back/models/account-config.js | 2 +- modules/account/back/models/sip-config.js | 2 +- modules/account/front/card/index.js | 2 +- modules/account/front/card/index.spec.js | 2 +- modules/account/front/descriptor/index.js | 6 +- .../account/front/descriptor/index.spec.js | 4 +- modules/account/front/privileges/index.html | 2 +- modules/account/front/summary/index.js | 2 +- .../back/methods/claim/createFromSales.js | 2 +- .../claim/back/methods/claim/isEditable.js | 2 +- .../claim/back/methods/claim/updateClaim.js | 4 +- .../back/methods/client/createWithUser.js | 2 +- .../client/back/methods/client/setPassword.js | 2 +- .../client/specs/createWithUser.spec.js | 4 +- .../methods/client/specs/updateUser.spec.js | 2 +- .../back/methods/client/updateAddress.js | 2 +- .../back/methods/client/updateFiscalData.js | 2 +- .../client/back/methods/client/updateUser.js | 6 +- modules/client/back/models/client.js | 14 +- .../client/back/models/specs/client.spec.js | 6 +- .../back/models/specs/clientCredit.spec.js | 2 +- .../back/methods/invoiceOut/createPdf.js | 2 +- modules/supplier/back/models/supplier.js | 2 +- .../back/methods/state/editableStates.js | 6 +- .../ticket/back/methods/state/isEditable.js | 6 +- .../back/methods/ticket/componentUpdate.js | 2 +- .../back/methods/ticket/isRoleAdvanced.js | 8 +- .../back/methods/ticket/priceDifference.js | 2 +- .../ticket/back/methods/ticket/setDeleted.js | 2 +- .../back/methods/ticket/transferSales.js | 2 +- .../back/methods/ticket/updateDiscount.js | 2 +- .../worker/back/methods/worker-dms/filter.js | 2 +- .../worker-time-control/addTimeEntry.js | 2 +- .../worker-time-control/deleteTimeEntry.js | 2 +- .../worker-time-control/updateTimeEntry.js | 2 +- .../back/methods/worker/createAbsence.js | 6 +- .../back/methods/worker/deleteAbsence.js | 6 +- .../back/methods/worker/isSubordinate.js | 2 +- modules/worker/back/methods/worker/new.js | 4 +- .../specs/activeWithInheritedRole.spec.js | 4 +- .../back/methods/worker/specs/new.spec.js | 4 +- .../back/methods/worker/updateAbsence.js | 2 +- modules/worker/front/account/index.html | 2 +- modules/zone/back/methods/agency/getLanded.js | 2 +- .../back/methods/zone/includingExpired.js | 2 +- 82 files changed, 285 insertions(+), 321 deletions(-) rename back/methods/{account => vn-user}/acl.js (95%) rename back/methods/{account => vn-user}/change-password.js (100%) rename back/methods/{account => vn-user}/privileges.js (80%) rename back/methods/{account => vn-user}/recover-password.js (100%) rename back/methods/{account => vn-user}/set-password.js (100%) rename back/methods/{account/login.js => vn-user/signIn.js} (80%) rename back/methods/{account/logout.js => vn-user/signOut.js} (70%) rename back/methods/{account => vn-user}/specs/change-password.spec.js (80%) rename back/methods/{account => vn-user}/specs/login.spec.js (75%) rename back/methods/{account => vn-user}/specs/logout.spec.js (79%) rename back/methods/{account => vn-user}/specs/privileges.spec.js (74%) rename back/methods/{account => vn-user}/specs/set-password.spec.js (64%) rename back/methods/{account => vn-user}/validate-token.js (100%) delete mode 100644 back/models/account.js rename back/models/specs/{account.spec.js => vn-user.spec.js} (63%) create mode 100644 back/models/vn-user.js rename back/models/{account.json => vn-user.json} (73%) create mode 100644 db/changes/230401/00-ACL.sql diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index c5c8feead..b751b97b8 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -26,7 +26,7 @@ module.exports = Self => { Self.send = async(ctx, to, message) => { const models = Self.app.models; const accessToken = ctx.req.accessToken; - const sender = await models.Account.findById(accessToken.userId); + const sender = await models.VnUser.findById(accessToken.userId); const recipient = to.replace('@', ''); if (sender.name != recipient) { diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 075591969..9dbb51469 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -34,8 +34,8 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; - const sender = await models.Account.findById(userId); - const recipient = await models.Account.findById(recipientId, null, myOptions); + const sender = await models.VnUser.findById(userId); + const recipient = await models.VnUser.findById(recipientId, null, myOptions); // Prevent sending messages to yourself if (recipientId == userId) return false; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 66fbfcdc5..54733cd00 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -56,7 +56,7 @@ module.exports = Self => { const models = Self.app.models; const recipientName = chat.recipient.slice(1); - const recipient = await models.Account.findOne({ + const recipient = await models.VnUser.findOne({ where: { name: recipientName } @@ -102,7 +102,7 @@ module.exports = Self => { } const models = Self.app.models; - const sender = await models.Account.findById(senderFk); + const sender = await models.VnUser.findById(senderFk); const login = await Self.getServiceAuth(); const avatar = `${login.host}/avatar/${sender.name}`; diff --git a/back/methods/account/acl.js b/back/methods/vn-user/acl.js similarity index 95% rename from back/methods/account/acl.js rename to back/methods/vn-user/acl.js index bc1990e1d..ab3efd287 100644 --- a/back/methods/account/acl.js +++ b/back/methods/vn-user/acl.js @@ -22,7 +22,7 @@ module.exports = Self => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let user = await models.Account.findById(userId, { + let user = await models.VnUser.findById(userId, { fields: ['id', 'name', 'nickname', 'email', 'lang'], include: { relation: 'userConfig', diff --git a/back/methods/account/change-password.js b/back/methods/vn-user/change-password.js similarity index 100% rename from back/methods/account/change-password.js rename to back/methods/vn-user/change-password.js diff --git a/back/methods/account/privileges.js b/back/methods/vn-user/privileges.js similarity index 80% rename from back/methods/account/privileges.js rename to back/methods/vn-user/privileges.js index 5c5e7409d..8e09a7d63 100644 --- a/back/methods/account/privileges.js +++ b/back/methods/vn-user/privileges.js @@ -1,9 +1,14 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethodCtx('privileges', { + Self.remoteMethod('privileges', { description: 'Change role and hasGrant if user has privileges', accepts: [ + { + arg: 'ctx', + type: 'Object', + http: {source: 'context'} + }, { arg: 'id', type: 'number', @@ -39,9 +44,9 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const user = await models.Account.findById(userId, {fields: ['hasGrant']}, myOptions); + const user = await models.VnUser.findById(userId, {fields: ['hasGrant']}, myOptions); - const userToUpdate = await models.Account.findById(id, { + const userToUpdate = await models.VnUser.findById(id, { fields: ['id', 'name', 'hasGrant', 'roleFk', 'password'], include: { relation: 'role', @@ -54,7 +59,7 @@ module.exports = Self => { if (!user.hasGrant) throw new UserError(`You don't have grant privilege`); - const hasRoleFromUser = await models.Account.hasRole(userId, userToUpdate.role().name, myOptions); + const hasRoleFromUser = await models.VnUser.hasRole(userId, userToUpdate.role().name, myOptions); if (!hasRoleFromUser) throw new UserError(`You don't own the role and you can't assign it to another user`); @@ -64,7 +69,7 @@ module.exports = Self => { if (roleFk) { const role = await models.Role.findById(roleFk, {fields: ['name']}, myOptions); - const hasRole = await models.Account.hasRole(userId, role.name, myOptions); + const hasRole = await models.VnUser.hasRole(userId, role.name, myOptions); if (!hasRole) throw new UserError(`You don't own the role and you can't assign it to another user`); diff --git a/back/methods/account/recover-password.js b/back/methods/vn-user/recover-password.js similarity index 100% rename from back/methods/account/recover-password.js rename to back/methods/vn-user/recover-password.js diff --git a/back/methods/account/set-password.js b/back/methods/vn-user/set-password.js similarity index 100% rename from back/methods/account/set-password.js rename to back/methods/vn-user/set-password.js diff --git a/back/methods/account/login.js b/back/methods/vn-user/signIn.js similarity index 80% rename from back/methods/account/login.js rename to back/methods/vn-user/signIn.js index 7393e8374..1b4b853f7 100644 --- a/back/methods/account/login.js +++ b/back/methods/vn-user/signIn.js @@ -2,13 +2,14 @@ const md5 = require('md5'); const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethod('login', { + Self.remoteMethod('signIn', { description: 'Login a user with username/email and password', accepts: [ { arg: 'user', type: 'String', description: 'The user name or email', + http: {source: 'form'}, required: true }, { arg: 'password', @@ -21,20 +22,20 @@ module.exports = Self => { root: true }, http: { - path: `/login`, + path: `/signIn`, verb: 'POST' } }); - Self.login = async function(user, password) { - let $ = Self.app.models; + Self.signIn = async function(user, password) { + let models = Self.app.models; let token; let usesEmail = user.indexOf('@') !== -1; let userInfo = usesEmail ? {email: user} : {username: user}; - let instance = await $.User.findOne({ + let instance = await models.User.findOne({ fields: ['username', 'password'], where: userInfo }); @@ -57,14 +58,14 @@ module.exports = Self => { throw new UserError('User disabled'); try { - await $.UserAccount.sync(instance.username, password); + await models.UserAccount.sync(instance.username, password); } catch (err) { console.warn(err); } } let loginInfo = Object.assign({password}, userInfo); - token = await $.User.login(loginInfo, 'user'); + token = await models.User.login(loginInfo, 'user'); return {token: token.id}; }; }; diff --git a/back/methods/account/logout.js b/back/methods/vn-user/signOut.js similarity index 70% rename from back/methods/account/logout.js rename to back/methods/vn-user/signOut.js index 515855267..35d444819 100644 --- a/back/methods/account/logout.js +++ b/back/methods/vn-user/signOut.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('logout', { + Self.remoteMethod('signOut', { description: 'Logout a user with access token', accepts: [ { @@ -13,13 +13,13 @@ module.exports = Self => { root: true }, http: { - path: `/logout`, + path: `/signOut`, verb: 'POST' } }); - Self.logout = async function(ctx) { - await Self.app.models.User.logout(ctx.req.accessToken.id); + Self.signOut = async function(ctx) { + await Self.app.models.VnUser.logout(ctx.req.accessToken.id); return true; }; }; diff --git a/back/methods/account/specs/change-password.spec.js b/back/methods/vn-user/specs/change-password.spec.js similarity index 80% rename from back/methods/account/specs/change-password.spec.js rename to back/methods/vn-user/specs/change-password.spec.js index 17fadb3c6..267fa11dd 100644 --- a/back/methods/account/specs/change-password.spec.js +++ b/back/methods/vn-user/specs/change-password.spec.js @@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server'); describe('account changePassword()', () => { it('should throw an error when old password is wrong', async() => { let err; - await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999') + await models.VnUser.changePassword(1, 'wrongPassword', 'nightmare.9999') .catch(error => err = error.sqlMessage); expect(err).toBeDefined(); diff --git a/back/methods/account/specs/login.spec.js b/back/methods/vn-user/specs/login.spec.js similarity index 75% rename from back/methods/account/specs/login.spec.js rename to back/methods/vn-user/specs/login.spec.js index 59eea2612..eba27aa9a 100644 --- a/back/methods/account/specs/login.spec.js +++ b/back/methods/vn-user/specs/login.spec.js @@ -3,23 +3,23 @@ const app = require('vn-loopback/server/server'); describe('account login()', () => { describe('when credentials are correct', () => { it('should return the token', async() => { - let login = await app.models.Account.login('salesAssistant', 'nightmare'); + let login = await app.models.VnUser.login('salesAssistant', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; expect(login.token).toBeDefined(); - await app.models.Account.logout(ctx); + await app.models.VnUser.logout(ctx); }); it('should return the token if the user doesnt exist but the client does', async() => { - let login = await app.models.Account.login('PetterParker', 'nightmare'); + let login = await app.models.VnUser.login('PetterParker', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; expect(login.token).toBeDefined(); - await app.models.Account.logout(ctx); + await app.models.VnUser.logout(ctx); }); }); @@ -28,7 +28,7 @@ describe('account login()', () => { let error; try { - await app.models.Account.login('IDontExist', 'TotallyWrongPassword'); + await app.models.VnUser.login('IDontExist', 'TotallyWrongPassword'); } catch (e) { error = e; } diff --git a/back/methods/account/specs/logout.spec.js b/back/methods/vn-user/specs/logout.spec.js similarity index 79% rename from back/methods/account/specs/logout.spec.js rename to back/methods/vn-user/specs/logout.spec.js index b3d69d6ef..f7275eb91 100644 --- a/back/methods/account/specs/logout.spec.js +++ b/back/methods/vn-user/specs/logout.spec.js @@ -2,11 +2,11 @@ const app = require('vn-loopback/server/server'); describe('account logout()', () => { it('should logout and remove token after valid login', async() => { - let loginResponse = await app.models.Account.login('buyer', 'nightmare'); + let loginResponse = await app.models.VnUser.login('buyer', 'nightmare'); let accessToken = await app.models.AccessToken.findById(loginResponse.token); let ctx = {req: {accessToken: accessToken}}; - let logoutResponse = await app.models.Account.logout(ctx); + let logoutResponse = await app.models.VnUser.logout(ctx); let tokenAfterLogout = await app.models.AccessToken.findById(loginResponse.token); expect(logoutResponse).toBeTrue(); @@ -18,7 +18,7 @@ describe('account logout()', () => { let ctx = {req: {accessToken: {id: 'invalidToken'}}}; try { - response = await app.models.Account.logout(ctx); + response = await app.models.VnUser.logout(ctx); } catch (e) { error = e; } @@ -32,7 +32,7 @@ describe('account logout()', () => { let ctx = {req: {accessToken: null}}; try { - response = await app.models.Account.logout(ctx); + response = await app.models.VnUser.logout(ctx); } catch (e) { error = e; } diff --git a/back/methods/account/specs/privileges.spec.js b/back/methods/vn-user/specs/privileges.spec.js similarity index 74% rename from back/methods/account/specs/privileges.spec.js rename to back/methods/vn-user/specs/privileges.spec.js index edfe0f03f..3d25eecf9 100644 --- a/back/methods/account/specs/privileges.spec.js +++ b/back/methods/vn-user/specs/privileges.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('account privileges()', () => { +describe('VnUser privileges()', () => { const employeeId = 1; const developerId = 9; const sysadminId = 66; @@ -10,13 +10,13 @@ describe('account privileges()', () => { it('should throw an error when user not has privileges', async() => { const ctx = {req: {accessToken: {userId: developerId}}}; - const tx = await models.Account.beginTransaction({}); + const tx = await models.VnUser.beginTransaction({}); let error; try { const options = {transaction: tx}; - await models.Account.privileges(ctx, employeeId, null, true, options); + await models.VnUser.privileges(ctx, employeeId, null, true, options); await tx.rollback(); } catch (e) { @@ -29,13 +29,13 @@ describe('account privileges()', () => { it('should throw an error when user has privileges but not has the role', async() => { const ctx = {req: {accessToken: {userId: sysadminId}}}; - const tx = await models.Account.beginTransaction({}); + const tx = await models.VnUser.beginTransaction({}); let error; try { const options = {transaction: tx}; - await models.Account.privileges(ctx, employeeId, rootId, null, options); + await models.VnUser.privileges(ctx, employeeId, rootId, null, options); await tx.rollback(); } catch (e) { @@ -48,13 +48,13 @@ describe('account privileges()', () => { it('should throw an error when user has privileges but not has the role from user', async() => { const ctx = {req: {accessToken: {userId: sysadminId}}}; - const tx = await models.Account.beginTransaction({}); + const tx = await models.VnUser.beginTransaction({}); let error; try { const options = {transaction: tx}; - await models.Account.privileges(ctx, itBossId, developerId, null, options); + await models.VnUser.privileges(ctx, itBossId, developerId, null, options); await tx.rollback(); } catch (e) { @@ -67,7 +67,7 @@ describe('account privileges()', () => { it('should change role', async() => { const ctx = {req: {accessToken: {userId: sysadminId}}}; - const tx = await models.Account.beginTransaction({}); + const tx = await models.VnUser.beginTransaction({}); const options = {transaction: tx}; const agency = await models.Role.findOne({ @@ -79,8 +79,8 @@ describe('account privileges()', () => { let error; let result; try { - await models.Account.privileges(ctx, clarkKent, agency.id, null, options); - result = await models.Account.findById(clarkKent, null, options); + await models.VnUser.privileges(ctx, clarkKent, agency.id, null, options); + result = await models.VnUser.findById(clarkKent, null, options); await tx.rollback(); } catch (e) { @@ -94,14 +94,14 @@ describe('account privileges()', () => { it('should change hasGrant', async() => { const ctx = {req: {accessToken: {userId: sysadminId}}}; - const tx = await models.Account.beginTransaction({}); + const tx = await models.VnUser.beginTransaction({}); let error; let result; try { const options = {transaction: tx}; - await models.Account.privileges(ctx, clarkKent, null, true, options); - result = await models.Account.findById(clarkKent, null, options); + await models.VnUser.privileges(ctx, clarkKent, null, true, options); + result = await models.VnUser.findById(clarkKent, null, options); await tx.rollback(); } catch (e) { diff --git a/back/methods/account/specs/set-password.spec.js b/back/methods/vn-user/specs/set-password.spec.js similarity index 64% rename from back/methods/account/specs/set-password.spec.js rename to back/methods/vn-user/specs/set-password.spec.js index fe71873de..3d6ae7338 100644 --- a/back/methods/account/specs/set-password.spec.js +++ b/back/methods/vn-user/specs/set-password.spec.js @@ -1,14 +1,14 @@ const app = require('vn-loopback/server/server'); -describe('account setPassword()', () => { +describe('VnUser setPassword()', () => { it('should throw an error when password does not meet requirements', async() => { - let req = app.models.Account.setPassword(1, 'insecurePass'); + let req = app.models.VnUser.setPassword(1, 'insecurePass'); await expectAsync(req).toBeRejected(); }); it('should update password when it passes requirements', async() => { - let req = app.models.Account.setPassword(1, 'Very$ecurePa22.'); + let req = app.models.VnUser.setPassword(1, 'Very$ecurePa22.'); await expectAsync(req).toBeResolved(); }); diff --git a/back/methods/account/validate-token.js b/back/methods/vn-user/validate-token.js similarity index 100% rename from back/methods/account/validate-token.js rename to back/methods/vn-user/validate-token.js diff --git a/back/model-config.json b/back/model-config.json index 29676e979..a2cd88756 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -1,7 +1,4 @@ { - "Account": { - "dataSource": "vn" - }, "AccountingType": { "dataSource": "vn" }, @@ -131,6 +128,9 @@ "Warehouse": { "dataSource": "vn" }, + "VnUser": { + "dataSource": "vn" + }, "OsTicket": { "dataSource": "osticket" }, diff --git a/back/models/account.js b/back/models/account.js deleted file mode 100644 index c2502380a..000000000 --- a/back/models/account.js +++ /dev/null @@ -1,139 +0,0 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ -const md5 = require('md5'); -const LoopBackContext = require('loopback-context'); -const {Email} = require('vn-print'); - -module.exports = Self => { - require('../methods/account/login')(Self); - require('../methods/account/logout')(Self); - require('../methods/account/acl')(Self); - require('../methods/account/change-password')(Self); - require('../methods/account/set-password')(Self); - require('../methods/account/recover-password')(Self); - require('../methods/account/validate-token')(Self); - require('../methods/account/privileges')(Self); - - // Validations - - Self.validatesFormatOf('email', { - message: 'Invalid email', - allowNull: true, - allowBlank: true, - with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/ - }); - - Self.validatesUniquenessOf('name', { - message: `A client with that Web User name already exists` - }); - - Self.observe('before save', async function(ctx) { - if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password) - ctx.data.password = md5(ctx.data.password); - }); - - Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => { - if (!ctx.args || !ctx.args.data.email) return; - const models = Self.app.models; - - const loopBackContext = LoopBackContext.getCurrentContext(); - const httpCtx = {req: loopBackContext.active}; - const httpRequest = httpCtx.req.http.req; - const headers = httpRequest.headers; - const origin = headers.origin; - const url = origin.split(':'); - - const userId = ctx.instance.id; - const user = await models.user.findById(userId); - - class Mailer { - async send(verifyOptions, cb) { - const params = { - url: verifyOptions.verifyHref, - recipient: verifyOptions.to, - lang: ctx.req.getLocale() - }; - - const email = new Email('email-verify', params); - email.send(); - - cb(null, verifyOptions.to); - } - } - - const options = { - type: 'email', - to: instance.email, - from: {}, - redirect: `${origin}/#!/account/${instance.id}/basic-data?emailConfirmed`, - template: false, - mailer: new Mailer, - host: url[1].split('/')[2], - port: url[2], - protocol: url[0], - user: Self - }; - - await user.verify(options); - }); - - Self.remoteMethod('getCurrentUserData', { - description: 'Gets the current user data', - accepts: [ - { - arg: 'ctx', - type: 'object', - http: {source: 'context'} - } - ], - returns: { - type: 'object', - root: true - }, - http: { - verb: 'GET', - path: '/getCurrentUserData' - } - }); - - Self.getCurrentUserData = async function(ctx) { - let userId = ctx.req.accessToken.userId; - return await Self.findById(userId, { - fields: ['id', 'name', 'nickname'] - }); - }; - - /** - * Checks if user has a role. - * - * @param {Integer} userId The user id - * @param {String} name The role name - * @param {object} options Options - * @return {Boolean} %true if user has the role, %false otherwise - */ - Self.hasRole = async function(userId, name, options) { - let roles = await Self.getRoles(userId, options); - return roles.some(role => role == name); - }; - - /** - * Get all user roles. - * - * @param {Integer} userId The user id - * @param {object} options Options - * @return {object} User role list - */ - Self.getRoles = async(userId, options) => { - let result = await Self.rawSql( - `SELECT r.name - FROM account.user u - JOIN account.roleRole rr ON rr.role = u.role - JOIN account.role r ON r.id = rr.inheritsFrom - WHERE u.id = ?`, [userId], options); - - let roles = []; - for (role of result) - roles.push(role.name); - - return roles; - }; -}; diff --git a/back/models/dms-type.js b/back/models/dms-type.js index 267c905e9..c9329f30b 100644 --- a/back/models/dms-type.js +++ b/back/models/dms-type.js @@ -54,8 +54,8 @@ module.exports = Self => { const writeRole = dmsType.writeRole() && dmsType.writeRole().name; const requiredRole = readRole || writeRole; - const hasRequiredRole = await models.Account.hasRole(myUserId, requiredRole, options); - const isRoot = await models.Account.hasRole(myUserId, 'root', options); + const hasRequiredRole = await models.VnUser.hasRole(myUserId, requiredRole, options); + const isRoot = await models.VnUser.hasRole(myUserId, 'root', options); if (isRoot || hasRequiredRole) return true; diff --git a/back/models/image-collection.js b/back/models/image-collection.js index 8ea3c6f12..2c4d274ee 100644 --- a/back/models/image-collection.js +++ b/back/models/image-collection.js @@ -53,8 +53,8 @@ module.exports = Self => { const writeRole = collection.writeRole() && collection.writeRole().name; const requiredRole = readRole || writeRole; - const hasRequiredRole = await models.Account.hasRole(myUserId, requiredRole, options); - const isRoot = await models.Account.hasRole(myUserId, 'root', options); + const hasRequiredRole = await models.VnUser.hasRole(myUserId, requiredRole, options); + const isRoot = await models.VnUser.hasRole(myUserId, 'root', options); if (isRoot || hasRequiredRole) return true; diff --git a/back/models/specs/user.spec.js b/back/models/specs/user.spec.js index 124afdc0c..78835e6eb 100644 --- a/back/models/specs/user.spec.js +++ b/back/models/specs/user.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('account recoverPassword()', () => { +describe('VnUser recoverPassword()', () => { const userId = 1107; const activeCtx = { @@ -21,9 +21,9 @@ describe('account recoverPassword()', () => { it('should send email with token', async() => { const userId = 1107; - const user = await models.Account.findById(userId); + const user = await models.VnUser.findById(userId); - await models.Account.recoverPassword(user.email); + await models.VnUser.recoverPassword(user.email); const result = await models.AccessToken.findOne({where: {userId: userId}}); diff --git a/back/models/specs/account.spec.js b/back/models/specs/vn-user.spec.js similarity index 63% rename from back/models/specs/account.spec.js rename to back/models/specs/vn-user.spec.js index f31c81b75..3700b919a 100644 --- a/back/models/specs/account.spec.js +++ b/back/models/specs/vn-user.spec.js @@ -1,14 +1,14 @@ const models = require('vn-loopback/server/server').models; -describe('loopback model Account', () => { +describe('loopback model VnUser', () => { it('should return true if the user has the given role', async() => { - let result = await models.Account.hasRole(1, 'employee'); + let result = await models.VnUser.hasRole(1, 'employee'); expect(result).toBeTruthy(); }); it('should return false if the user doesnt have the given role', async() => { - let result = await models.Account.hasRole(1, 'administrator'); + let result = await models.VnUser.hasRole(1, 'administrator'); expect(result).toBeFalsy(); }); diff --git a/back/models/user.js b/back/models/user.js index b24d702b3..284b69f71 100644 --- a/back/models/user.js +++ b/back/models/user.js @@ -9,7 +9,7 @@ module.exports = function(Self) { const headers = httpRequest.headers; const origin = headers.origin; - const user = await Self.app.models.Account.findById(info.user.id); + const user = await Self.app.models.VnUser.findById(info.user.id); const params = { recipient: info.email, lang: user.lang, diff --git a/back/models/user.json b/back/models/user.json index 921362e0e..aa5ea11c1 100644 --- a/back/models/user.json +++ b/back/models/user.json @@ -2,18 +2,18 @@ "name": "user", "base": "User", "options": { - "mysql": { - "table": "salix.User" - } + "mysql": { + "table": "salix.User" + } }, "properties": { - "id": { - "id": true, - "type": "number", - "forceId": false - }, - "username":{ - "type": "string" - } + "id": { + "id": true, + "type": "number", + "forceId": false + }, + "username":{ + "type": "string" + } } } \ No newline at end of file diff --git a/back/models/vn-user.js b/back/models/vn-user.js new file mode 100644 index 000000000..3759a89a7 --- /dev/null +++ b/back/models/vn-user.js @@ -0,0 +1,92 @@ +const md5 = require('md5'); +// const vnModel = require('vn-loopback/common/mixins/vn-model'); +module.exports = function(Self) { + // vnModel(Self); + + require('../methods/vn-user/signIn')(Self); + require('../methods/vn-user/signOut')(Self); + require('../methods/vn-user/acl')(Self); + require('../methods/vn-user/change-password')(Self); + require('../methods/vn-user/set-password')(Self); + require('../methods/vn-user/validate-token')(Self); + require('../methods/vn-user/privileges')(Self); + + // Validations + + Self.validatesFormatOf('email', { + message: 'Invalid email', + allowNull: true, + allowBlank: true, + with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/ + }); + + Self.validatesUniquenessOf('name', { + message: `A client with that Web User name already exists` + }); + + Self.observe('before save', async function(ctx) { + if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password) + ctx.data.password = md5(ctx.data.password); + }); + + Self.remoteMethod('getCurrentUserData', { + description: 'Gets the current user data', + accepts: [ + { + arg: 'ctx', + type: 'Object', + http: {source: 'context'} + } + ], + returns: { + type: 'Object', + root: true + }, + http: { + verb: 'GET', + path: '/getCurrentUserData' + } + }); + + Self.getCurrentUserData = async function(ctx) { + let userId = ctx.req.accessToken.userId; + return await Self.findById(userId, { + fields: ['id', 'name', 'nickname'] + }); + }; + + /** + * Checks if user has a role. + * + * @param {Integer} userId The user id + * @param {String} name The role name + * @param {Object} options Options + * @return {Boolean} %true if user has the role, %false otherwise + */ + Self.hasRole = async function(userId, name, options) { + const roles = await Self.getRoles(userId, options); + return roles.some(role => role == name); + }; + + /** + * Get all user roles. + * + * @param {Integer} userId The user id + * @param {Object} options Options + * @return {Object} User role list + */ + Self.getRoles = async(userId, options) => { + const result = await Self.rawSql( + `SELECT r.name + FROM account.user u + JOIN account.roleRole rr ON rr.role = u.role + JOIN account.role r ON r.id = rr.inheritsFrom + WHERE u.id = ?`, [userId], options); + + const roles = []; + for (const role of result) + roles.push(role.name); + + return roles; + }; +}; diff --git a/back/models/account.json b/back/models/vn-user.json similarity index 73% rename from back/models/account.json rename to back/models/vn-user.json index 5e35c711a..d1386d579 100644 --- a/back/models/account.json +++ b/back/models/vn-user.json @@ -1,11 +1,16 @@ { - "name": "Account", - "base": "VnModel", + "name": "VnUser", + "base": "User", + "validateUpsert": true, "options": { "mysql": { "table": "account.user" } }, + "excludeBaseProperties": [ + "username", + "login" + ], "properties": { "id": { "type": "number", @@ -40,9 +45,6 @@ "email": { "type": "string" }, - "emailVerified": { - "type": "boolean" - }, "created": { "type": "date" }, @@ -86,39 +88,25 @@ }, "acls": [ { - "property": "login", + "property": "signIn", "accessType": "EXECUTE", "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" - }, - { - "property": "recoverPassword", - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }, + }, { - "property": "logout", + "property": "logout", "accessType": "EXECUTE", "principalType": "ROLE", "principalId": "$authenticated", "permission": "ALLOW" }, { - "property": "validateToken", + "property": "validateToken", "accessType": "EXECUTE", "principalType": "ROLE", "principalId": "$authenticated", "permission": "ALLOW" - }, - { - "property": "privileges", - "accessType": "*", - "principalType": "ROLE", - "principalId": "$authenticated", - "permission": "ALLOW" } ] -} +} \ No newline at end of file diff --git a/db/changes/230401/00-ACL.sql b/db/changes/230401/00-ACL.sql new file mode 100644 index 000000000..0f50e1093 --- /dev/null +++ b/db/changes/230401/00-ACL.sql @@ -0,0 +1,17 @@ +UPDATE `salix`.`ACL` + SET model='VnUser' + WHERE id=1; +UPDATE `salix`.`ACL` + SET model='VnUser' + WHERE id=219; +UPDATE `salix`.`ACL` + SET model='VnUser' + WHERE id=220; +UPDATE `salix`.`ACL` + SET model='VnUser' + WHERE id=246; + +UPDATE hedera.imageCollection t +SET t.model = 'VnUser' +WHERE t.id = 6; + diff --git a/front/core/directives/specs/acl.spec.js b/front/core/directives/specs/acl.spec.js index 94000d543..751afe457 100644 --- a/front/core/directives/specs/acl.spec.js +++ b/front/core/directives/specs/acl.spec.js @@ -7,7 +7,7 @@ describe('Directive acl', () => { beforeEach(ngModule('vnCore')); beforeEach(inject(($httpBackend, aclService) => { - $httpBackend.whenGET('Accounts/acl') + $httpBackend.whenGET('VnUsers/acl') .respond({ user: {id: 1, name: 'myUser'}, roles: [ diff --git a/front/core/lib/specs/acl-service.spec.js b/front/core/lib/specs/acl-service.spec.js index 3a1460241..eda3ae823 100644 --- a/front/core/lib/specs/acl-service.spec.js +++ b/front/core/lib/specs/acl-service.spec.js @@ -4,7 +4,7 @@ describe('Service acl', () => { beforeEach(ngModule('vnCore')); beforeEach(inject((_aclService_, $httpBackend) => { - $httpBackend.when('GET', `Accounts/acl`).respond({ + $httpBackend.when('GET', `VnUsers/acl`).respond({ roles: [ {role: {name: 'foo'}}, {role: {name: 'bar'}}, diff --git a/front/core/services/acl-service.js b/front/core/services/acl-service.js index ee4404d34..aa2e3d917 100644 --- a/front/core/services/acl-service.js +++ b/front/core/services/acl-service.js @@ -11,7 +11,7 @@ class AclService { } load() { - return this.$http.get('Accounts/acl').then(res => { + return this.$http.get('VnUsers/acl').then(res => { this.user = res.data.user; this.roles = {}; diff --git a/front/core/services/auth.js b/front/core/services/auth.js index c15a34d94..f5bd96620 100644 --- a/front/core/services/auth.js +++ b/front/core/services/auth.js @@ -59,7 +59,7 @@ export default class Auth { password: password || undefined }; - return this.$http.post('Accounts/login', params).then( + return this.$http.post('VnUsers/signIn', params).then( json => this.onLoginOk(json, remember)); } @@ -76,7 +76,7 @@ export default class Auth { } logout() { - let promise = this.$http.post('Accounts/logout', null, { + let promise = this.$http.post('VnUsers/signOut', null, { headers: {Authorization: this.vnToken.token} }).catch(() => {}); diff --git a/front/salix/components/layout/index.js b/front/salix/components/layout/index.js index 372e8e828..48f50f404 100644 --- a/front/salix/components/layout/index.js +++ b/front/salix/components/layout/index.js @@ -13,7 +13,7 @@ export class Layout extends Component { } getUserData() { - this.$http.get('Accounts/getCurrentUserData').then(json => { + this.$http.get('VnUsers/getCurrentUserData').then(json => { this.$.$root.user = json.data; window.localStorage.currentUserWorkerId = json.data.id; }); diff --git a/front/salix/components/layout/index.spec.js b/front/salix/components/layout/index.spec.js index 71dbb9192..0d70c4806 100644 --- a/front/salix/components/layout/index.spec.js +++ b/front/salix/components/layout/index.spec.js @@ -15,7 +15,7 @@ describe('Component vnLayout', () => { describe('getUserData()', () => { it(`should set the user name property in the controller`, () => { - $httpBackend.expect('GET', `Accounts/getCurrentUserData`).respond({name: 'batman'}); + $httpBackend.expect('GET', `VnUsers/getCurrentUserData`).respond({name: 'batman'}); controller.getUserData(); $httpBackend.flush(); diff --git a/front/salix/components/recover-password/index.js b/front/salix/components/recover-password/index.js index 3de7f3266..f4662b6d5 100644 --- a/front/salix/components/recover-password/index.js +++ b/front/salix/components/recover-password/index.js @@ -23,7 +23,7 @@ export default class Controller { email: this.email }; - this.$http.post('Accounts/recoverPassword', params) + this.$http.post('VnUsers/recoverPassword', params) .then(() => { this.goToLogin(); }); diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index cc3eede8e..48f51d9de 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -228,7 +228,7 @@ module.exports = function(Self) { async checkAcls(ctx, actionType) { let userId = ctx.req.accessToken.userId; let models = this.app.models; - let userRoles = await models.Account.getRoles(userId); + let userRoles = await models.VnUser.getRoles(userId); let data = ctx.args.data; let modelAcls; diff --git a/modules/account/back/methods/user-account/sync-by-id.js b/modules/account/back/methods/user-account/sync-by-id.js index b08c9d9fc..538bc09bd 100644 --- a/modules/account/back/methods/user-account/sync-by-id.js +++ b/modules/account/back/methods/user-account/sync-by-id.js @@ -25,7 +25,7 @@ module.exports = Self => { }); Self.syncById = async function(id, password, force) { - let user = await Self.app.models.Account.findById(id, {fields: ['name']}); + let user = await Self.app.models.VnUser.findById(id, {fields: ['name']}); await Self.sync(user.name, password, force); }; }; diff --git a/modules/account/back/methods/user-account/sync.js b/modules/account/back/methods/user-account/sync.js index 86491d72e..808349014 100644 --- a/modules/account/back/methods/user-account/sync.js +++ b/modules/account/back/methods/user-account/sync.js @@ -26,7 +26,7 @@ module.exports = Self => { Self.sync = async function(userName, password, force) { let $ = Self.app.models; - let user = await $.Account.findOne({ + let user = await $.VnUser.findOne({ fields: ['id'], where: {name: userName} }); diff --git a/modules/account/back/models/account-config.js b/modules/account/back/models/account-config.js index 49e120a08..ccde8bba0 100644 --- a/modules/account/back/models/account-config.js +++ b/modules/account/back/models/account-config.js @@ -100,7 +100,7 @@ module.exports = Self => { if (['administrator', 'root'].indexOf(userName) >= 0) return; - let user = await $.Account.findOne({ + let user = await $.VnUser.findOne({ where: {name: userName}, fields: [ 'id', diff --git a/modules/account/back/models/sip-config.js b/modules/account/back/models/sip-config.js index 78213039b..3b5cb2dbb 100644 --- a/modules/account/back/models/sip-config.js +++ b/modules/account/back/models/sip-config.js @@ -10,7 +10,7 @@ module.exports = Self => { async syncUser(userName, info, password) { if (!info.hasAccount || !password) return; - await app.models.Account.rawSql('CALL pbx.sip_setPassword(?, ?)', + await app.models.VnUser.rawSql('CALL pbx.sip_setPassword(?, ?)', [info.user.id, password] ); } diff --git a/modules/account/front/card/index.js b/modules/account/front/card/index.js index 5266592f3..61053ad02 100644 --- a/modules/account/front/card/index.js +++ b/modules/account/front/card/index.js @@ -14,7 +14,7 @@ class Controller extends ModuleCard { }; return Promise.all([ - this.$http.get(`Accounts/${this.$params.id}`, {filter}) + this.$http.get(`VnUsers/${this.$params.id}`, {filter}) .then(res => this.user = res.data), this.$http.get(`UserAccounts/${this.$params.id}/exists`) .then(res => this.hasAccount = res.data.exists) diff --git a/modules/account/front/card/index.spec.js b/modules/account/front/card/index.spec.js index cd28c458a..4fbf9b127 100644 --- a/modules/account/front/card/index.spec.js +++ b/modules/account/front/card/index.spec.js @@ -15,7 +15,7 @@ describe('component vnUserCard', () => { it('should reload the controller data', () => { controller.$params.id = 1; - $httpBackend.expectGET('Accounts/1').respond('foo'); + $httpBackend.expectGET('VnUsers/1').respond('foo'); $httpBackend.expectGET('UserAccounts/1/exists').respond({exists: true}); controller.reload(); $httpBackend.flush(); diff --git a/modules/account/front/descriptor/index.js b/modules/account/front/descriptor/index.js index b802b2349..ae0a58a4c 100644 --- a/modules/account/front/descriptor/index.js +++ b/modules/account/front/descriptor/index.js @@ -25,7 +25,7 @@ class Controller extends Descriptor { } onDelete() { - return this.$http.delete(`Accounts/${this.id}`) + return this.$http.delete(`VnUsers/${this.id}`) .then(() => this.$state.go('account.index')) .then(() => this.vnApp.showSuccess(this.$t('User removed'))); } @@ -54,7 +54,7 @@ class Controller extends Descriptor { } else method = 'setPassword'; - return this.$http.patch(`Accounts/${this.id}/${method}`, params) + return this.$http.patch(`VnUsers/${this.id}/${method}`, params) .then(() => { this.emit('change'); this.vnApp.showSuccess(this.$t('Password changed succesfully!')); @@ -88,7 +88,7 @@ class Controller extends Descriptor { } onSetActive(active) { - return this.$http.patch(`Accounts/${this.id}`, {active}) + return this.$http.patch(`VnUsers/${this.id}`, {active}) .then(() => { this.user.active = active; const message = active diff --git a/modules/account/front/descriptor/index.spec.js b/modules/account/front/descriptor/index.spec.js index f5e7aa7d4..26933ff3d 100644 --- a/modules/account/front/descriptor/index.spec.js +++ b/modules/account/front/descriptor/index.spec.js @@ -21,7 +21,7 @@ describe('component vnUserDescriptor', () => { it('should delete entity and go to index', () => { controller.$state.go = jest.fn(); - $httpBackend.expectDELETE('Accounts/1').respond(); + $httpBackend.expectDELETE('VnUsers/1').respond(); controller.onDelete(); $httpBackend.flush(); @@ -85,7 +85,7 @@ describe('component vnUserDescriptor', () => { describe('onSetActive()', () => { it('should make request to activate/deactivate the user', () => { - $httpBackend.expectPATCH('Accounts/1', {active: true}).respond(); + $httpBackend.expectPATCH('VnUsers/1', {active: true}).respond(); controller.onSetActive(true); $httpBackend.flush(); diff --git a/modules/account/front/privileges/index.html b/modules/account/front/privileges/index.html index e3e44898a..ba596909b 100644 --- a/modules/account/front/privileges/index.html +++ b/modules/account/front/privileges/index.html @@ -1,4 +1,4 @@ - + this.$.summary = res.data); } get isHr() { diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index ba7bda71d..ec457a6c9 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -59,7 +59,7 @@ module.exports = Self => { const landedPlusWeek = new Date(ticket.landed); landedPlusWeek.setDate(landedPlusWeek.getDate() + 7); - const hasClaimManagerRole = await models.Account.hasRole(userId, 'claimManager', myOptions); + const hasClaimManagerRole = await models.VnUser.hasRole(userId, 'claimManager', myOptions); const isClaimable = landedPlusWeek >= new Date(); if (ticket.isDeleted) diff --git a/modules/claim/back/methods/claim/isEditable.js b/modules/claim/back/methods/claim/isEditable.js index cd14d70c7..ccb34e463 100644 --- a/modules/claim/back/methods/claim/isEditable.js +++ b/modules/claim/back/methods/claim/isEditable.js @@ -26,7 +26,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager', myOptions); + const isClaimManager = await Self.app.models.VnUser.hasRole(userId, 'claimManager', myOptions); const claim = await Self.app.models.Claim.findById(id, { fields: ['claimStateFk'], diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index cc9937c19..55295f294 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -80,7 +80,7 @@ module.exports = Self => { if (args.claimStateFk) { const canUpdate = await canChangeState(ctx, claim.claimStateFk, myOptions); const hasRights = await canChangeState(ctx, args.claimStateFk, myOptions); - const isClaimManager = await models.Account.hasRole(userId, 'claimManager', myOptions); + const isClaimManager = await models.VnUser.hasRole(userId, 'claimManager', myOptions); if (!canUpdate || !hasRights || changedHasToPickUp && !isClaimManager) throw new UserError(`You don't have enough privileges to change that field`); @@ -123,7 +123,7 @@ module.exports = Self => { } }, options); let stateRole = state.writeRole().name; - let canUpdate = await models.Account.hasRole(userId, stateRole, options); + let canUpdate = await models.VnUser.hasRole(userId, stateRole, options); return canUpdate; } diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index cb97d5d59..99c4e3b1d 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -37,7 +37,7 @@ module.exports = function(Self) { }; try { - const account = await models.Account.create(user, myOptions); + const account = await models.VnUser.create(user, myOptions); const client = await Self.create({ id: account.id, name: data.name, diff --git a/modules/client/back/methods/client/setPassword.js b/modules/client/back/methods/client/setPassword.js index e3fc9bbf8..ad24c2aff 100644 --- a/modules/client/back/methods/client/setPassword.js +++ b/modules/client/back/methods/client/setPassword.js @@ -28,7 +28,7 @@ module.exports = Self => { const isUserAccount = await models.UserAccount.findById(id, null); if (isClient && !isUserAccount) - await models.Account.setPassword(id, newPassword); + await models.VnUser.setPassword(id, newPassword); else throw new UserError(`Modifiable password only via recovery or by an administrator`); }; diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 7d4261aee..062f5845e 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -34,7 +34,7 @@ describe('Client Create', () => { try { const options = {transaction: tx}; - const account = await models.Account.findOne({where: {name: newAccount.userName}}, options); + const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); const client = await models.Client.findOne({where: {name: newAccount.name}}, options); expect(account).toEqual(null); @@ -54,7 +54,7 @@ describe('Client Create', () => { const options = {transaction: tx}; const client = await models.Client.createWithUser(newAccount, options); - const account = await models.Account.findOne({where: {name: newAccount.userName}}, options); + const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); expect(account.name).toEqual(newAccount.userName); expect(client.id).toEqual(account.id); diff --git a/modules/client/back/methods/client/specs/updateUser.spec.js b/modules/client/back/methods/client/specs/updateUser.spec.js index 2d7f7dce0..b51686ae0 100644 --- a/modules/client/back/methods/client/specs/updateUser.spec.js +++ b/modules/client/back/methods/client/specs/updateUser.spec.js @@ -61,7 +61,7 @@ describe('Client updateUser', () => { const clientID = 1105; await models.Client.updateUser(ctx, clientID, options); - const client = await models.Account.findById(clientID, null, options); + const client = await models.VnUser.findById(clientID, null, options); expect(client.name).toEqual('test'); diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index cae797f6b..e521870fd 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -93,7 +93,7 @@ module.exports = function(Self) { if (typeof options == 'object') Object.assign(myOptions, options); - const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions); + const isSalesAssistant = await models.VnUser.hasRole(userId, 'salesAssistant', myOptions); if (args.isLogifloraAllowed && !isSalesAssistant) throw new UserError(`You don't have enough privileges`); diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index fdd8c4c15..c63dc3991 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -131,7 +131,7 @@ module.exports = Self => { myOptions.transaction = tx; } try { - const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions); + const isSalesAssistant = await models.VnUser.hasRole(userId, 'salesAssistant', myOptions); const client = await models.Client.findById(clientId, null, myOptions); if (!isSalesAssistant && client.isTaxDataChecked) throw new UserError(`Not enough privileges to edit a client with verified data`); diff --git a/modules/client/back/methods/client/updateUser.js b/modules/client/back/methods/client/updateUser.js index 1db8cd6b6..f0f3ebd79 100644 --- a/modules/client/back/methods/client/updateUser.js +++ b/modules/client/back/methods/client/updateUser.js @@ -40,12 +40,12 @@ module.exports = Self => { Object.assign(myOptions, options); if (!myOptions.transaction) { - tx = await models.Account.beginTransaction({}); + tx = await models.VnUser.beginTransaction({}); myOptions.transaction = tx; } try { - const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions); + const isSalesPerson = await models.VnUser.hasRole(userId, 'salesPerson', myOptions); if (!isSalesPerson) throw new UserError(`Not enough privileges to edit a client`); @@ -54,7 +54,7 @@ module.exports = Self => { const isUserAccount = await models.UserAccount.findById(id, null, myOptions); if (isClient && !isUserAccount) { - const user = await models.Account.findById(id, null, myOptions); + const user = await models.VnUser.findById(id, null, myOptions); await user.updateAttributes(ctx.args, myOptions); } else throw new UserError(`Modifiable user details only by an administrator`); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e07993f79..a99ccb4f2 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -209,7 +209,7 @@ module.exports = Self => { const loopBackContext = LoopBackContext.getCurrentContext(); const userId = loopBackContext.active.accessToken.userId; - const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', ctx.options); + const isSalesAssistant = await models.VnUser.hasRole(userId, 'salesAssistant', ctx.options); const hasChanges = orgData && changes; const isTaxDataChecked = hasChanges && (changes.isTaxDataChecked || orgData.isTaxDataChecked); @@ -375,7 +375,7 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.options.accessToken.userId; - const isFinancialBoss = await models.Account.hasRole(userId, 'financialBoss', ctx.options); + const isFinancialBoss = await models.VnUser.hasRole(userId, 'financialBoss', ctx.options); if (!isFinancialBoss) { const lastCredit = await models.ClientCredit.findOne({ where: { @@ -386,7 +386,7 @@ module.exports = Self => { const lastAmount = lastCredit && lastCredit.amount; const lastWorkerId = lastCredit && lastCredit.workerFk; - const lastWorkerIsFinancialBoss = await models.Account.hasRole(lastWorkerId, 'financialBoss', ctx.options); + const lastWorkerIsFinancialBoss = await models.VnUser.hasRole(lastWorkerId, 'financialBoss', ctx.options); if (lastAmount == 0 && lastWorkerIsFinancialBoss) throw new UserError(`You can't change the credit set to zero from a financialBoss`); @@ -421,15 +421,15 @@ module.exports = Self => { const app = require('vn-loopback/server/server'); app.on('started', function() { - const account = app.models.Account; + const VnUser = app.models.VnUser; - account.observe('before save', async ctx => { + VnUser.observe('before save', async ctx => { if (ctx.isNewInstance) return; if (ctx.currentInstance) ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance)); }); - account.observe('after save', async ctx => { + VnUser.observe('after save', async ctx => { const changes = ctx.data || ctx.instance; if (!ctx.isNewInstance && changes) { const oldData = ctx.hookState.oldInstance; @@ -448,7 +448,7 @@ module.exports = Self => { originFk: oldData.id, userFk: userId, action: 'update', - changedModel: 'Account', + changedModel: 'VnUser', oldInstance: {name: oldData.name, active: oldData.active}, newInstance: {name: changes.name, active: changes.active} }; diff --git a/modules/client/back/models/specs/client.spec.js b/modules/client/back/models/specs/client.spec.js index 1f7e56cdb..45debc08a 100644 --- a/modules/client/back/models/specs/client.spec.js +++ b/modules/client/back/models/specs/client.spec.js @@ -63,14 +63,14 @@ describe('Client Model', () => { const context = {options}; // Set credit to zero by a financialBoss - const financialBoss = await models.Account.findOne({ + const financialBoss = await models.VnUser.findOne({ where: {name: 'financialBoss'} }, options); context.options.accessToken = {userId: financialBoss.id}; await models.Client.changeCredit(context, instance, {credit: 0}); - const salesAssistant = await models.Account.findOne({ + const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} }, options); context.options.accessToken = {userId: salesAssistant.id}; @@ -95,7 +95,7 @@ describe('Client Model', () => { const options = {transaction: tx}; const context = {options}; - const salesAssistant = await models.Account.findOne({ + const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} }, options); context.options.accessToken = {userId: salesAssistant.id}; diff --git a/modules/client/back/models/specs/clientCredit.spec.js b/modules/client/back/models/specs/clientCredit.spec.js index fcd86c979..65d40404c 100644 --- a/modules/client/back/models/specs/clientCredit.spec.js +++ b/modules/client/back/models/specs/clientCredit.spec.js @@ -15,7 +15,7 @@ describe('Client Credit', () => { try { const options = {transaction: tx}; - const salesAssistant = await models.Account.findOne({ + const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} }, options); diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index e56516237..f676d6593 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -43,7 +43,7 @@ module.exports = Self => { try { const invoiceOut = await Self.findById(id, null, myOptions); - const hasInvoicing = await models.Account.hasRole(userId, 'invoicing', myOptions); + const hasInvoicing = await models.VnUser.hasRole(userId, 'invoicing', myOptions); if (invoiceOut.hasPdf && !hasInvoicing) throw new UserError(`You don't have enough privileges`); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 44549c65c..a8f03d3b3 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -107,7 +107,7 @@ module.exports = Self => { const orgData = ctx.currentInstance; const userId = loopbackContext.active.accessToken.userId; - const isNotFinancial = !await Self.app.models.Account.hasRole(userId, 'financial'); + const isNotFinancial = !await Self.app.models.VnUser.hasRole(userId, 'financial'); const isPayMethodChecked = changes.isPayMethodChecked || orgData.isPayMethodChecked; const hasChanges = orgData && changes; const isPayMethodCheckedChanged = hasChanges diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 2c90ac43b..f51d1774d 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -25,9 +25,9 @@ module.exports = Self => { Object.assign(myOptions, options); let statesList = await models.State.find({where: filter.where}, myOptions); - const isProduction = await models.Account.hasRole(userId, 'production', myOptions); - const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions); - const isAdministrative = await models.Account.hasRole(userId, 'administrative', myOptions); + const isProduction = await models.VnUser.hasRole(userId, 'production', myOptions); + const isSalesPerson = await models.VnUser.hasRole(userId, 'salesPerson', myOptions); + const isAdministrative = await models.VnUser.hasRole(userId, 'administrative', myOptions); if (isProduction || isAdministrative) return statesList; diff --git a/modules/ticket/back/methods/state/isEditable.js b/modules/ticket/back/methods/state/isEditable.js index a0d11c2b7..730e6b9eb 100644 --- a/modules/ticket/back/methods/state/isEditable.js +++ b/modules/ticket/back/methods/state/isEditable.js @@ -27,9 +27,9 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isProduction = await models.Account.hasRole(userId, 'production', myOptions); - const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions); - const isAdministrative = await models.Account.hasRole(userId, 'administrative', myOptions); + const isProduction = await models.VnUser.hasRole(userId, 'production', myOptions); + const isSalesPerson = await models.VnUser.hasRole(userId, 'salesPerson', myOptions); + const isAdministrative = await models.VnUser.hasRole(userId, 'administrative', myOptions); const state = await models.State.findById(stateId, null, myOptions); const salesPersonAllowed = (isSalesPerson && (state.code == 'PICKER_DESIGNED' || state.code == 'PRINTED')); diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index f4a4bb98d..dddd8230d 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -116,7 +116,7 @@ module.exports = Self => { if (!isEditable) throw new UserError(`The sales of this ticket can't be modified`); - const isDeliveryBoss = await models.Account.hasRole(userId, 'deliveryBoss', myOptions); + const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions); if (!isDeliveryBoss) { const zoneShipped = await models.Agency.getShipped( args.landed, diff --git a/modules/ticket/back/methods/ticket/isRoleAdvanced.js b/modules/ticket/back/methods/ticket/isRoleAdvanced.js index 7c5c8ed86..d6186a0c9 100644 --- a/modules/ticket/back/methods/ticket/isRoleAdvanced.js +++ b/modules/ticket/back/methods/ticket/isRoleAdvanced.js @@ -20,10 +20,10 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions); - const isDeliveryBoss = await models.Account.hasRole(userId, 'deliveryBoss', myOptions); - const isBuyer = await models.Account.hasRole(userId, 'buyer', myOptions); - const isClaimManager = await models.Account.hasRole(userId, 'claimManager', myOptions); + const isSalesAssistant = await models.VnUser.hasRole(userId, 'salesAssistant', myOptions); + const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions); + const isBuyer = await models.VnUser.hasRole(userId, 'buyer', myOptions); + const isClaimManager = await models.VnUser.hasRole(userId, 'claimManager', myOptions); const isRoleAdvanced = isSalesAssistant || isDeliveryBoss || isBuyer || isClaimManager; diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 989e0e5ce..a0a10d997 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -78,7 +78,7 @@ module.exports = Self => { if (!isEditable) throw new UserError(`The sales of this ticket can't be modified`); - const isDeliveryBoss = await models.Account.hasRole(userId, 'deliveryBoss', myOptions); + const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions); if (!isDeliveryBoss) { const zoneShipped = await models.Agency.getShipped( args.landed, diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index cec8096a6..d114d15bb 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -43,7 +43,7 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); // Check if has sales with shelving - const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions); + const isSalesAssistant = await models.VnUser.hasRole(userId, 'salesAssistant', myOptions); const sales = await models.Sale.find({ include: {relation: 'itemShelvingSale'}, where: {ticketFk: id} diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 1b8476184..26925cca8 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -77,7 +77,7 @@ module.exports = Self => { const saleIds = sales.map(sale => sale.id); - const isClaimManager = await models.Account.hasRole(userId, 'claimManager'); + const isClaimManager = await models.VnUser.hasRole(userId, 'claimManager'); const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}}); if (hasClaimedSales && !isClaimManager) throw new UserError(`Can't transfer claimed sales`); diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 4dd346161..8300db886 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -85,7 +85,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const isLocked = await models.Ticket.isLocked(id, myOptions); - const roles = await models.Account.getRoles(userId, myOptions); + const roles = await models.VnUser.getRoles(userId, myOptions); const hasAllowedRoles = roles.filter(role => role == 'salesPerson' || role == 'claimManager' ); diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 82216f956..c16b2bbb1 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -26,7 +26,7 @@ module.exports = Self => { const conn = Self.dataSource.connector; const userId = ctx.req.accessToken.userId; - const account = await Self.app.models.Account.findById(userId); + const account = await Self.app.models.VnUser.findById(userId); const stmt = new ParameterizedSQL( `SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile FROM workerDocument wd diff --git a/modules/worker/back/methods/worker-time-control/addTimeEntry.js b/modules/worker/back/methods/worker-time-control/addTimeEntry.js index fef3cf223..09b8f8bd2 100644 --- a/modules/worker/back/methods/worker-time-control/addTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/addTimeEntry.js @@ -40,7 +40,7 @@ module.exports = Self => { Object.assign(myOptions, options); const isSubordinate = await models.Worker.isSubordinate(ctx, workerId, myOptions); - const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions); + const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions); const isHimself = currentUserId == workerId; if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss)) diff --git a/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js b/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js index c80dcab81..5c1971873 100644 --- a/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js @@ -32,7 +32,7 @@ module.exports = Self => { const targetTimeEntry = await Self.findById(id, null, myOptions); const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions); - const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions); + const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions); const isHimself = currentUserId == targetTimeEntry.userFk; if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss)) diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index a99a61770..f94384352 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -38,7 +38,7 @@ module.exports = Self => { const targetTimeEntry = await Self.findById(id, null, myOptions); const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions); - const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions); + const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions); const isHimself = currentUserId == targetTimeEntry.userFk; const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 1467d6d6b..24399bc7a 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -53,7 +53,7 @@ module.exports = Self => { try { const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions); - const isTeamBoss = await models.Account.hasRole(userId, 'teamBoss', myOptions); + const isTeamBoss = await models.VnUser.hasRole(userId, 'teamBoss', myOptions); if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); @@ -107,8 +107,8 @@ module.exports = Self => { const department = labour.department(); if (department && department.notificationEmail) { const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions); - const account = await models.Account.findById(userId, null, myOptions); - const subordinated = await models.Account.findById(id, null, myOptions); + const account = await models.VnUser.findById(userId, null, myOptions); + const subordinated = await models.VnUser.findById(id, null, myOptions); const origin = ctx.req.headers.origin; const body = $t('Created absence', { author: account.nickname, diff --git a/modules/worker/back/methods/worker/deleteAbsence.js b/modules/worker/back/methods/worker/deleteAbsence.js index 45dc04b2d..2d0078ba7 100644 --- a/modules/worker/back/methods/worker/deleteAbsence.js +++ b/modules/worker/back/methods/worker/deleteAbsence.js @@ -40,7 +40,7 @@ module.exports = Self => { try { const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions); - const isTeamBoss = await models.Account.hasRole(userId, 'teamBoss', myOptions); + const isTeamBoss = await models.VnUser.hasRole(userId, 'teamBoss', myOptions); if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); @@ -58,8 +58,8 @@ module.exports = Self => { const department = labour && labour.department(); if (department && department.notificationEmail) { const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions); - const account = await models.Account.findById(userId, null, myOptions); - const subordinated = await models.Account.findById(labour.workerFk, null, myOptions); + const account = await models.VnUser.findById(userId, null, myOptions); + const subordinated = await models.VnUser.findById(labour.workerFk, null, myOptions); const origin = ctx.req.headers.origin; const body = $t('Deleted absence', { author: account.nickname, diff --git a/modules/worker/back/methods/worker/isSubordinate.js b/modules/worker/back/methods/worker/isSubordinate.js index f051cf768..6c17ad0d0 100644 --- a/modules/worker/back/methods/worker/isSubordinate.js +++ b/modules/worker/back/methods/worker/isSubordinate.js @@ -37,7 +37,7 @@ module.exports = Self => { return subordinate.workerFk == id; }); - const isHr = await models.Account.hasRole(myUserId, 'hr', myOptions); + const isHr = await models.VnUser.hasRole(myUserId, 'hr', myOptions); if (isHr || isSubordinate) return true; diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index a7bb883cd..cd736f770 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -144,7 +144,7 @@ module.exports = Self => { 'SELECT account.passwordGenerate() as password;' ); - const user = await models.Account.create( + const user = await models.VnUser.create( { name: args.name, nickname, @@ -210,7 +210,7 @@ module.exports = Self => { ); } - const user = await models.Account.findById(client.id, null, myOptions); + const user = await models.VnUser.findById(client.id, null, myOptions); await user.updateAttribute('email', args.email, myOptions); await models.Worker.rawSql( diff --git a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js index 411cb8e57..da54f6adb 100644 --- a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js +++ b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js @@ -13,7 +13,7 @@ describe('Worker activeWithInheritedRole', () => { const randomIndex = Math.floor(Math.random() * result.length); const worker = result[randomIndex]; - const isSalesPerson = await app.models.Account.hasRole(worker.id, 'salesPerson'); + const isSalesPerson = await app.models.VnUser.hasRole(worker.id, 'salesPerson'); expect(result.length).toBeGreaterThan(1); expect(result.length).toBeLessThan(allRolesCount); @@ -27,7 +27,7 @@ describe('Worker activeWithInheritedRole', () => { const randomIndex = Math.floor(Math.random() * result.length); const worker = result[randomIndex]; - const isBuyer = await app.models.Account.hasRole(worker.id, 'buyer'); + const isBuyer = await app.models.VnUser.hasRole(worker.id, 'buyer'); expect(result.length).toBeGreaterThan(1); expect(result.length).toBeLessThan(allRolesCount); diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index f695ab80e..dbcc66683 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -38,7 +38,7 @@ describe('Worker new', () => { }; it('should return error if personal mail already exists', async() => { - const user = await models.Account.findById(employeeId, {fields: ['email']}); + const user = await models.VnUser.findById(employeeId, {fields: ['email']}); const tx = await models.Worker.beginTransaction({}); @@ -112,7 +112,7 @@ describe('Worker new', () => { await models.Address.destroyAll({clientFk: newWorker.id}); await models.Mandate.destroyAll({clientFk: newWorker.id}); await models.Client.destroyById(newWorker.id); - await models.Account.destroyById(newWorker.id); + await models.VnUser.destroyById(newWorker.id); expect(newWorker.id).toBeDefined(); }); diff --git a/modules/worker/back/methods/worker/updateAbsence.js b/modules/worker/back/methods/worker/updateAbsence.js index 7ed8992d3..d904c2c14 100644 --- a/modules/worker/back/methods/worker/updateAbsence.js +++ b/modules/worker/back/methods/worker/updateAbsence.js @@ -30,7 +30,7 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; const isSubordinate = await models.Worker.isSubordinate(ctx, id); - const isTeamBoss = await models.Account.hasRole(userId, 'teamBoss'); + const isTeamBoss = await models.VnUser.hasRole(userId, 'teamBoss'); if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); diff --git a/modules/worker/front/account/index.html b/modules/worker/front/account/index.html index f51876a07..d629de286 100644 --- a/modules/worker/front/account/index.html +++ b/modules/worker/front/account/index.html @@ -1,5 +1,5 @@ diff --git a/modules/zone/back/methods/agency/getLanded.js b/modules/zone/back/methods/agency/getLanded.js index a662f59dd..cdde3b155 100644 --- a/modules/zone/back/methods/agency/getLanded.js +++ b/modules/zone/back/methods/agency/getLanded.js @@ -42,7 +42,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; - const roles = await models.Account.getRoles(userId); + const roles = await models.VnUser.getRoles(userId); const canSeeExpired = roles.filter(role => role == 'productionBoss' || role == 'administrative' ); diff --git a/modules/zone/back/methods/zone/includingExpired.js b/modules/zone/back/methods/zone/includingExpired.js index e93b86471..59e4079c2 100644 --- a/modules/zone/back/methods/zone/includingExpired.js +++ b/modules/zone/back/methods/zone/includingExpired.js @@ -36,7 +36,7 @@ module.exports = Self => { && where.agencyModeFk && where.warehouseFk; if (filterByAvailability) { - const roles = await models.Account.getRoles(userId, myOptions); + const roles = await models.VnUser.getRoles(userId, myOptions); const canSeeExpired = roles.filter(role => role == 'productionBoss' || role == 'administrative' );