transaction changes
gitea/salix/1762-worker_dms There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2019-11-22 13:46:38 +01:00
parent 5aae48c7dc
commit 3c144ea0cd
13 changed files with 68 additions and 67 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -77,7 +77,7 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Upload"></vn-submit>
<vn-button ui-sref="client.card.dms.index" label="Cancel"></vn-button>
<vn-button ui-sref="worker.card.dms.index" label="Cancel"></vn-button>
</vn-button-bar>
</div>
</form>

View File

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

View File

@ -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">
<append>
<vn-icon vn-none
color-marginal
title="{{$ctrl.contentTypesInfo}}"
icon="info">
</vn-icon>
</append>
</vn-input-file>
</vn-horizontal>
<vn-vertical>
@ -68,7 +76,7 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ui-sref="client.card.dms.index" label="Cancel"></vn-button>
<vn-button ui-sref="worker.card.dms.index" label="Cancel"></vn-button>
</vn-button-bar>
</div>
</form>

View File

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

View File

@ -1,7 +1,7 @@
<vn-crud-model
vn-id="model"
url="WorkerDms"
link="{workerFk: $ctrl.$stateParams.id}"
link="{workerFk: $ctrl.$params.id}"
filter="::$ctrl.filter"
limit="20"
data="$ctrl.workerDms"

View File

@ -1,14 +1,11 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller {
constructor($stateParams, $scope, vnToken, $http, vnApp, $translate) {
this.$stateParams = $stateParams;
this.$ = $scope;
class Controller extends Component {
constructor($element, $, vnToken) {
super($element, $);
this.accessToken = vnToken.token;
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.filter = {
include: {
relation: 'dms',
@ -62,7 +59,7 @@ class Controller {
deleteDms(response) {
if (response === 'accept') {
const dmsFk = this.workerDms[this.dmsIndex].dmsFk;
const query = `workerDms/${dmsFk}/removeFile`;
const query = `WorkerDms/${dmsFk}/removeFile`;
this.$http.post(query).then(() => {
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'),

View File

@ -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
Created: Creado
Employee: Empleado