version 1
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:
parent
0793588ef3
commit
0561f19313
|
@ -0,0 +1,12 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
checkRole = async function(ctx, id) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const dms = await Self.findById(id);
|
||||||
|
|
||||||
|
const hasReadRole = await models.DmsType.hasReadRole(ctx, dms.dmsTypeFk);
|
||||||
|
if (!hasReadRole)
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
|
@ -1,4 +1,6 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
const checkRole = require('./checkRole');
|
||||||
|
const getfile = require('./getfile');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('downloadFile', {
|
Self.remoteMethodCtx('downloadFile', {
|
||||||
|
@ -34,29 +36,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.downloadFile = async function(ctx, id) {
|
Self.downloadFile = async function(ctx, id) {
|
||||||
const storageConnector = Self.app.dataSources.storage.connector;
|
await checkRole(ctx, id);
|
||||||
const models = Self.app.models;
|
return await getfile(ctx, id);
|
||||||
const dms = await Self.findById(id);
|
|
||||||
|
|
||||||
const hasReadRole = await models.DmsType.hasReadRole(ctx, dms.dmsTypeFk);
|
|
||||||
if (!hasReadRole)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
const pathHash = storageConnector.getPathHash(dms.id);
|
|
||||||
try {
|
|
||||||
await models.Container.getFile(pathHash, dms.file);
|
|
||||||
} catch (e) {
|
|
||||||
if (e.code != 'ENOENT')
|
|
||||||
throw e;
|
|
||||||
|
|
||||||
const error = new UserError(`File doesn't exists`);
|
|
||||||
error.statusCode = 404;
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stream = models.Container.downloadStream(pathHash, dms.file);
|
|
||||||
|
|
||||||
return [stream, dms.contentType, `filename="${dms.file}"`];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
getFile = async function(ctx, id) {
|
||||||
|
const storageConnector = Self.app.dataSources.storage.connector;
|
||||||
|
const models = Self.app.models;
|
||||||
|
const dms = await Self.findById(id);
|
||||||
|
|
||||||
|
const hasReadRole = await models.DmsType.hasReadRole(ctx, dms.dmsTypeFk);
|
||||||
|
if (!hasReadRole)
|
||||||
|
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
const pathHash = storageConnector.getPathHash(dms.id);
|
||||||
|
try {
|
||||||
|
await models.Container.getFile(pathHash, dms.file);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code != 'ENOENT')
|
||||||
|
throw e;
|
||||||
|
|
||||||
|
const error = new UserError(`File doesn't exists`);
|
||||||
|
error.statusCode = 404;
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = models.Container.downloadStream(pathHash, dms.file);
|
||||||
|
|
||||||
|
return [stream, dms.contentType, `filename="${dms.file}"`];
|
||||||
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('dms downloadFile()', () => {
|
fdescribe('dms downloadFile()', () => {
|
||||||
let dmsId = 1;
|
let dmsId = 1;
|
||||||
|
|
||||||
it('should return a response for an employee with text content-type', async() => {
|
it('should return a response for an employee with text content-type', async() => {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE `vn`.`workerDocument`
|
||||||
|
ADD COLUMN `isReadableByWorker` TINYINT(1) NOT NULL DEFAULT 0 AFTER `document`;
|
||||||
|
|
||||||
|
UPDATE `vn`.`workerDocument` SET `isReadableByWorker` = '1' WHERE (`id` = '1');
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/worker-dms/removeFile')(Self);
|
require('../methods/worker-dms/removeFile')(Self);
|
||||||
require('../methods/worker-dms/allowedContentTypes')(Self);
|
require('../methods/worker-dms/allowedContentTypes')(Self);
|
||||||
|
// require('../methods/worker-dms/filter')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"columnName": "worker"
|
"columnName": "worker"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"isReadableByWorker": {
|
||||||
|
"type": "Boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="WorkerDms"
|
url="filter"
|
||||||
link="{workerFk: $ctrl.$params.id}"
|
link="{workerFk: $ctrl.$params.id}"
|
||||||
filter="::$ctrl.filter"
|
filter="::$ctrl.filter"
|
||||||
limit="20"
|
limit="20"
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
"url": "/index",
|
"url": "/index",
|
||||||
"state": "worker.card.dms.index",
|
"state": "worker.card.dms.index",
|
||||||
"component": "vn-worker-dms-index",
|
"component": "vn-worker-dms-index",
|
||||||
"description": "File management",
|
"description": "My documentation",
|
||||||
"acl": ["hr"]
|
"acl": ["hr"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Fiscal Identifier"
|
label="Fiscal identifier"
|
||||||
ng-model="filter.fi">
|
ng-model="filter.fi">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
Loading…
Reference in New Issue