4108-mdb_backend #987
|
@ -2585,4 +2585,10 @@ INSERT INTO `vn`.`mdbBranch` (`name`)
|
||||||
INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
|
INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
|
||||||
VALUES
|
VALUES
|
||||||
('tpv', 'test', '1'),
|
('tpv', 'test', '1'),
|
||||||
('lab', 'master', '2');
|
('lab', 'master', '1'),
|
||||||
|
('enc', 'test', '1'),
|
||||||
|
('ent', 'master', '1'),
|
||||||
|
('com', 'test', '1'),
|
||||||
|
('eti', 'master', '1'),
|
||||||
|
('ser', 'test', '1'),
|
||||||
|
('lib', 'master', '1');
|
|
@ -99,24 +99,14 @@
|
||||||
"video/mp4"
|
"video/mp4"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mdbStorage": {
|
"accessStorage": {
|
||||||
"name": "mdbStorage",
|
"name": "accessStorage",
|
||||||
"connector": "loopback-component-storage",
|
"connector": "loopback-component-storage",
|
||||||
"provider": "filesystem",
|
"provider": "filesystem",
|
||||||
"root": "./storage/mdb",
|
"root": "./storage/access/branches",
|
||||||
"maxFileSize": "262144000",
|
"maxFileSize": "2621440000",
|
||||||
"allowedContentTypes": [
|
"allowedContentTypes": [
|
||||||
"application/x-7z-compressed",
|
"application/x-7z-compressed"
|
||||||
"application/x-zip-compressed",
|
|
||||||
"application/x-rar-compressed",
|
|
||||||
"application/octet-stream",
|
|
||||||
"application/pdf",
|
|
||||||
"application/zip",
|
|
||||||
"application/rar",
|
|
||||||
"multipart/x-zip",
|
|
||||||
"image/png",
|
|
||||||
"image/jpeg",
|
|
||||||
"image/jpg"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -71,7 +71,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
const query = `claims/${this.claim.id}/uploadFile`;
|
const query = `mdbVersions/upload`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('tag filterValue()', () => {
|
|
||||||
const colorTagId = 1;
|
|
||||||
it('should return a list of color values', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const filter = {limit: 5};
|
|
||||||
const result = await models.Tag.filterValue(colorTagId, filter, options);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(5);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the values matching color "Blue"', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const filter = {where: {value: 'Blue'}, limit: 5};
|
|
||||||
const result = await models.Tag.filterValue(colorTagId, filter, options);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
|
||||||
expect(result[0].value).toEqual('Blue');
|
|
||||||
expect(result[1].value).toEqual('Blue/Silver');
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the values matching color "Blue/Silver"', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const filter = {where: {value: 'Blue/Silver'}, limit: 5};
|
|
||||||
const result = await models.Tag.filterValue(colorTagId, filter, options);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
|
||||||
expect(result[0].value).toEqual('Blue/Silver');
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the values matching color "Silver"', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const filter = {where: {value: 'Silver'}, limit: 5};
|
|
||||||
const result = await models.Tag.filterValue(colorTagId, filter, options);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
|
||||||
expect(result[0].value).toEqual('Silver');
|
|
||||||
expect(result[1].value).toEqual('Blue/Silver');
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
fdescribe('Mdb upload()', () => {
|
||||||
|
it(`should return an error for a user without enough privileges`, async() => {
|
||||||
|
const tx = await models.MdbVersion.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const currentUserId = 1101;
|
||||||
|
const appName = 'tpv';
|
||||||
|
const newVersion = '123';
|
||||||
|
const branch = 'test';
|
||||||
|
const ctx = {req: {accessToken: {userId: currentUserId}}};
|
||||||
|
|
||||||
|
await models.MdbVersion.upload(ctx, appName, newVersion, branch, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`You don't have enough privileges`);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,3 +1,6 @@
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('upload', {
|
Self.remoteMethodCtx('upload', {
|
||||||
description: 'Returns a list of tag values',
|
description: 'Returns a list of tag values',
|
||||||
|
@ -34,17 +37,48 @@ module.exports = Self => {
|
||||||
Self.upload = async(ctx, appName, newVersion, branch, options) => {
|
Self.upload = async(ctx, appName, newVersion, branch, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
console.log(ctx);
|
||||||
|
|
||||||
const moduleFile = ctx.req;
|
const TempContainer = models.TempContainer;
|
||||||
if (!moduleFile) return;
|
const AccessContainer = models.AccessContainer;
|
||||||
|
const fileOptions = {};
|
||||||
|
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const newMdb = await models.mdbVersion.create({
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tempContainer = await TempContainer.container('access');
|
||||||
|
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
||||||
|
const files = Object.values(uploaded.files).map(file => {
|
||||||
|
return file[0];
|
||||||
|
});
|
||||||
|
const uploadedFile = files[0];
|
||||||
|
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
||||||
|
const srcFile = path.join(file.client.root, file.container, file.name);
|
||||||
|
const accessContainer = await AccessContainer.container(branch);
|
||||||
|
const destinationFile = path.join(accessContainer.client.root, branch, `${appName}${newVersion}.7z`);
|
||||||
|
|
||||||
|
await fs.move(srcFile, destinationFile, {
|
||||||
|
overwrite: true
|
||||||
|
});
|
||||||
|
|
||||||
|
await models.MdbVersion.create({
|
||||||
app: appName,
|
app: appName,
|
||||||
version: newVersion,
|
version: newVersion,
|
||||||
branchFk: branch
|
branchFk: branch
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"MdbVersion": {
|
"MdbVersion": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"MdbContainer": {
|
"AccessContainer": {
|
||||||
"dataSource": "mdbStorage"
|
"dataSource": "accessStorage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "MdbContainer",
|
"name": "AccessContainer",
|
||||||
"base": "Container",
|
"base": "Container",
|
||||||
"acls": [{
|
"acls": [{
|
||||||
"accessType": "*",
|
"accessType": "*",
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
"branch": {
|
"branch": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "MdbBranch",
|
"model": "MdbBranch",
|
||||||
"foreignKey": "name"
|
"foreignKey": "branchFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue