231801_test_to_master #1519

Merged
alexm merged 490 commits from 231801_test_to_master into master 2023-05-12 06:29:59 +00:00
82 changed files with 285 additions and 321 deletions
Showing only changes of commit ee1ce21bb9 - Show all commits

View File

@ -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) {

View File

@ -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;

View File

@ -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}`;

View File

@ -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',

View File

@ -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`);

View File

@ -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};
};
};

View File

@ -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;
};
};

View File

@ -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();

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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();
});

View File

@ -1,7 +1,4 @@
{
"Account": {
"dataSource": "vn"
},
"AccountingType": {
"dataSource": "vn"
},
@ -131,6 +128,9 @@
"Warehouse": {
"dataSource": "vn"
},
"VnUser": {
"dataSource": "vn"
},
"OsTicket": {
"dataSource": "osticket"
},

View File

@ -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;
};
};

View File

@ -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;

View File

@ -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;

View File

@ -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}});

View File

@ -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();
});

View File

@ -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,

View File

@ -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"
}
}
}

92
back/models/vn-user.js Normal file
View File

@ -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;
};
};

View File

@ -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"
}
]
}

View File

@ -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;

View File

@ -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: [

View File

@ -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'}},

View File

@ -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 = {};

View File

@ -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(() => {});

View File

@ -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;
});

View File

@ -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();

View File

@ -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();
});

View File

@ -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;

View File

@ -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);
};
};

View File

@ -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}
});

View File

@ -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',

View File

@ -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]
);
}

View File

@ -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)

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -1,4 +1,4 @@
<mg-ajax path="Accounts/{{post.params.id}}/privileges" options="vnPost"></mg-ajax>
<mg-ajax path="VnUsers/{{post.params.id}}/privileges" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
url="Accounts"

View File

@ -15,7 +15,7 @@ class Controller extends Summary {
}
}
};
this.$http.get(`Accounts/${value.id}`, {filter})
this.$http.get(`VnUsers/${value.id}`, {filter})
.then(res => this.$.summary = res.data);
}
get isHr() {

View File

@ -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)

View File

@ -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'],

View File

@ -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;
}

View File

@ -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,

View File

@ -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`);
};

View File

@ -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);

View File

@ -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');

View File

@ -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`);

View File

@ -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`);

View File

@ -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`);

View File

@ -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}
};

View File

@ -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};

View File

@ -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);

View File

@ -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`);

View File

@ -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

View File

@ -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;

View File

@ -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'));

View File

@ -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,

View File

@ -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;

View File

@ -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,

View File

@ -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}

View File

@ -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`);

View File

@ -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'
);

View File

@ -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

View File

@ -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))

View File

@ -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))

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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(

View File

@ -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);

View File

@ -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();
});

View File

@ -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`);

View File

@ -1,5 +1,5 @@
<mg-ajax
path="Accounts/{{$ctrl.worker.userFk}}"
path="VnUsers/{{$ctrl.worker.userFk}}"
actions="user = edit.model"
options="mgEdit">
</mg-ajax>

View File

@ -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'
);

View File

@ -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'
);