transaction changes
gitea/salix/1762-worker_dms There was a failure building this commit
Details
gitea/salix/1762-worker_dms There was a failure building this commit
Details
This commit is contained in:
parent
5aae48c7dc
commit
3c144ea0cd
|
@ -63,7 +63,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId);
|
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
|
||||||
if (!hasWriteRole)
|
if (!hasWriteRole)
|
||||||
throw new UserError(`You don't have enough privileges`);
|
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 originPath = `${tempContainer.client.root}/${tempContainer.name}/${file.name}`;
|
||||||
const destinationPath = `${container.client.root}/${pathHash}/${newDms.file}`;
|
const destinationPath = `${container.client.root}/${pathHash}/${newDms.file}`;
|
||||||
|
|
||||||
fs.rename(originPath, destinationPath);
|
await fs.rename(originPath, destinationPath);
|
||||||
|
|
||||||
addedDms.push(newDms);
|
addedDms.push(newDms);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@ module.exports = Self => {
|
||||||
* @param {String} name The role name
|
* @param {String} name The role name
|
||||||
* @return {Boolean} %true if user has the role, %false otherwise
|
* @return {Boolean} %true if user has the role, %false otherwise
|
||||||
*/
|
*/
|
||||||
Self.hasRole = async function(userId, name) {
|
Self.hasRole = async function(userId, name, options) {
|
||||||
let roles = await Self.getRoles(userId);
|
let roles = await Self.getRoles(userId, options);
|
||||||
return roles.some(role => role == name);
|
return roles.some(role => role == name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,13 +71,13 @@ module.exports = Self => {
|
||||||
* @param {Integer} userId The user id
|
* @param {Integer} userId The user id
|
||||||
* @return {Object} User role list
|
* @return {Object} User role list
|
||||||
*/
|
*/
|
||||||
Self.getRoles = async userId => {
|
Self.getRoles = async(userId, options) => {
|
||||||
let result = await Self.rawSql(
|
let result = await Self.rawSql(
|
||||||
`SELECT r.name
|
`SELECT r.name
|
||||||
FROM account.user u
|
FROM account.user u
|
||||||
JOIN account.roleRole rr ON rr.role = u.role
|
JOIN account.roleRole rr ON rr.role = u.role
|
||||||
JOIN account.role r ON r.id = rr.inheritsFrom
|
JOIN account.role r ON r.id = rr.inheritsFrom
|
||||||
WHERE u.id = ?`, [userId]);
|
WHERE u.id = ?`, [userId], options);
|
||||||
|
|
||||||
let roles = [];
|
let roles = [];
|
||||||
for (role of result)
|
for (role of result)
|
||||||
|
|
|
@ -5,17 +5,18 @@ module.exports = Self => {
|
||||||
*
|
*
|
||||||
* @param {Object} ctx - Request context
|
* @param {Object} ctx - Request context
|
||||||
* @param {Interger} id - DmsType id
|
* @param {Interger} id - DmsType id
|
||||||
|
* @param {Object} options - Query options
|
||||||
* @return {Boolean} True for user with read privileges
|
* @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 models = Self.app.models;
|
||||||
const dmsType = await models.DmsType.findById(id, {
|
const dmsType = await models.DmsType.findById(id, {
|
||||||
include: {
|
include: {
|
||||||
relation: 'readRole'
|
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 {Object} ctx - Request context
|
||||||
* @param {Interger} id - DmsType id
|
* @param {Interger} id - DmsType id
|
||||||
|
* @param {Object} options - Query options
|
||||||
* @return {Boolean} True for user with write privileges
|
* @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 models = Self.app.models;
|
||||||
const dmsType = await models.DmsType.findById(id, {
|
const dmsType = await models.DmsType.findById(id, {
|
||||||
include: {
|
include: {
|
||||||
relation: 'writeRole'
|
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
|
* read or write privileges
|
||||||
* @param {Object} ctx - Context
|
* @param {Object} ctx - Context
|
||||||
* @param {Object} dmsType - Dms type [read/write]
|
* @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 models = Self.app.models;
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
const myUserId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
@ -51,8 +54,8 @@ module.exports = Self => {
|
||||||
const writeRole = dmsType.writeRole() && dmsType.writeRole().name;
|
const writeRole = dmsType.writeRole() && dmsType.writeRole().name;
|
||||||
const requiredRole = readRole || writeRole;
|
const requiredRole = readRole || writeRole;
|
||||||
|
|
||||||
const hasRequiredRole = await models.Account.hasRole(myUserId, requiredRole);
|
const hasRequiredRole = await models.Account.hasRole(myUserId, requiredRole, options);
|
||||||
const isRoot = await models.Account.hasRole(myUserId, 'root');
|
const isRoot = await models.Account.hasRole(myUserId, 'root', options);
|
||||||
|
|
||||||
if (isRoot || hasRequiredRole)
|
if (isRoot || hasRequiredRole)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('removeFile', {
|
Self.remoteMethodCtx('removeFile', {
|
||||||
description: 'Removes a ticket document',
|
description: 'Removes a claim document',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: {
|
accepts: {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id) => {
|
Self.removeFile = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
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);
|
await models.Dms.removeFile(ctx, clientDms.dmsFk);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('removeFile', {
|
Self.remoteMethodCtx('removeFile', {
|
||||||
description: 'Removes a client document',
|
description: 'Removes a worker document',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: {
|
accepts: {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
@ -20,11 +20,11 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id) => {
|
Self.removeFile = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
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();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-submit label="Upload"></vn-submit>
|
<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>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller {
|
class Controller extends Component {
|
||||||
constructor($scope, $http, $state, $translate, vnApp, vnConfig) {
|
constructor($element, $, vnConfig) {
|
||||||
this.$ = $scope;
|
super($element, $);
|
||||||
this.$http = $http;
|
|
||||||
this.$state = $state;
|
|
||||||
this.$translate = $translate;
|
|
||||||
this.vnApp = vnApp;
|
|
||||||
this.vnConfig = vnConfig;
|
this.vnConfig = vnConfig;
|
||||||
this.dms = {
|
this.dms = {
|
||||||
files: [],
|
files: [],
|
||||||
|
@ -106,7 +103,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig'];
|
Controller.$inject = ['$element', '$scope', 'vnConfig'];
|
||||||
|
|
||||||
ngModule.component('vnWorkerDmsCreate', {
|
ngModule.component('vnWorkerDmsCreate', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -56,7 +56,15 @@
|
||||||
label="File"
|
label="File"
|
||||||
ng-model="$ctrl.dms.files"
|
ng-model="$ctrl.dms.files"
|
||||||
on-change="$ctrl.onFileChange($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-input-file>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
|
@ -68,7 +76,7 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-submit label="Save"></vn-submit>
|
<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>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller {
|
class Controller extends Component {
|
||||||
constructor($scope, $http, $state, $translate, vnApp) {
|
get worker() {
|
||||||
this.$ = $scope;
|
return this._worker;
|
||||||
this.$http = $http;
|
|
||||||
this.$state = $state;
|
|
||||||
this.$stateParams = $state.params;
|
|
||||||
this.$translate = $translate;
|
|
||||||
this.vnApp = vnApp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
set worker(value) {
|
||||||
return this._client;
|
this._worker = value;
|
||||||
}
|
|
||||||
|
|
||||||
set client(value) {
|
|
||||||
this._client = value;
|
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.setDefaultParams();
|
this.setDefaultParams();
|
||||||
|
@ -25,7 +17,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllowedContentTypes() {
|
getAllowedContentTypes() {
|
||||||
this.$http.get('clientDms/allowedContentTypes').then(res => {
|
this.$http.get('WorkerDms/allowedContentTypes').then(res => {
|
||||||
const contentTypes = res.data.join(', ');
|
const contentTypes = res.data.join(', ');
|
||||||
this.allowedContentTypes = contentTypes;
|
this.allowedContentTypes = contentTypes;
|
||||||
});
|
});
|
||||||
|
@ -38,7 +30,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultParams() {
|
setDefaultParams() {
|
||||||
const path = `Dms/${this.$stateParams.dmsId}`;
|
const path = `Dms/${this.$params.dmsId}`;
|
||||||
this.$http.get(path).then(res => {
|
this.$http.get(path).then(res => {
|
||||||
const dms = res.data && res.data;
|
const dms = res.data && res.data;
|
||||||
this.dms = {
|
this.dms = {
|
||||||
|
@ -55,7 +47,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `dms/${this.$stateParams.dmsId}/updateFile`;
|
const query = `dms/${this.$params.dmsId}/updateFile`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
@ -77,7 +69,7 @@ class Controller {
|
||||||
if (res) {
|
if (res) {
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||||
this.$.watcher.updateOriginalData();
|
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('vnWorkerDmsEdit', {
|
||||||
|
|
||||||
ngModule.component('vnClientDmsEdit', {
|
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
worker: '<'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="WorkerDms"
|
url="WorkerDms"
|
||||||
link="{workerFk: $ctrl.$stateParams.id}"
|
link="{workerFk: $ctrl.$params.id}"
|
||||||
filter="::$ctrl.filter"
|
filter="::$ctrl.filter"
|
||||||
limit="20"
|
limit="20"
|
||||||
data="$ctrl.workerDms"
|
data="$ctrl.workerDms"
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller {
|
class Controller extends Component {
|
||||||
constructor($stateParams, $scope, vnToken, $http, vnApp, $translate) {
|
constructor($element, $, vnToken) {
|
||||||
this.$stateParams = $stateParams;
|
super($element, $);
|
||||||
this.$ = $scope;
|
|
||||||
this.accessToken = vnToken.token;
|
this.accessToken = vnToken.token;
|
||||||
this.$http = $http;
|
|
||||||
this.vnApp = vnApp;
|
|
||||||
this.$translate = $translate;
|
|
||||||
this.filter = {
|
this.filter = {
|
||||||
include: {
|
include: {
|
||||||
relation: 'dms',
|
relation: 'dms',
|
||||||
|
@ -62,7 +59,7 @@ class Controller {
|
||||||
deleteDms(response) {
|
deleteDms(response) {
|
||||||
if (response === 'accept') {
|
if (response === 'accept') {
|
||||||
const dmsFk = this.workerDms[this.dmsIndex].dmsFk;
|
const dmsFk = this.workerDms[this.dmsIndex].dmsFk;
|
||||||
const query = `workerDms/${dmsFk}/removeFile`;
|
const query = `WorkerDms/${dmsFk}/removeFile`;
|
||||||
this.$http.post(query).then(() => {
|
this.$http.post(query).then(() => {
|
||||||
this.$.model.remove(this.dmsIndex);
|
this.$.model.remove(this.dmsIndex);
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
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', {
|
ngModule.component('vnWorkerDmsIndex', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
|
Reference: Referencia
|
||||||
|
Description: Descripción
|
||||||
|
Company: Empresa
|
||||||
Upload file: Subir fichero
|
Upload file: Subir fichero
|
||||||
Edit file: Editar fichero
|
Edit file: Editar fichero
|
||||||
Upload: Subir
|
Upload: Subir
|
||||||
File: Fichero
|
File: Fichero
|
||||||
ClientFileDescription: "{{dmsTypeName}} del cliente {{clientName}} id {{clientId}}"
|
WorkerFileDescription: "{{dmsTypeName}} del empleado {{workerName}} id {{workerId}}"
|
||||||
ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}"
|
ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}"
|
||||||
Generate identifier for original file: Generar identificador para archivo original
|
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
|
File management: Gestión documental
|
||||||
Hard copy: Copia
|
Hard copy: Copia
|
||||||
This file will be deleted: Este fichero va a ser borrado
|
This file will be deleted: Este fichero va a ser borrado
|
||||||
Are you sure?: Estas seguro?
|
Are you sure?: ¿Seguro?
|
||||||
File deleted: Fichero eliminado
|
File deleted: Fichero eliminado
|
||||||
Remove file: Eliminar fichero
|
Remove file: Eliminar fichero
|
||||||
Download file: Descargar fichero
|
Download file: Descargar fichero
|
||||||
|
Created: Creado
|
||||||
|
Employee: Empleado
|
Loading…
Reference in New Issue