From 3c144ea0cdba735f259e1a3f37d9738ca62c81ad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 22 Nov 2019 13:46:38 +0100 Subject: [PATCH] transaction changes --- back/methods/dms/uploadFile.js | 4 +-- back/models/account.js | 8 ++--- back/models/dmsType.js | 21 +++++++----- .../back/methods/claim-dms/removeFile.js | 2 +- .../back/methods/client-dms/removeFile.js | 2 +- .../back/methods/worker-dms/removeFile.js | 8 ++--- modules/worker/front/dms/create/index.html | 2 +- modules/worker/front/dms/create/index.js | 13 +++---- modules/worker/front/dms/edit/index.html | 12 +++++-- modules/worker/front/dms/edit/index.js | 34 +++++++------------ modules/worker/front/dms/index/index.html | 2 +- modules/worker/front/dms/index/index.js | 15 ++++---- modules/worker/front/dms/locale/es.yml | 12 +++++-- 13 files changed, 68 insertions(+), 67 deletions(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index e077eea30..27e5169c9 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -63,7 +63,7 @@ module.exports = Self => { } try { - const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId); + const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions); if (!hasWriteRole) throw new UserError(`You don't have enough privileges`); @@ -83,7 +83,7 @@ module.exports = Self => { const originPath = `${tempContainer.client.root}/${tempContainer.name}/${file.name}`; const destinationPath = `${container.client.root}/${pathHash}/${newDms.file}`; - fs.rename(originPath, destinationPath); + await fs.rename(originPath, destinationPath); addedDms.push(newDms); } diff --git a/back/models/account.js b/back/models/account.js index 00c583d31..92ec589c5 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -60,8 +60,8 @@ module.exports = Self => { * @param {String} name The role name * @return {Boolean} %true if user has the role, %false otherwise */ - Self.hasRole = async function(userId, name) { - let roles = await Self.getRoles(userId); + Self.hasRole = async function(userId, name, options) { + let roles = await Self.getRoles(userId, options); return roles.some(role => role == name); }; @@ -71,13 +71,13 @@ module.exports = Self => { * @param {Integer} userId The user id * @return {Object} User role list */ - Self.getRoles = async userId => { + 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]); + WHERE u.id = ?`, [userId], options); let roles = []; for (role of result) diff --git a/back/models/dmsType.js b/back/models/dmsType.js index f76b095df..267c905e9 100644 --- a/back/models/dmsType.js +++ b/back/models/dmsType.js @@ -5,17 +5,18 @@ module.exports = Self => { * * @param {Object} ctx - Request context * @param {Interger} id - DmsType id + * @param {Object} options - Query options * @return {Boolean} True for user with read privileges */ - Self.hasReadRole = async(ctx, id) => { + Self.hasReadRole = async(ctx, id, options) => { const models = Self.app.models; const dmsType = await models.DmsType.findById(id, { include: { relation: 'readRole' } - }); + }, options); - return await hasRole(ctx, dmsType); + return await hasRole(ctx, dmsType, options); }; /** @@ -24,17 +25,18 @@ module.exports = Self => { * * @param {Object} ctx - Request context * @param {Interger} id - DmsType id + * @param {Object} options - Query options * @return {Boolean} True for user with write privileges */ - Self.hasWriteRole = async(ctx, id) => { + Self.hasWriteRole = async(ctx, id, options) => { const models = Self.app.models; const dmsType = await models.DmsType.findById(id, { include: { relation: 'writeRole' } - }); + }, options); - return await hasRole(ctx, dmsType); + return await hasRole(ctx, dmsType, options); }; /** @@ -42,8 +44,9 @@ module.exports = Self => { * read or write privileges * @param {Object} ctx - Context * @param {Object} dmsType - Dms type [read/write] + * @param {Object} options - Query options */ - async function hasRole(ctx, dmsType) { + async function hasRole(ctx, dmsType, options) { const models = Self.app.models; const myUserId = ctx.req.accessToken.userId; @@ -51,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); - const isRoot = await models.Account.hasRole(myUserId, 'root'); + const hasRequiredRole = await models.Account.hasRole(myUserId, requiredRole, options); + const isRoot = await models.Account.hasRole(myUserId, 'root', options); if (isRoot || hasRequiredRole) return true; diff --git a/modules/claim/back/methods/claim-dms/removeFile.js b/modules/claim/back/methods/claim-dms/removeFile.js index 8de764db0..ac546455a 100644 --- a/modules/claim/back/methods/claim-dms/removeFile.js +++ b/modules/claim/back/methods/claim-dms/removeFile.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('removeFile', { - description: 'Removes a ticket document', + description: 'Removes a claim document', accessType: 'WRITE', accepts: { arg: 'id', diff --git a/modules/client/back/methods/client-dms/removeFile.js b/modules/client/back/methods/client-dms/removeFile.js index 6cf7ccc41..5ff123630 100644 --- a/modules/client/back/methods/client-dms/removeFile.js +++ b/modules/client/back/methods/client-dms/removeFile.js @@ -20,7 +20,7 @@ module.exports = Self => { Self.removeFile = async(ctx, id) => { const models = Self.app.models; - const clientDms = await models.ClientDms.findById(id); + const clientDms = await Self.findById(id); await models.Dms.removeFile(ctx, clientDms.dmsFk); diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index 6cf7ccc41..d0116c3c2 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('removeFile', { - description: 'Removes a client document', + description: 'Removes a worker document', accessType: 'WRITE', accepts: { arg: 'id', @@ -20,11 +20,11 @@ module.exports = Self => { Self.removeFile = async(ctx, id) => { const models = Self.app.models; - const clientDms = await models.ClientDms.findById(id); + const workerDms = await Self.findById(id); - await models.Dms.removeFile(ctx, clientDms.dmsFk); + await models.Dms.removeFile(ctx, workerDms.dmsFk); - return clientDms.destroy(); + return workerDms.destroy(); }; }; diff --git a/modules/worker/front/dms/create/index.html b/modules/worker/front/dms/create/index.html index 4ed221ae8..dcafa5986 100644 --- a/modules/worker/front/dms/create/index.html +++ b/modules/worker/front/dms/create/index.html @@ -77,7 +77,7 @@ - + diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index d14d9fd92..e7bfe7bfd 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -1,13 +1,10 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; +class Controller extends Component { + constructor($element, $, vnConfig) { + super($element, $); this.vnConfig = vnConfig; this.dms = { files: [], @@ -106,7 +103,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; +Controller.$inject = ['$element', '$scope', 'vnConfig']; ngModule.component('vnWorkerDmsCreate', { template: require('./index.html'), diff --git a/modules/worker/front/dms/edit/index.html b/modules/worker/front/dms/edit/index.html index dbc2e0ed1..13bf6f953 100644 --- a/modules/worker/front/dms/edit/index.html +++ b/modules/worker/front/dms/edit/index.html @@ -56,7 +56,15 @@ label="File" ng-model="$ctrl.dms.files" on-change="$ctrl.onFileChange($files)" - accept=".pdf, .png, .jpg, .jpeg, application/zip, application/rar, application/x-7z-compressed"> + accept="{{$ctrl.allowedContentTypes}}" + multiple="true"> + + + + @@ -68,7 +76,7 @@ - + diff --git a/modules/worker/front/dms/edit/index.js b/modules/worker/front/dms/edit/index.js index 460aa17a7..1a593414a 100644 --- a/modules/worker/front/dms/edit/index.js +++ b/modules/worker/front/dms/edit/index.js @@ -1,22 +1,14 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $state.params; - this.$translate = $translate; - this.vnApp = vnApp; +class Controller extends Component { + get worker() { + return this._worker; } - get client() { - return this._client; - } - - set client(value) { - this._client = value; + set worker(value) { + this._worker = value; if (value) { this.setDefaultParams(); @@ -25,7 +17,7 @@ class Controller { } getAllowedContentTypes() { - this.$http.get('clientDms/allowedContentTypes').then(res => { + this.$http.get('WorkerDms/allowedContentTypes').then(res => { const contentTypes = res.data.join(', '); this.allowedContentTypes = contentTypes; }); @@ -38,7 +30,7 @@ class Controller { } setDefaultParams() { - const path = `Dms/${this.$stateParams.dmsId}`; + const path = `Dms/${this.$params.dmsId}`; this.$http.get(path).then(res => { const dms = res.data && res.data; this.dms = { @@ -55,7 +47,7 @@ class Controller { } onSubmit() { - const query = `dms/${this.$stateParams.dmsId}/updateFile`; + const query = `dms/${this.$params.dmsId}/updateFile`; const options = { method: 'POST', url: query, @@ -77,7 +69,7 @@ class Controller { if (res) { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$.watcher.updateOriginalData(); - this.$state.go('client.card.dms.index'); + this.$state.go('worker.card.dms.index'); } }); } @@ -93,12 +85,10 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; - -ngModule.component('vnClientDmsEdit', { +ngModule.component('vnWorkerDmsEdit', { template: require('./index.html'), controller: Controller, bindings: { - client: '<' + worker: '<' } }); diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 491248171..7859a50a4 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -1,7 +1,7 @@ { this.$.model.remove(this.dmsIndex); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); @@ -71,7 +68,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', 'vnToken', '$http', 'vnApp', '$translate']; +Controller.$inject = ['$element', '$scope', 'vnToken']; ngModule.component('vnWorkerDmsIndex', { template: require('./index.html'), diff --git a/modules/worker/front/dms/locale/es.yml b/modules/worker/front/dms/locale/es.yml index 4185098f3..fa4178d35 100644 --- a/modules/worker/front/dms/locale/es.yml +++ b/modules/worker/front/dms/locale/es.yml @@ -1,14 +1,20 @@ +Reference: Referencia +Description: Descripción +Company: Empresa Upload file: Subir fichero Edit file: Editar fichero Upload: Subir File: Fichero -ClientFileDescription: "{{dmsTypeName}} del cliente {{clientName}} id {{clientId}}" +WorkerFileDescription: "{{dmsTypeName}} del empleado {{workerName}} id {{workerId}}" ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}" Generate identifier for original file: Generar identificador para archivo original +Are you sure you want to continue?: ¿Seguro que quieres continuar? File management: Gestión documental Hard copy: Copia This file will be deleted: Este fichero va a ser borrado -Are you sure?: Estas seguro? +Are you sure?: ¿Seguro? File deleted: Fichero eliminado Remove file: Eliminar fichero -Download file: Descargar fichero \ No newline at end of file +Download file: Descargar fichero +Created: Creado +Employee: Empleado \ No newline at end of file