Merge branch 'dev'
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
commit
12aa9c6b4b
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [2326.01] - 2023-06-29
|
||||
|
||||
### Added
|
||||
- (Entradas -> Correo) Al cambiar el tipo de cambio enviará un correo a las personas designadas
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('renewToken', {
|
||||
description: 'Checks if the token has more than renewPeriod seconds to live and if so, renews it',
|
||||
accessType: 'WRITE',
|
||||
accepts: [],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/renewToken`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.renewToken = async function(ctx) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const created = ctx.req.accessToken.created;
|
||||
const tokenId = ctx.req.accessToken.id;
|
||||
|
||||
const now = new Date();
|
||||
const differenceMilliseconds = now - created;
|
||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
||||
|
||||
const accessTokenConfig = await models.AccessTokenConfig.findOne({fields: ['renewPeriod']});
|
||||
|
||||
if (differenceSeconds <= accessTokenConfig.renewPeriod)
|
||||
throw new UserError(`The renew period has not been exceeded`);
|
||||
|
||||
await Self.logout(tokenId);
|
||||
const user = await Self.findById(userId);
|
||||
const accessToken = await user.createAccessToken();
|
||||
|
||||
return {token: accessToken.id, created: accessToken.created};
|
||||
};
|
||||
};
|
|
@ -76,6 +76,6 @@ module.exports = Self => {
|
|||
|
||||
let loginInfo = Object.assign({password}, userInfo);
|
||||
token = await Self.login(loginInfo, 'user');
|
||||
return {token: token.id};
|
||||
return {token: token.id, created: token.created};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ describe('VnUser signIn()', () => {
|
|||
|
||||
expect(login.token).toBeDefined();
|
||||
|
||||
await models.VnUser.signOut(ctx);
|
||||
await models.VnUser.logout(ctx.req.accessToken.id);
|
||||
});
|
||||
|
||||
it('should return the token if the user doesnt exist but the client does', async() => {
|
||||
|
@ -19,7 +19,7 @@ describe('VnUser signIn()', () => {
|
|||
|
||||
expect(login.token).toBeDefined();
|
||||
|
||||
await models.VnUser.signOut(ctx);
|
||||
await models.VnUser.logout(ctx.req.accessToken.id);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('VnUser signOut()', () => {
|
||||
it('should logout and remove token after valid login', async() => {
|
||||
let loginResponse = await models.VnUser.signOut('buyer', 'nightmare');
|
||||
let accessToken = await models.AccessToken.findById(loginResponse.token);
|
||||
let ctx = {req: {accessToken: accessToken}};
|
||||
|
||||
let logoutResponse = await models.VnUser.signOut(ctx);
|
||||
let tokenAfterLogout = await models.AccessToken.findById(loginResponse.token);
|
||||
|
||||
expect(logoutResponse).toBeTrue();
|
||||
expect(tokenAfterLogout).toBeNull();
|
||||
});
|
||||
|
||||
it('should throw a 401 error when token is invalid', async() => {
|
||||
let error;
|
||||
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
|
||||
|
||||
try {
|
||||
response = await models.VnUser.signOut(ctx);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it('should throw an error when no token is passed', async() => {
|
||||
let error;
|
||||
let ctx = {req: {accessToken: null}};
|
||||
|
||||
try {
|
||||
response = await models.VnUser.signOut(ctx);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -2,6 +2,14 @@
|
|||
"AccountingType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"AccessTokenConfig": {
|
||||
"dataSource": "vn",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "salix.accessTokenConfig"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Bank": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "AccessTokenConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "accessTokenConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"renewPeriod": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"renewInterval": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
"acls": [{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
}
|
|
@ -10,6 +10,9 @@ module.exports = function(Self) {
|
|||
require('../methods/vn-user/recover-password')(Self);
|
||||
require('../methods/vn-user/validate-token')(Self);
|
||||
require('../methods/vn-user/privileges')(Self);
|
||||
require('../methods/vn-user/renew-token')(Self);
|
||||
|
||||
Self.definition.settings.acls = Self.definition.settings.acls.filter(acl => acl.property !== 'create');
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
|
@ -118,5 +118,24 @@
|
|||
"principalId": "$authenticated",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"scopes": {
|
||||
"preview": {
|
||||
"fields": [
|
||||
"id",
|
||||
"name",
|
||||
"username",
|
||||
"roleFk",
|
||||
"nickname",
|
||||
"lang",
|
||||
"active",
|
||||
"created",
|
||||
"updated",
|
||||
"image",
|
||||
"hasGrant",
|
||||
"realm",
|
||||
"email"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('VnUser', '*', '*', 'ALLOW', 'ROLE', 'employee'),
|
||||
('VnUser','acl','READ','ALLOW','ROLE','account'),
|
||||
('VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'),
|
||||
('VnUser','changePassword', 'WRITE', 'ALLOW', 'ROLE', 'account'),
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELETE
|
||||
FROM `salix`.`ACL`
|
||||
WHERE model='Account' AND property='*' AND accessType='*';
|
||||
|
||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'sysadmin'),
|
||||
('Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,5 @@
|
|||
DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount';
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('MailAliasAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
|
@ -0,0 +1,5 @@
|
|||
DELETE FROM `salix`.`ACL` WHERE model = 'MailForward';
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('MailForward', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('MailForward', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
|
@ -0,0 +1,5 @@
|
|||
DELETE FROM `salix`.`ACL` WHERE model = 'Role';
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('Role', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('Role', '*', 'WRITE', 'ALLOW', 'ROLE', 'it');
|
|
@ -0,0 +1,10 @@
|
|||
DELETE
|
||||
FROM `salix`.`ACL`
|
||||
WHERE model = 'VnUser' AND property = '*' AND principalId = 'employee';
|
||||
|
||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('VnUser', '*', '*', 'ALLOW', 'ROLE', 'itManagement'),
|
||||
('VnUser', '__get__preview', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('VnUser', 'preview', '*', 'ALLOW', 'ROLE', 'employee'),
|
||||
('VnUser', 'create', '*', 'ALLOW', 'ROLE', 'itManagement');
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('VnUser', 'renewToken', 'WRITE', 'ALLOW', 'ROLE', 'employee')
|
|
@ -0,0 +1,40 @@
|
|||
DELIMITER $$
|
||||
$$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_updateComission`(vCurrency INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Actualiza la comision de las entradas de hoy a futuro y las recalcula
|
||||
*
|
||||
* @param vCurrency id del tipo de moneda(SAR,EUR,USD,GBP,JPY)
|
||||
*/
|
||||
DECLARE vCurrencyName VARCHAR(25);
|
||||
DECLARE vComission INT;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.recalcEntryCommision
|
||||
SELECT e.id
|
||||
FROM vn.entry e
|
||||
JOIN vn.travel t ON t.id = e.travelFk
|
||||
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
||||
WHERE t.shipped >= util.VN_CURDATE()
|
||||
AND e.currencyFk = vCurrency;
|
||||
|
||||
SET vComission = currency_getCommission(vCurrency);
|
||||
|
||||
UPDATE vn.entry e
|
||||
JOIN tmp.recalcEntryCommision tmp ON tmp.id = e.id
|
||||
SET e.commission = vComission;
|
||||
|
||||
SELECT `name` INTO vCurrencyName
|
||||
FROM currency
|
||||
WHERE id = vCurrency;
|
||||
|
||||
CALL entry_recalc();
|
||||
SELECT util.notification_send(
|
||||
'entry-update-comission',
|
||||
JSON_OBJECT('currencyName', vCurrencyName, 'referenceCurrent', vComission),
|
||||
account.myUser_getId()
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE tmp.recalcEntryCommision;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE `salix`.`accessTokenConfig` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`renewPeriod` int(10) unsigned DEFAULT NULL,
|
||||
`renewInterval` int(10) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`)
|
||||
VALUES
|
||||
(1, 21600, 300);
|
|
@ -2895,6 +2895,10 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`)
|
|||
(2, 1, 50, 2),
|
||||
(3, 1, 0, 3);
|
||||
|
||||
INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`)
|
||||
VALUES
|
||||
(1, 21600, 300);
|
||||
|
||||
INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`)
|
||||
VALUES
|
||||
(1, 1, 1, 1, 442);
|
||||
|
|
|
@ -53,7 +53,7 @@ describe('Worker create path', () => {
|
|||
expect(message.text).toContain('Data saved!');
|
||||
|
||||
// 'rollback'
|
||||
await page.loginAndModule('sysadmin', 'account');
|
||||
await page.loginAndModule('itManagement', 'account');
|
||||
await page.accessToSearchResult(newWorker);
|
||||
|
||||
await page.waitToClick(selectors.accountDescriptor.menuButton);
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('Account create and basic data path', () => {
|
|||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('developer', 'account');
|
||||
await page.loginAndModule('itManagement', 'account');
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
|
|
|
@ -64,7 +64,7 @@ export default class Auth {
|
|||
}
|
||||
|
||||
onLoginOk(json, remember) {
|
||||
this.vnToken.set(json.data.token, remember);
|
||||
this.vnToken.set(json.data.token, json.data.created, remember);
|
||||
|
||||
return this.loadAcls().then(() => {
|
||||
let continueHash = this.$state.params.continue;
|
||||
|
|
|
@ -11,3 +11,4 @@ import './report';
|
|||
import './email';
|
||||
import './file';
|
||||
import './date';
|
||||
|
||||
|
|
|
@ -9,25 +9,33 @@ export default class Token {
|
|||
constructor() {
|
||||
try {
|
||||
this.token = sessionStorage.getItem('vnToken');
|
||||
if (!this.token)
|
||||
this.created = sessionStorage.getItem('vnTokenCreated');
|
||||
if (!this.token) {
|
||||
this.token = localStorage.getItem('vnToken');
|
||||
this.created = localStorage.getItem('vnTokenCreated');
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
set(value, remember) {
|
||||
set(token, created, remember) {
|
||||
this.unset();
|
||||
try {
|
||||
if (remember)
|
||||
localStorage.setItem('vnToken', value);
|
||||
else
|
||||
sessionStorage.setItem('vnToken', value);
|
||||
if (remember) {
|
||||
localStorage.setItem('vnToken', token);
|
||||
localStorage.setItem('vnTokenCreated', created);
|
||||
} else {
|
||||
sessionStorage.setItem('vnToken', token);
|
||||
sessionStorage.setItem('vnTokenCreated', created);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
this.token = value;
|
||||
this.token = token;
|
||||
this.created = created;
|
||||
}
|
||||
unset() {
|
||||
localStorage.removeItem('vnToken');
|
||||
sessionStorage.removeItem('vnToken');
|
||||
this.token = null;
|
||||
this.created = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,14 @@ import Component from 'core/lib/component';
|
|||
import './style.scss';
|
||||
|
||||
export class Layout extends Component {
|
||||
constructor($element, $, vnModules) {
|
||||
constructor($element, $, vnModules, vnToken) {
|
||||
super($element, $);
|
||||
this.modules = vnModules.get();
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.getUserData();
|
||||
this.getAccessTokenConfig();
|
||||
}
|
||||
|
||||
getUserData() {
|
||||
|
@ -30,8 +31,42 @@ export class Layout extends Component {
|
|||
refresh() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
getAccessTokenConfig() {
|
||||
this.$http.get('AccessTokenConfigs').then(json => {
|
||||
const firtsResult = json.data[0];
|
||||
if (!firtsResult) return;
|
||||
this.renewPeriod = firtsResult.renewPeriod;
|
||||
this.renewInterval = firtsResult.renewInterval;
|
||||
|
||||
const intervalMilliseconds = firtsResult.renewInterval * 1000;
|
||||
this.inservalId = setInterval(this.checkTokenValidity.bind(this), intervalMilliseconds);
|
||||
});
|
||||
}
|
||||
|
||||
checkTokenValidity() {
|
||||
const now = new Date();
|
||||
const differenceMilliseconds = now - new Date(this.vnToken.created);
|
||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
||||
|
||||
if (differenceSeconds > this.renewPeriod) {
|
||||
this.$http.post('VnUsers/renewToken')
|
||||
.then(json => {
|
||||
if (json.data.token) {
|
||||
let remember = true;
|
||||
if (window.sessionStorage.vnToken) remember = false;
|
||||
|
||||
this.vnToken.set(json.data.token, json.data.created, remember);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$onDestroy() {
|
||||
clearInterval(this.inservalId);
|
||||
}
|
||||
}
|
||||
Layout.$inject = ['$element', '$scope', 'vnModules'];
|
||||
Layout.$inject = ['$element', '$scope', 'vnModules', 'vnToken'];
|
||||
|
||||
ngModule.vnComponent('vnLayout', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -37,4 +37,49 @@ describe('Component vnLayout', () => {
|
|||
expect(url).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAccessTokenConfig()', () => {
|
||||
it(`should set the renewPeriod and renewInterval properties in localStorage`, () => {
|
||||
const response = [{
|
||||
renewPeriod: 100,
|
||||
renewInterval: 5
|
||||
}];
|
||||
|
||||
$httpBackend.expect('GET', `AccessTokenConfigs`).respond(response);
|
||||
controller.getAccessTokenConfig();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.renewPeriod).toBe(100);
|
||||
expect(controller.renewInterval).toBe(5);
|
||||
expect(controller.inservalId).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkTokenValidity()', () => {
|
||||
it(`should not call renewToken and not set vnToken in the controller`, () => {
|
||||
controller.renewPeriod = 100;
|
||||
controller.vnToken.created = new Date();
|
||||
|
||||
controller.checkTokenValidity();
|
||||
|
||||
expect(controller.vnToken.token).toBeNull();
|
||||
});
|
||||
|
||||
it(`should call renewToken and set vnToken properties in the controller`, () => {
|
||||
const response = {
|
||||
token: 999,
|
||||
created: new Date()
|
||||
};
|
||||
controller.renewPeriod = 100;
|
||||
const oneHourBefore = new Date(Date.now() - (60 * 60 * 1000));
|
||||
controller.vnToken.created = oneHourBefore;
|
||||
|
||||
$httpBackend.expect('POST', `VnUsers/renewToken`).respond(response);
|
||||
controller.checkTokenValidity();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnToken.token).toBe(999);
|
||||
expect(controller.vnToken.created).toEqual(response.created);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -297,6 +297,6 @@
|
|||
"Fecha fuera de rango": "Fecha fuera de rango",
|
||||
"Error while generating PDF": "Error al generar PDF",
|
||||
"Error when sending mail to client": "Error al enviar el correo al cliente",
|
||||
"Mail not sent": "Se ha producido un fallo al enviar la factura al cliente [{{clientId}}]({{{clientUrl}}}), por favor revisa la dirección de correo electrónico"
|
||||
|
||||
"Mail not sent": "Se ha producido un fallo al enviar la factura al cliente [{{clientId}}]({{{clientUrl}}}), por favor revisa la dirección de correo electrónico",
|
||||
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado"
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
<vn-icon-button
|
||||
icon="delete"
|
||||
translate-attr="{title: 'Unsubscribe'}"
|
||||
ng-click="removeConfirm.show(row)">
|
||||
ng-click="removeConfirm.show(row)"
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove">
|
||||
</vn-icon-button>
|
||||
</vn-item-section>
|
||||
</vn-item>
|
||||
|
@ -30,7 +32,9 @@
|
|||
translate-attr="{title: 'Add'}"
|
||||
vn-bind="+"
|
||||
ng-click="$ctrl.onAddClick()"
|
||||
fixed-bottom-right>
|
||||
fixed-bottom-right
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove">
|
||||
</vn-float-button>
|
||||
<vn-dialog
|
||||
vn-id="dialog"
|
||||
|
|
|
@ -5,6 +5,7 @@ import './style.scss';
|
|||
class Controller extends ModuleCard {
|
||||
reload() {
|
||||
const filter = {
|
||||
where: {id: this.$params.id},
|
||||
include: {
|
||||
relation: 'role',
|
||||
scope: {
|
||||
|
@ -14,8 +15,11 @@ class Controller extends ModuleCard {
|
|||
};
|
||||
|
||||
return Promise.all([
|
||||
this.$http.get(`VnUsers/${this.$params.id}`, {filter})
|
||||
.then(res => this.user = res.data),
|
||||
this.$http.get(`VnUsers/preview`, {filter})
|
||||
.then(res => {
|
||||
const [user] = res.data;
|
||||
this.user = user;
|
||||
}),
|
||||
this.$http.get(`Accounts/${this.$params.id}/exists`)
|
||||
.then(res => this.hasAccount = res.data.exists)
|
||||
]);
|
||||
|
|
|
@ -15,12 +15,12 @@ describe('component vnUserCard', () => {
|
|||
it('should reload the controller data', () => {
|
||||
controller.$params.id = 1;
|
||||
|
||||
$httpBackend.expectGET('VnUsers/1').respond('foo');
|
||||
$httpBackend.expectGET('VnUsers/preview').respond('foo');
|
||||
$httpBackend.expectGET('Accounts/1/exists').respond({exists: true});
|
||||
controller.reload();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.user).toBe('foo');
|
||||
expect(controller.user).toBe('f');
|
||||
expect(controller.hasAccount).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,11 @@ import ngModule from '../module';
|
|||
import Section from 'salix/components/section';
|
||||
|
||||
export default class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.user = {active: true};
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
return this.$.watcher.submit().then(res => {
|
||||
this.$state.go('account.card.basicData', {id: res.data.id});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<vn-item
|
||||
ng-click="deleteUser.show()"
|
||||
name="deleteUser"
|
||||
vn-acl="it"
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Delete
|
||||
|
@ -15,7 +15,7 @@
|
|||
ng-if="::$root.user.id == $ctrl.id"
|
||||
ng-click="$ctrl.onChangePassClick(true)"
|
||||
name="changePassword"
|
||||
vn-acl="hr"
|
||||
vn-acl="sysadmin"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Change password
|
||||
|
@ -23,7 +23,7 @@
|
|||
<vn-item
|
||||
ng-click="$ctrl.onChangePassClick(false)"
|
||||
name="setPassword"
|
||||
vn-acl="hr"
|
||||
vn-acl="sysadmin"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Set password
|
||||
|
@ -32,7 +32,7 @@
|
|||
ng-if="!$ctrl.hasAccount"
|
||||
ng-click="enableAccount.show()"
|
||||
name="enableAccount"
|
||||
vn-acl="it"
|
||||
vn-acl="sysadmin"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Enable account
|
||||
|
@ -41,7 +41,7 @@
|
|||
ng-if="$ctrl.hasAccount"
|
||||
ng-click="disableAccount.show()"
|
||||
name="disableAccount"
|
||||
vn-acl="it"
|
||||
vn-acl="sysadmin"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Disable account
|
||||
|
@ -50,7 +50,7 @@
|
|||
ng-if="!$ctrl.user.active"
|
||||
ng-click="activateUser.show()"
|
||||
name="activateUser"
|
||||
vn-acl="hr"
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Activate user
|
||||
|
@ -59,7 +59,7 @@
|
|||
ng-if="$ctrl.user.active"
|
||||
ng-click="deactivateUser.show()"
|
||||
name="deactivateUser"
|
||||
vn-acl="hr"
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Deactivate user
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
ui-sref="account.create"
|
||||
vn-tooltip="New user"
|
||||
vn-bind="+"
|
||||
vn-acl="it"
|
||||
vn-acl="itManagement"
|
||||
vn-acl-action="remove">
|
||||
<vn-float-button icon="add"></vn-float-button>
|
||||
</a>
|
|
@ -4,3 +4,4 @@ Enable mail forwarding: Habilitar redirección de correo
|
|||
All emails will be forwarded to the specified address.: >
|
||||
Todos los correos serán reenviados a la dirección especificada, no se
|
||||
mantendrá copia de los mismos en el buzón del usuario.
|
||||
You don't have enough privileges: No tienes suficientes permisos
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="VnUsers"
|
||||
url="VnUsers/preview"
|
||||
filter="::$ctrl.filter"
|
||||
limit="20">
|
||||
</vn-crud-model>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
<mg-ajax path="VnUsers/{{post.params.id}}/privileges" options="vnPost"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="VnUsers"
|
||||
data="$ctrl.user"
|
||||
id-value="$ctrl.$params.id"
|
||||
form="form"
|
||||
save="post">
|
||||
</vn-watcher>
|
||||
|
@ -11,15 +9,16 @@
|
|||
name="form"
|
||||
ng-submit="watcher.submit()"
|
||||
class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg" vn-focus>
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-vertical>
|
||||
<vn-check
|
||||
label="Has grant"
|
||||
ng-model="$ctrl.user.hasGrant">
|
||||
</vn-check>
|
||||
</vn-vertical>
|
||||
<vn-vertical
|
||||
class="vn-mt-md">
|
||||
</vn-card>
|
||||
<vn-card class="vn-pa-lg vn-mt-md">
|
||||
<vn-vertical>
|
||||
<vn-autocomplete
|
||||
label="Role"
|
||||
ng-model="$ctrl.user.roleFk"
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
import ngModule from '../module';
|
||||
import Section from 'salix/components/section';
|
||||
|
||||
export default class Controller extends Section {}
|
||||
export default class Controller extends Section {
|
||||
get user() {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
set user(value) {
|
||||
this._user = value;
|
||||
if (!value) return;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.component('vnUserPrivileges', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
user: '<'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -49,15 +49,13 @@
|
|||
"url": "/index?q",
|
||||
"state": "account.index",
|
||||
"component": "vn-user-index",
|
||||
"description": "Users",
|
||||
"acl": ["marketing", "hr"]
|
||||
"description": "Users"
|
||||
},
|
||||
{
|
||||
"url": "/create",
|
||||
"state": "account.create",
|
||||
"component": "vn-user-create",
|
||||
"description": "New user",
|
||||
"acl": ["it"]
|
||||
"description": "New user"
|
||||
},
|
||||
{
|
||||
"url": "/:id",
|
||||
|
@ -80,7 +78,7 @@
|
|||
"state": "account.card.basicData",
|
||||
"component": "vn-user-basic-data",
|
||||
"description": "Basic data",
|
||||
"acl": ["hr"]
|
||||
"acl": ["itManagement"]
|
||||
},
|
||||
{
|
||||
"url" : "/log",
|
||||
|
@ -98,8 +96,7 @@
|
|||
"url": "/roles",
|
||||
"state": "account.card.roles",
|
||||
"component": "vn-user-roles",
|
||||
"description": "Inherited roles",
|
||||
"acl": ["it"]
|
||||
"description": "Inherited roles"
|
||||
},
|
||||
{
|
||||
"url": "/mail-forwarding",
|
||||
|
@ -111,15 +108,16 @@
|
|||
"url": "/aliases",
|
||||
"state": "account.card.aliases",
|
||||
"component": "vn-user-aliases",
|
||||
"description": "Mail aliases",
|
||||
"acl": ["marketing", "hr"]
|
||||
"description": "Mail aliases"
|
||||
},
|
||||
{
|
||||
"url": "/privileges",
|
||||
"state": "account.card.privileges",
|
||||
"component": "vn-user-privileges",
|
||||
"description": "Privileges",
|
||||
"acl": ["hr"]
|
||||
"params": {
|
||||
"user": "$ctrl.user"
|
||||
}
|
||||
},
|
||||
{
|
||||
"url": "/role?q",
|
||||
|
@ -180,8 +178,7 @@
|
|||
"url": "/alias?q",
|
||||
"state": "account.alias",
|
||||
"component": "vn-alias",
|
||||
"description": "Mail aliases",
|
||||
"acl": ["marketing"]
|
||||
"description": "Mail aliases"
|
||||
},
|
||||
{
|
||||
"url": "/create",
|
||||
|
|
|
@ -8,6 +8,7 @@ class Controller extends Summary {
|
|||
if (!value) return;
|
||||
|
||||
const filter = {
|
||||
where: {id: value.id},
|
||||
include: {
|
||||
relation: 'role',
|
||||
scope: {
|
||||
|
@ -15,8 +16,11 @@ class Controller extends Summary {
|
|||
}
|
||||
}
|
||||
};
|
||||
this.$http.get(`VnUsers/${value.id}`, {filter})
|
||||
.then(res => this.$.summary = res.data);
|
||||
this.$http.get(`VnUsers/preview`, {filter})
|
||||
.then(res => {
|
||||
const [summary] = res.data;
|
||||
this.$.summary = summary;
|
||||
});
|
||||
}
|
||||
get isHr() {
|
||||
return this.aclService.hasAny(['hr']);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="VnUsers"
|
||||
id-field="id"
|
||||
data="$ctrl.account"
|
||||
form="form">
|
||||
</vn-watcher>
|
||||
|
|
|
@ -8,6 +8,22 @@ export default class Controller extends Section {
|
|||
this.canEnableCheckBox = true;
|
||||
}
|
||||
|
||||
set client(value) {
|
||||
this._client = value;
|
||||
if (!value) return;
|
||||
|
||||
const filter = {where: {id: value.id}};
|
||||
this.$http.get(`VnUsers/preview`, {filter})
|
||||
.then(res => {
|
||||
const [user] = res.data;
|
||||
this.account = user;
|
||||
});
|
||||
}
|
||||
|
||||
get client() {
|
||||
return this._client;
|
||||
}
|
||||
|
||||
$onChanges() {
|
||||
if (this.client) {
|
||||
this.account = this.client.account;
|
||||
|
|
|
@ -5,12 +5,14 @@ describe('Component VnClientWebAccess', () => {
|
|||
let $scope;
|
||||
let vnApp;
|
||||
let controller;
|
||||
let $httpParamSerializer;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_, _vnApp_) => {
|
||||
$scope = $rootScope.$new();
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
vnApp = _vnApp_;
|
||||
jest.spyOn(vnApp, 'showError');
|
||||
const $element = angular.element('<vn-client-web-access></vn-client-web-access>');
|
||||
|
@ -32,7 +34,10 @@ describe('Component VnClientWebAccess', () => {
|
|||
describe('isCustomer()', () => {
|
||||
it('should return true if the password can be modified', () => {
|
||||
controller.client = {id: '1234'};
|
||||
const filter = {where: {id: controller.client.id}};
|
||||
const serializedParams = $httpParamSerializer({filter});
|
||||
|
||||
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
|
||||
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(true);
|
||||
controller.isCustomer();
|
||||
$httpBackend.flush();
|
||||
|
@ -42,7 +47,10 @@ describe('Component VnClientWebAccess', () => {
|
|||
|
||||
it(`should return a false if the password can't be modified`, () => {
|
||||
controller.client = {id: '1234'};
|
||||
const filter = {where: {id: controller.client.id}};
|
||||
const serializedParams = $httpParamSerializer({filter});
|
||||
|
||||
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
|
||||
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(false);
|
||||
controller.isCustomer();
|
||||
$httpBackend.flush();
|
||||
|
@ -54,9 +62,12 @@ describe('Component VnClientWebAccess', () => {
|
|||
describe('checkConditions()', () => {
|
||||
it('should perform a query to check if the client is valid', () => {
|
||||
controller.client = {id: '1234'};
|
||||
const filter = {where: {id: controller.client.id}};
|
||||
const serializedParams = $httpParamSerializer({filter});
|
||||
|
||||
expect(controller.canEnableCheckBox).toBeTruthy();
|
||||
|
||||
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
|
||||
$httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`).respond(false);
|
||||
controller.checkConditions();
|
||||
$httpBackend.flush();
|
||||
|
@ -82,7 +93,10 @@ describe('Component VnClientWebAccess', () => {
|
|||
controller.newPassword = 'm24x8';
|
||||
controller.repeatPassword = 'm24x8';
|
||||
controller.canChangePassword = true;
|
||||
const filter = {where: {id: controller.client.id}};
|
||||
const serializedParams = $httpParamSerializer({filter});
|
||||
|
||||
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
|
||||
const query = `Clients/${controller.client.id}/setPassword`;
|
||||
$httpBackend.expectPATCH(query, {newPassword: controller.newPassword}).respond('done');
|
||||
controller.onPassChange();
|
||||
|
|
|
@ -75,7 +75,7 @@ module.exports = Self => {
|
|||
value[field] = newValue;
|
||||
|
||||
if (filter) {
|
||||
ctx.args.filter = {where: filter, limit: null};
|
||||
ctx.args = {where: filter, limit: null};
|
||||
lines = await models.Buy.latestBuysFilter(ctx, null, myOptions);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,36 @@ describe('Buy editLatestsBuys()', () => {
|
|||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const filter = {'i.typeFk': 1};
|
||||
const filter = {'categoryFk': 1, 'tags': []};
|
||||
const ctx = {
|
||||
args: {
|
||||
filter: filter
|
||||
},
|
||||
req: {accessToken: {userId: 1}}
|
||||
};
|
||||
|
||||
const field = 'size';
|
||||
const newValue = 88;
|
||||
|
||||
await models.Buy.editLatestBuys(ctx, field, newValue, null, filter, options);
|
||||
|
||||
const [result] = await models.Buy.latestBuysFilter(ctx, null, options);
|
||||
|
||||
expect(result[field]).toEqual(newValue);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should change the value of a given column for filter tags', async() => {
|
||||
const tx = await models.Buy.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const filter = {'tags': [{tagFk: 1, value: 'Brown'}]};
|
||||
const ctx = {
|
||||
args: {
|
||||
filter: filter
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('isAuthorized', {
|
||||
description: 'Return true if the current user is a superior of the worker that is passed by parameter',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'ctx',
|
||||
type: 'Object',
|
||||
http: {source: 'context'}
|
||||
}, {
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The worker id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/isAuthorized`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.isAuthorized = async(ctx, id, options) => {
|
||||
const models = Self.app.models;
|
||||
const currentUserId = ctx.req.accessToken.userId;
|
||||
const isHimself = currentUserId == id;
|
||||
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions);
|
||||
const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions);
|
||||
|
||||
if (!isSubordinate || (isSubordinate && isHimself && !isTeamBoss))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
|
@ -16,6 +16,7 @@ module.exports = Self => {
|
|||
require('../methods/worker/new')(Self);
|
||||
require('../methods/worker/deallocatePDA')(Self);
|
||||
require('../methods/worker/allocatePDA')(Self);
|
||||
require('../methods/worker/isAuthorized')(Self);
|
||||
|
||||
Self.validatesUniquenessOf('locker', {
|
||||
message: 'This locker has already been assigned'
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<mg-ajax
|
||||
path="VnUsers/{{$ctrl.worker.userFk}}"
|
||||
actions="user = edit.model"
|
||||
options="mgEdit">
|
||||
</mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="VnUsers"
|
||||
id-field="id"
|
||||
data="user"
|
||||
form="form">
|
||||
</vn-watcher>
|
||||
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-vertical>
|
||||
<vn-horizontal>
|
||||
<vn-field
|
||||
vn-one
|
||||
label="Nickname"
|
||||
ng-model="user.nickname">
|
||||
</vn-field>
|
||||
</vn-horizontal>
|
||||
</vn-vertical>
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit label="Save"></vn-submit>
|
||||
<vn-button
|
||||
label="Undo changes"
|
||||
ng-if="watcher.dataChanged()"
|
||||
ng-click="watcher.loadOriginalData()">
|
||||
</vn-button>
|
||||
</vn-button-bar>
|
||||
</form>
|
|
@ -63,6 +63,7 @@
|
|||
ng-model="$ctrl.businessId"
|
||||
search-function="{businessFk: $search}"
|
||||
value-field="businessFk"
|
||||
show-field="businessFk"
|
||||
order="businessFk DESC"
|
||||
limit="5">
|
||||
<tpl-item>
|
||||
|
|
|
@ -71,10 +71,6 @@ class Controller extends Section {
|
|||
}
|
||||
}
|
||||
|
||||
get payedHolidays() {
|
||||
return this._businessId;
|
||||
}
|
||||
|
||||
buildYearFilter() {
|
||||
const now = Date.vnNew();
|
||||
now.setFullYear(now.getFullYear() + 1);
|
||||
|
@ -95,9 +91,9 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
getActiveContract() {
|
||||
this.$http.get(`Workers/${this.worker.id}/activeContract`).then(res => {
|
||||
if (res.data)
|
||||
this.businessId = res.data.businessFk;
|
||||
this.$http.get(`Workers/${this.worker.id}/activeContract`)
|
||||
.then(res => {
|
||||
if (res.data) this.businessId = res.data.businessFk;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,9 @@ module.exports = {
|
|||
name: 'report-footer',
|
||||
async serverPrefetch() {
|
||||
this.company = await db.findOne(`
|
||||
SELECT IFNULL(ci.footnotes, cl.footnotes) as footnotes
|
||||
SELECT IFNULL(ci.footnotes, c.footnotes) footnotes
|
||||
FROM company c
|
||||
LEFT JOIN companyL10n cl ON c.id = cl.id
|
||||
LEFT JOIN companyI18n ci ON ci.companyFk = cl.id
|
||||
LEFT JOIN companyI18n ci ON ci.companyFk = c.id
|
||||
AND ci.lang = (SELECT lang FROM account.user where id = ?)
|
||||
WHERE c.code = ?`,
|
||||
[this.recipientId, this.companyCode]);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||
|
||||
const path = require('path');
|
||||
const vnPrintPath = path.resolve('print');
|
||||
|
||||
module.exports = new Stylesheet([
|
||||
`${vnPrintPath}/common/css/spacing.css`,
|
||||
`${vnPrintPath}/common/css/misc.css`,
|
||||
`${vnPrintPath}/common/css/layout.css`,
|
||||
`${vnPrintPath}/common/css/email.css`,
|
||||
`${__dirname}/style.css`])
|
||||
.mergeStyles();
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
.external-link {
|
||||
border: 2px dashed #8dba25;
|
||||
border-radius: 3px;
|
||||
text-align: center
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<email-body v-bind="$props">
|
||||
<div class="grid-row">
|
||||
<div class="grid-block vn-pa-ml">
|
||||
<p>
|
||||
{{$t('dear')}}
|
||||
</p>
|
||||
<p v-html="$t('body',[currencyName,referenceCurrent])"></p>
|
||||
</div>
|
||||
</div>
|
||||
</email-body>
|
|
@ -0,0 +1,19 @@
|
|||
const Component = require(`vn-print/core/component`);
|
||||
const emailBody = new Component('email-body');
|
||||
|
||||
module.exports = {
|
||||
name: 'entry-update-comission',
|
||||
components: {
|
||||
'email-body': emailBody.build(),
|
||||
},
|
||||
props: {
|
||||
currencyName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
referenceCurrent: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
subject: Actualización tipo de cambio en entradas
|
||||
title: Actualización tipo de cambio en entradas
|
||||
dear: Hola,
|
||||
body: 'El tipo de cambio para las ENTRADAS/COMPRAS en <strong>{0}</strong> se ha actualizado a partir de hoy en: <strong>{1}</strong>'
|
Loading…
Reference in New Issue