From 3b08fb63c7578748ac4331ee10a99478b849e9e3 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 23 Jul 2020 14:55:41 +0200 Subject: [PATCH 1/5] /authorized returns level, added device to spectrum measurement --- .nvmrc | 1 + api/root.yaml | 3 +++ build.bat | 2 ++ data_import/import.js | 11 ++++---- package.json | 2 +- src/routes/measurement.spec.ts | 14 +++++----- src/routes/root.spec.ts | 6 ++--- src/routes/root.ts | 2 +- src/routes/sample.spec.ts | 2 +- src/routes/sample.ts | 49 +++++++++++++++++++++------------- src/routes/template.spec.ts | 16 ++++++----- src/routes/validate/sample.ts | 3 +-- src/test/db.json | 10 +++++-- 13 files changed, 74 insertions(+), 47 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..339dacb --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +12.17 \ No newline at end of file diff --git a/api/root.yaml b/api/root.yaml index 3070412..af618a7 100644 --- a/api/root.yaml +++ b/api/root.yaml @@ -37,6 +37,9 @@ method: type: string example: 'basic' + level: + type: string + example: read 401: $ref: 'api.yaml#/components/responses/401' 500: diff --git a/build.bat b/build.bat index d632b14..3112adb 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,6 @@ call npm run tsc-full copy package.json dist\package.json +copy package-lock.json dist\package-lock.json +copy .nvmrc dist\.nvmrc Xcopy /E /I api dist\api Xcopy /E /I static dist\static \ No newline at end of file diff --git a/data_import/import.js b/data_import/import.js index 8fac949..24a0292 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -30,8 +30,8 @@ const docs = [ const errors = []; const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200717\\nmDocs'; // NormMaster Documents const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200717\\DPT'; // Spectrum files -const host = 'http://localhost:3000'; -// const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; +// const host = 'http://localhost:3000'; +const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; const requiredProperties = ['samplenumber','materialnumber','materialname','supplier','reinforcementmaterial','material','granulate/part','color','charge/batch','comments']; dict = { // dictionary 'Granulat': 'granulate', @@ -194,7 +194,8 @@ async function allDpts() { password: 'Abc123!#' } }); - const measurement_template = res.data.find(e => e.name === 'spectrum')._id; + const measurement_templates = res.data.filter(e => e.name === 'spectrum'); + const measurement_template = measurement_templates[measurement_templates.length - 1]._id; res = await axios({ method: 'get', url: host + '/samples?status=all', @@ -207,7 +208,7 @@ async function allDpts() { res.data.forEach(sample => { sampleIds[sample.number] = sample._id; }); - const dptRegex = /(.*?)_(.*?)_(\d+|\d+_\d+).DPT/; + const dptRegex = /(.*?)_(.*?)_(\d+|\w+_\d+).DPT/; const dpts = fs.readdirSync(dptFiles); for (let i in dpts) { const regexRes = dptRegex.exec(dpts[i]) @@ -314,7 +315,7 @@ async function allKfVz() { errors.push(`KF/VZ upload for ${JSON.stringify(sample)} failed: ${JSON.stringify(err.response.data)}`); }); } - if (sample['VZ (ml/g)']) { + if (sample['vz(ml/g)']) { await axios({ method: 'post', url: host + '/measurement/new', diff --git a/package.json b/package.json index f9494d3..ae69e4f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "tsc": "tsc", "tsc-full": "del /q dist\\* & (for /d %x in (dist\\*) do @rd /s /q \"%x\") & tsc", "build": "build.bat", - "build-push": "build.bat && cf push", + "build-push": "build.bat && timeout 3 && cf push", "test": "mocha dist/**/**.spec.js", "start": "node index.js", "dev": "nodemon -e ts,yaml --exec \"tsc && node dist/index.js || exit 1\"", diff --git a/src/routes/measurement.spec.ts b/src/routes/measurement.spec.ts index d33bfdc..180f3ce 100644 --- a/src/routes/measurement.spec.ts +++ b/src/routes/measurement.spec.ts @@ -18,7 +18,7 @@ describe('/measurement', () => { url: '/measurement/800000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]}, measurement_template: '300000000000000000000001'} + res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'} }); }); it('returns the measurement for an API key', done => { @@ -27,7 +27,7 @@ describe('/measurement', () => { url: '/measurement/800000000000000000000001', auth: {key: 'janedoe'}, httpStatus: 200, - res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]}, measurement_template: '300000000000000000000001'} + res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'} }); }); it('returns deleted measurements for a maintain/admin user', done => { @@ -80,7 +80,7 @@ describe('/measurement', () => { auth: {basic: 'janedoe'}, httpStatus: 200, req: {}, - res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]}, measurement_template: '300000000000000000000001'} + res: {_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'} }); }); it('keeps unchanged values', done => { @@ -89,10 +89,10 @@ describe('/measurement', () => { url: '/measurement/800000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - req: {values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]}} + req: {values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]}, measurement_template: '300000000000000000000001'}); + should(res.body).be.eql({_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'}); MeasurementModel.findById('800000000000000000000001').lean().exec((err, data: any) => { if (err) return done(err); should(data).have.property('status',globals.status.validated); @@ -126,7 +126,7 @@ describe('/measurement', () => { req: {values: {dpt: [[1,2],[3,4],[5,6]]}} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[1,2],[3,4],[5,6]]}, measurement_template: '300000000000000000000001'}); + should(res.body).be.eql({_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[1,2],[3,4],[5,6]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'}); MeasurementModel.findById('800000000000000000000001').lean().exec((err, data: any) => { should(data).have.only.keys('_id', 'sample_id', 'values', 'measurement_template', 'status', '__v'); should(data.sample_id.toString()).be.eql('400000000000000000000001'); @@ -144,7 +144,7 @@ describe('/measurement', () => { url: '/measurement/800000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - req: {values: {dpt: [[1,2],[3,4],[5,6]]}}, + req: {values: {dpt: [[1,2],[3,4],[5,6]], device: 'Alpha I'}}, log: { collection: 'measurements', dataAdd: { diff --git a/src/routes/root.spec.ts b/src/routes/root.spec.ts index 68531a5..b84d0c2 100644 --- a/src/routes/root.spec.ts +++ b/src/routes/root.spec.ts @@ -179,7 +179,7 @@ describe('/', () => { url: '/authorized', auth: {key: 'admin'}, httpStatus: 200, - res: {status: 'Authorization successful', method: 'key'} + res: {status: 'Authorization successful', method: 'key', level: 'admin'} }); }); it('works with basic auth', done => { @@ -188,7 +188,7 @@ describe('/', () => { url: '/authorized', auth: {basic: 'admin'}, httpStatus: 200, - res: {status: 'Authorization successful', method: 'basic'} + res: {status: 'Authorization successful', method: 'basic', level: 'admin'} }); }); }); @@ -242,7 +242,7 @@ describe('The /api/{url} redirect', () => { url: '/api/authorized', auth: {basic: 'admin'}, httpStatus: 200, - res: {status: 'Authorization successful', method: 'basic'} + res: {status: 'Authorization successful', method: 'basic', level: 'admin'} }); }); it('is disabled in production', done => { diff --git a/src/routes/root.ts b/src/routes/root.ts index 1547844..20f10b9 100644 --- a/src/routes/root.ts +++ b/src/routes/root.ts @@ -14,7 +14,7 @@ router.get('/', (req, res) => { router.get('/authorized', (req, res) => { if (!req.auth(res, globals.levels)) return; - res.json({status: 'Authorization successful', method: req.authDetails.method}); + res.json({status: 'Authorization successful', method: req.authDetails.method, level: req.authDetails.level}); }); // TODO: evaluate exact changelog functionality (restoring, delting after time, etc.) diff --git a/src/routes/sample.spec.ts b/src/routes/sample.spec.ts index ca62d16..d9db97a 100644 --- a/src/routes/sample.spec.ts +++ b/src/routes/sample.spec.ts @@ -266,7 +266,7 @@ describe('/sample', () => { httpStatus: 200 }).end((err, res) => { if (err) return done(err); - should(res.body).have.lengthOf(2); + should(res.body.filter(e => e.spectrum.dpt)).have.lengthOf(2); should(res.body[0].spectrum).have.property('dpt', [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]); should(res.body[1].spectrum).have.property('dpt', [[3996.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]); done(); diff --git a/src/routes/sample.ts b/src/routes/sample.ts index e468a41..10694ac 100644 --- a/src/routes/sample.ts +++ b/src/routes/sample.ts @@ -22,12 +22,11 @@ import csv from '../helpers/csv'; const router = express.Router(); // TODO: check added filter -// TODO: use query pointer // TODO: convert filter value to number according to table model // TODO: validation for filter parameters // TODO: location/device sort/filter -// TODO: think about material numbers +// TODO: think about filter keys with measurement template versions router.get('/samples', async (req, res, next) => { if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'all')) return; @@ -104,9 +103,9 @@ router.get('/samples', async (req, res, next) => { if (filters.sort[0].indexOf('measurements.') >= 0) { // sorting with measurements as starting collection collection = MeasurementModel; const [,measurementName, measurementParam] = filters.sort[0].split('.'); - const measurementTemplate = await MeasurementTemplateModel.findOne({name: measurementName}).lean().exec().catch(err => {next(err);}); - if (measurementTemplate instanceof Error) return; - if (!measurementTemplate) { + const measurementTemplates = await MeasurementTemplateModel.find({name: measurementName}).lean().exec().catch(err => {next(err);}); + if (measurementTemplates instanceof Error) return; + if (!measurementTemplates) { return res.status(400).json({status: 'Invalid body format', details: filters.sort[0] + ' not found'}); } let sortStartValue = null; @@ -118,7 +117,7 @@ router.get('/samples', async (req, res, next) => { } sortStartValue = fromSample.values[measurementParam]; } - queryPtr[0].$match.$and.push({measurement_template: mongoose.Types.ObjectId(measurementTemplate._id)}); // find measurements to sort + queryPtr[0].$match.$and.push({measurement_template: {$in: measurementTemplates.map(e => e._id)}}); // find measurements to sort if (filters.filters.find(e => e.field === filters.sort[0])) { // sorted measurement should also be filtered queryPtr[0].$match.$and.push(...filterQueries(filters.filters.filter(e => e.field === filters.sort[0]).map(e => {e.field = 'values.' + e.field.split('.')[2]; return e; }))); } @@ -194,7 +193,16 @@ router.get('/samples', async (req, res, next) => { if (!fromSample) { return res.status(400).json({status: 'Invalid body format', details: 'from-id not found'}); } - sortStartValue = fromSample[filters.sort[0]]; + console.log(fromSample); + console.log(filters.sort[0]); + console.log(fromSample[filters.sort[0]]); + const filterKey = filters.sort[0].split('.'); + if (filterKey.length === 2) { + sortStartValue = fromSample[0][filterKey[0]][filterKey[1]]; + } + else { + sortStartValue = fromSample[0][filterKey[0]]; + } } queryPtr.push(...sortQuery(filters, [filters.sort[0], '_id'], sortStartValue)); } @@ -290,19 +298,22 @@ router.get('/samples', async (req, res, next) => { as: 'measurements' }}); } - measurementTemplates.filter(e => e.name !== 'spectrum').forEach(template => { // TODO: hard coded dpt for special treatment, change later + measurementTemplates.forEach(template => { // TODO: hard coded dpt for special treatment, change later queryPtr.push({$addFields: {[template.name]: {$let: { // add measurements as property [template.name], if one result, array is reduced to direct values vars: {arr: {$filter: {input: '$measurements', cond: {$eq: ['$$this.measurement_template', mongoose.Types.ObjectId(template._id)]}}}}, in:{$cond: [{$lte: [{$size: '$$arr'}, 1]}, {$arrayElemAt: ['$$arr', 0]}, '$$arr']} }}}}, {$addFields: {[template.name]: {$cond: ['$' + template.name + '.values', '$' + template.name + '.values', template.parameters.reduce((s, e) => {s[e.name] = null; return s;}, {})]}}}); + if (measurementFieldsFields.find(e => e === 'spectrum')) { + queryPtr.push({$unwind: '$spectrum'}); + } }); - if (measurementFieldsFields.find(e => e === 'spectrum')) { // TODO: remove hardcoded as well - queryPtr.push( - {$addFields: {spectrum: {$filter: {input: '$measurements', cond: {$eq: ['$$this.measurement_template', measurementTemplates.filter(e => e.name === 'spectrum')[0]._id]}}}}}, - {$addFields: {spectrum: '$spectrum.values'}}, - {$unwind: '$spectrum'} - ); - } + // if (measurementFieldsFields.find(e => e === 'spectrum')) { // TODO: remove hardcoded as well + // queryPtr.push( + // {$addFields: {spectrum: {$filter: {input: '$measurements', cond: {$eq: ['$$this.measurement_template', measurementTemplates.filter(e => e.name === 'spectrum')[0]._id]}}}}}, + // {$addFields: {spectrum: '$spectrum.values'}}, + // {$unwind: '$spectrum'} + // ); + // } // queryPtr.push({$unset: 'measurements'}); queryPtr.push({$project: {measurements: 0}}); } @@ -316,9 +327,8 @@ router.get('/samples', async (req, res, next) => { projection._id = false; } queryPtr.push({$project: projection}); - if (!fieldsToAdd.find(e => /spectrum\./.test(e))) { // use streaming when including spectrum files - collection.aggregate(query).exec((err, data) => { + collection.aggregate(query).allowDiskUse(true).exec((err, data) => { if (err) return next(err); if (data[0] && data[0].count) { res.header('x-total-items', data[0].count.length > 0 ? data[0].count[0].count : 0); @@ -354,7 +364,7 @@ router.get('/samples', async (req, res, next) => { res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'}); res.write('['); let count = 0; - const stream = collection.aggregate(query).cursor().exec(); + const stream = collection.aggregate(query).allowDiskUse(true).cursor().exec(); stream.on('data', data => { if (filters.fields.indexOf('added') >= 0) { // add added date data.added = data._id.getTimestamp(); @@ -364,6 +374,9 @@ router.get('/samples', async (req, res, next) => { } res.write((count === 0 ? '' : ',\n') + JSON.stringify(data)); count ++; }); + stream.on('error', err => { + console.error(err); + }); stream.on('close', () => { res.write(']'); res.end(); diff --git a/src/routes/template.spec.ts b/src/routes/template.spec.ts index b07014b..bf932cf 100644 --- a/src/routes/template.spec.ts +++ b/src/routes/template.spec.ts @@ -517,7 +517,7 @@ describe('/template', () => { url: '/template/measurement/300000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} }); }); it('rejects an API key', done => { @@ -553,7 +553,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} }); }); it('keeps unchanged properties', done => { @@ -562,8 +562,8 @@ describe('/template', () => { url: '/template/measurement/300000000000000000000001', auth: {basic: 'admin'}, httpStatus: 200, - req: {name: 'spectrum', parameters: [{name: 'dpt', range: { type: 'array'}}]}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}]} + req: {name: 'spectrum', parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]}, + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} }); }); it('keeps only one unchanged property', done => { @@ -573,7 +573,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {name: 'spectrum'}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} }); }); it('changes the given properties', done => { @@ -626,17 +626,19 @@ describe('/template', () => { req: {name: 'IR spectrum'}, }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'dpt', range: {type: 'array'}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]}); TemplateMeasurementModel.findById(res.body._id).lean().exec((err, data:any) => { if (err) return done(err); should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v'); should(data.first_id.toString()).be.eql('300000000000000000000001'); should(data).have.property('name', 'IR spectrum'); should(data).have.property('version', 2); - should(data).have.property('parameters').have.lengthOf(1); + should(data).have.property('parameters').have.lengthOf(2); should(data.parameters[0]).have.property('name', 'dpt'); should(data.parameters[0]).have.property('range'); should(data.parameters[0].range).have.property('type', 'array'); + should(data.parameters[1]).have.property('name', 'device'); + should(data.parameters[1]).have.property('range'); done(); }); }); diff --git a/src/routes/validate/sample.ts b/src/routes/validate/sample.ts index 3e9aed3..19f6b50 100644 --- a/src/routes/validate/sample.ts +++ b/src/routes/validate/sample.ts @@ -62,9 +62,8 @@ export default class SampleValidate { 'material.name', 'material.supplier', 'material.group', - 'material.number', 'material.properties.*', - 'measurements.(?!spectrum)*' + 'measurements.(?!spectrum\.dpt)*' ]; private static fieldKeys = [ diff --git a/src/test/db.json b/src/test/db.json index 7b0fab9..7930a94 100644 --- a/src/test/db.json +++ b/src/test/db.json @@ -403,7 +403,8 @@ [3997.12558,98.00555], [3995.08519,98.03253], [3993.04480,98.02657] - ] + ], + "device": "Alpha I" }, "status": 10, "measurement_template": {"$oid":"300000000000000000000001"}, @@ -470,7 +471,8 @@ [3996.12558,98.00555], [3995.08519,98.03253], [3993.04480,98.02657] - ] + ], + "device": "Alpha II" }, "status": 10, "measurement_template": {"$oid":"300000000000000000000001"}, @@ -551,6 +553,10 @@ "range": { "type": "array" } + }, + { + "name": "device", + "range": {} } ], "__v": 0 From a8e8b28c1147091133b7af3b0663cac239cf9c44 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 23 Jul 2020 15:25:45 +0200 Subject: [PATCH 2/5] added first_id for template response --- api/schemas.yaml | 4 +++ src/routes/template.spec.ts | 52 ++++++++++++++++++--------------- src/routes/validate/template.ts | 1 + 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/api/schemas.yaml b/api/schemas.yaml index 1c844bb..2ac14ce 100644 --- a/api/schemas.yaml +++ b/api/schemas.yaml @@ -158,6 +158,10 @@ Template: type: number readOnly: true example: 1 + first_id: + readOnly: true + type: string + example: 5ea0450ed851c30a90e70894 parameters: type: array items: diff --git a/src/routes/template.spec.ts b/src/routes/template.spec.ts index bf932cf..db924b3 100644 --- a/src/routes/template.spec.ts +++ b/src/routes/template.spec.ts @@ -25,10 +25,11 @@ describe('/template', () => { const json = require('../test/db.json'); should(res.body).have.lengthOf(json.collections.condition_templates.length); should(res.body).matchEach(condition => { - should(condition).have.only.keys('_id', 'name', 'version', 'parameters'); + should(condition).have.only.keys('_id', 'name', 'version', 'first_id', 'parameters'); should(condition).have.property('_id').be.type('string'); should(condition).have.property('name').be.type('string'); should(condition).have.property('version').be.type('number'); + should(condition).have.property('first_id').be.type('string'); should(condition.parameters).matchEach(number => { should(number).have.only.keys('name', 'range'); should(number).have.property('name').be.type('string'); @@ -62,7 +63,7 @@ describe('/template', () => { url: '/template/condition/200000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} + res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, first_id: '200000000000000000000001', parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} }); }); it('rejects an API key', done => { @@ -98,7 +99,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {}, - res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} + res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, first_id: '200000000000000000000001', parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} }); }); it('keeps unchanged properties', done => { @@ -108,7 +109,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {name: 'heat treatment', parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]}, - res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} + res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, first_id: '200000000000000000000001', parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} }); }); it('keeps only one unchanged property', done => { @@ -118,7 +119,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {name: 'heat treatment'}, - res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} + res: {_id: '200000000000000000000001', name: 'heat treatment', version: 1, first_id: '200000000000000000000001', parameters: [{name: 'material', range: {values: ['copper', 'hot air']}}, {name: 'weeks', range: {min: 1, max: 10}}]} }); }); it('changes the given properties', done => { @@ -136,6 +137,7 @@ describe('/template', () => { should(data.first_id.toString()).be.eql('200000000000000000000001'); should(data).have.property('name', 'heat aging'); should(data).have.property('version', 2); + should(data.first_id.toString()).be.eql('200000000000000000000001'); should(data).have.property('parameters').have.lengthOf(1); should(data.parameters[0]).have.property('name', 'time'); should(data.parameters[0]).have.property('range'); @@ -191,7 +193,7 @@ describe('/template', () => { req: {parameters: [{name: 'time', range: {values: [1, 2, 5]}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, parameters: [{name: 'time', range: {values: [1, 2, 5]}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, first_id: '200000000000000000000001', parameters: [{name: 'time', range: {values: [1, 2, 5]}}]}); done(); }); }); @@ -204,7 +206,7 @@ describe('/template', () => { req: {parameters: [{name: 'time', range: {min: 1, max: 11}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, parameters: [{name: 'time', range: {min: 1, max: 11}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, first_id: '200000000000000000000001', parameters: [{name: 'time', range: {min: 1, max: 11}}]}); done(); }); }); @@ -217,7 +219,7 @@ describe('/template', () => { req: {parameters: [{name: 'time', range: {type: 'array'}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, parameters: [{name: 'time', range: {type: 'array'}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, first_id: '200000000000000000000001', parameters: [{name: 'time', range: {type: 'array'}}]}); done(); }); }); @@ -230,7 +232,7 @@ describe('/template', () => { req: {parameters: [{name: 'time', range: {}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, parameters: [{name: 'time', range: {}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'heat treatment', version: 2, first_id: '200000000000000000000001', parameters: [{name: 'time', range: {}}]}); done(); }); }); @@ -310,9 +312,10 @@ describe('/template', () => { req: {name: 'heat treatment3', parameters: [{name: 'material', range: {values: ['copper']}}]} }).end((err, res) => { if (err) return done(err); - should(res.body).have.only.keys('_id', 'name', 'version', 'parameters'); + should(res.body).have.only.keys('_id', 'name', 'version', 'first_id', 'parameters'); should(res.body).have.property('name', 'heat treatment3'); should(res.body).have.property('version', 1); + should(res.body._id).be.eql(res.body.first_id); should(res.body).have.property('parameters').have.lengthOf(1); should(res.body.parameters[0]).have.property('name', 'material'); should(res.body.parameters[0]).have.property('range'); @@ -336,6 +339,7 @@ describe('/template', () => { should(data.first_id.toString()).be.eql(data._id.toString()); should(data).have.property('name', 'heat aging'); should(data).have.property('version', 1); + should(res.body._id).be.eql(res.body.first_id); should(data).have.property('parameters').have.lengthOf(1); should(data.parameters[0]).have.property('name', 'time'); should(data.parameters[0]).have.property('range'); @@ -480,8 +484,9 @@ describe('/template', () => { const json = require('../test/db.json'); should(res.body).have.lengthOf(json.collections.measurement_templates.length); should(res.body).matchEach(measurement => { - should(measurement).have.only.keys('_id', 'name', 'version', 'parameters'); + should(measurement).have.only.keys('_id', 'name', 'version', 'first_id', 'parameters'); should(measurement).have.property('_id').be.type('string'); + should(measurement).have.property('first_id').be.type('string'); should(measurement).have.property('name').be.type('string'); should(measurement).have.property('version').be.type('number'); should(measurement.parameters).matchEach(number => { @@ -517,7 +522,7 @@ describe('/template', () => { url: '/template/measurement/300000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} }); }); it('rejects an API key', done => { @@ -553,7 +558,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]} }); }); it('keeps unchanged properties', done => { @@ -563,7 +568,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {name: 'spectrum', parameters: [{name: 'dpt', range: { type: 'array'}}, {name: 'device', range: {}}]}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} }); }); it('keeps only one unchanged property', done => { @@ -573,7 +578,7 @@ describe('/template', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {name: 'spectrum'}, - res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} + res: {_id: '300000000000000000000001', name: 'spectrum', version: 1, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]} }); }); it('changes the given properties', done => { @@ -585,7 +590,7 @@ describe('/template', () => { req: {name: 'IR spectrum', parameters: [{name: 'data point table', range: {min: 0, max: 1000}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'data point table', range: {min: 0, max: 1000}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, first_id: '300000000000000000000001', parameters: [{name: 'data point table', range: {min: 0, max: 1000}}]}); TemplateMeasurementModel.findById(res.body._id).lean().exec((err, data:any) => { if (err) return done(err); should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v'); @@ -626,7 +631,7 @@ describe('/template', () => { req: {name: 'IR spectrum'}, }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: {type: 'array'}}, {name: 'device', range: {}}]}); TemplateMeasurementModel.findById(res.body._id).lean().exec((err, data:any) => { if (err) return done(err); should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v'); @@ -652,7 +657,7 @@ describe('/template', () => { req: {parameters: [{name: 'dpt', range: {values: [1, 2, 5]}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, parameters: [{name: 'dpt', range: {values: [1, 2, 5]}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: {values: [1, 2, 5]}}]}); done(); }); }); @@ -665,7 +670,7 @@ describe('/template', () => { req: {parameters: [{name: 'dpt', range: {min: 0, max: 1000}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, parameters: [{name: 'dpt', range: {min: 0, max: 1000}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, first_id: '300000000000000000000001', parameters: [{name: 'dpt', range: {min: 0, max: 1000}}]}); done(); }); }); @@ -678,7 +683,7 @@ describe('/template', () => { req: {parameters: [{name: 'dpt2', range: {type: 'array'}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, parameters: [{name: 'dpt2', range: {type: 'array'}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'spectrum', version: 2, first_id: '300000000000000000000001', parameters: [{name: 'dpt2', range: {type: 'array'}}]}); done(); }); }); @@ -691,7 +696,7 @@ describe('/template', () => { req: {parameters: [{name: 'weight %', range: {}}]} }).end((err, res) => { if (err) return done(err); - should(_.omit(res.body, '_id')).be.eql({name: 'kf', version: 2, parameters: [{name: 'weight %', range: {}}]}); + should(_.omit(res.body, '_id')).be.eql({name: 'kf', version: 2, first_id: '300000000000000000000002', parameters: [{name: 'weight %', range: {}}]}); done(); }); }); @@ -761,9 +766,10 @@ describe('/template', () => { req: {name: 'vz', parameters: [{name: 'vz', range: {min: 1}}]} }).end((err, res) => { if (err) return done(err); - should(res.body).have.only.keys('_id', 'name', 'version', 'parameters'); + should(res.body).have.only.keys('_id', 'name', 'version', 'first_id', 'parameters'); should(res.body).have.property('name', 'vz'); should(res.body).have.property('version', 1); + should(res.body._id).be.eql(res.body.first_id); should(res.body).have.property('parameters').have.lengthOf(1); should(res.body.parameters[0]).have.property('name', 'vz'); should(res.body.parameters[0]).have.property('range'); @@ -911,7 +917,7 @@ describe('/template', () => { const json = require('../test/db.json'); should(res.body).have.lengthOf(json.collections.material_templates.length); should(res.body).matchEach(measurement => { - should(measurement).have.only.keys('_id', 'name', 'version', 'parameters'); + should(measurement).have.only.keys('_id', 'name', 'version', 'first_id', 'parameters'); should(measurement).have.property('_id').be.type('string'); should(measurement).have.property('name').be.type('string'); should(measurement).have.property('version').be.type('number'); diff --git a/src/routes/validate/template.ts b/src/routes/validate/template.ts index 0721bd7..aed8f68 100644 --- a/src/routes/validate/template.ts +++ b/src/routes/validate/template.ts @@ -65,6 +65,7 @@ export default class TemplateValidate { _id: IdValidate.get(), name: this.template.name, version: this.template.version, + first_id: IdValidate.get(), parameters: this.template.parameters }).validate(data, {stripUnknown: true}); return error !== undefined? null : value; From 1988a67b359e10e4746719ea1f07861e35f4b9b0 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Tue, 28 Jul 2020 10:30:10 +0200 Subject: [PATCH 3/5] modified api.ts to directly incorporate swagger-ui-express code --- data_import/import.js | 4 +- package-lock.json | 14 +- package.json | 2 +- src/api.ts | 155 +++++++++++++---- src/index.ts | 36 +++- src/routes/template.ts | 9 +- static/img/favicon.ico | Bin 0 -> 1150 bytes static/styles/swagger-ui.css | 323 +++++++++++++++++++++++++++++++++++ static/styles/swagger.css | 323 ----------------------------------- 9 files changed, 489 insertions(+), 377 deletions(-) create mode 100644 static/img/favicon.ico create mode 100644 static/styles/swagger-ui.css delete mode 100644 static/styles/swagger.css diff --git a/data_import/import.js b/data_import/import.js index 24a0292..aa84bf3 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -30,8 +30,8 @@ const docs = [ const errors = []; const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200717\\nmDocs'; // NormMaster Documents const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200717\\DPT'; // Spectrum files -// const host = 'http://localhost:3000'; -const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; +const host = 'http://localhost:3000'; +// const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; const requiredProperties = ['samplenumber','materialnumber','materialname','supplier','reinforcementmaterial','material','granulate/part','color','charge/batch','comments']; dict = { // dictionary 'Granulat': 'granulate', diff --git a/package-lock.json b/package-lock.json index 34fb53e..6749f0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3773,17 +3773,9 @@ } }, "swagger-ui-dist": { - "version": "3.24.3", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.24.3.tgz", - "integrity": "sha512-kB8qobP42Xazaym7sD9g5mZuRL4416VIIYZMqPEIskkzKqbPLQGEiHA3ga31bdzyzFLgr6Z797+6X1Am6zYpbg==" - }, - "swagger-ui-express": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.1.2.tgz", - "integrity": "sha512-bVT16qj6WdNlEKFkSLOoTeGuqEm2lfOFRq6mVHAx+viA/ikORE+n4CS3WpVcYmQzM4HE6+DUFgAWcMRBJNpjcw==", - "requires": { - "swagger-ui-dist": "^3.18.1" - } + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.30.2.tgz", + "integrity": "sha512-hAu/ig5N8i0trXXbrC7rwbXV4DhpEAsZhYXDs1305OjmDgjGC0thINbb0197idy3Pp+B6w7u426SUM43GAP7qw==" }, "term-size": { "version": "2.2.0", diff --git a/package.json b/package.json index ae69e4f..7bf20ea 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "lodash": "^4.17.15", "mongo-sanitize": "^1.1.0", "mongoose": "^5.8.7", - "swagger-ui-express": "4.1.2" + "swagger-ui-dist": "^3.30.2" }, "devDependencies": { "@types/bcrypt": "^3.0.0", diff --git a/src/api.ts b/src/api.ts index aab7b80..d82a99e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,48 +1,131 @@ -import swagger from 'swagger-ui-express'; +import express from 'express'; +import swaggerUi from 'swagger-ui-dist'; import jsonRefParser, {JSONSchema} from '@apidevtools/json-schema-ref-parser'; import oasParser from '@apidevtools/swagger-parser'; -// modifies the normal swagger-ui-express package +// modified from https://github.com/scottie1984/swagger-ui-express // usage: app.use('/api-doc', api.serve(), api.setup()); // the paths property can be split using allOf // further route documentation can be included in the x-doc property -export default class api { - static serve () { - return swagger.serve; - } - static setup () { - let apiDoc: JSONSchema = {}; - jsonRefParser.bundle('api/api.yaml', (err, doc) => { // parse yaml - if (err) throw err; - apiDoc = doc; - apiDoc.servers.splice(process.env.NODE_ENV === 'production', 1); - apiDoc.paths = apiDoc.paths.allOf.reduce((s, e) => Object.assign(s, e)); // bundle routes - apiDoc = this.resolveXDoc(apiDoc); - oasParser.validate(apiDoc, (err, api) => { // validate oas schema - if (err) { - console.error(err); - } - else { - console.info(process.env.NODE_ENV === 'test' ? '' : 'API ok, version ' + api.info.version); - swagger.setup(apiDoc); - } - }); - }); - return swagger.setup(apiDoc, {customCssUrl: '/static/styles/swagger.css'}) - } - - private static resolveXDoc (doc) { // resolve x-doc properties recursively - Object.keys(doc).forEach(key => { - if (doc[key] !== null && doc[key].hasOwnProperty('x-doc')) { // add x-doc to description, is styled via css - doc[key].description += '
docs' + doc[key]['x-doc'] + '
'; +export default function api () { + // generate apiDoc + let apiDoc: JSONSchema = {}; + jsonRefParser.bundle('api/api.yaml', (err, doc) => { // parse yaml + if (err) throw err; + apiDoc = doc; + apiDoc.servers.splice(process.env.NODE_ENV === 'production', 1); + apiDoc.paths = apiDoc.paths.allOf.reduce((s, e) => Object.assign(s, e)); // bundle routes + apiDoc = resolveXDoc(apiDoc); + oasParser.validate(apiDoc, (err, api) => { // validate oas schema + if (err) { + console.error(err); } - else if (typeof doc[key] === 'object' && doc[key] !== null) { // go deeper into recursion - doc[key] = this.resolveXDoc(doc[key]); + else { + console.info(process.env.NODE_ENV === 'test' ? '' : 'API ok, version ' + api.info.version); } }); - return doc; - } -} \ No newline at end of file + }); + + return [ + (req, res, next) => { // serve init js and apiDoc file + switch (req.url) { + case '/swagger-ui-init.js': + res.set('Content-Type', 'application/javascript'); + res.send(jsTplString); + break; + case '/apidoc.json': + res.set('Content-Type', 'application/json'); + res.send(apiDoc); + break; + default: + next(); + } + }, // serve swagger files + express.static(swaggerUi.getAbsoluteFSPath(), {index: false}), + (req, res) => { // serve html file as default + res.send(htmlTplString); + } + ]; +} + + +function resolveXDoc (doc) { // resolve x-doc properties recursively + Object.keys(doc).forEach(key => { + if (doc[key] !== null && doc[key].hasOwnProperty('x-doc')) { // add x-doc to description, is styled via css + doc[key].description += '
docs' + doc[key]['x-doc'] + '
'; + } + else if (typeof doc[key] === 'object' && doc[key] !== null) { // go deeper into recursion + doc[key] = resolveXDoc(doc[key]); + } + }); + return doc; +} + + +// templates + +const htmlTplString = ` + + + + + API documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +`; + +const jsTplString = ` +window.onload = function() { + // Build a system + window.ui = SwaggerUIBundle({ + url: '/api-doc/apidoc.json', + dom_id: '#swagger-ui', + deepLinking: true, + presets: [ + SwaggerUIBundle.presets.apis, + SwaggerUIStandalonePreset + ], + plugins: [ + SwaggerUIBundle.plugins.DownloadUrl + ], + layout: 'StandaloneLayout' + }); +} +`; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d6ea865..b7b5e2e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,8 +24,38 @@ app.disable('x-powered-by'); // get port from environment, defaults to 3000 const port = process.env.PORT || 3000; -//middleware -app.use(helmet()); +// security headers +app.use(helmet({ + contentSecurityPolicy: { + directives: { + defaultSrc: [`'none'`], + baseUri: [`'self'`], + formAction: [`'none'`], + frameAncestors: [`'none'`] + } + } +})); +// special CSP header for api-doc +app.use('/api-doc', helmet.contentSecurityPolicy({ + directives: { + defaultSrc: [`'none'`], + scriptSrc: [`'self'`], + connectSrc: [`'self'`], + styleSrc: [`'self'`, `'unsafe-inline'`], + imgSrc: [`'self'`, 'data:'], + baseUri: [`'self'`], + formAction: [`'none'`], + frameAncestors: [`'none'`] + } +})); +// special CSP header for the bosch-logo.svg +app.use('/static/img/bosch-logo.svg', helmet.contentSecurityPolicy({ + directives: { + styleSrc: [`'unsafe-inline'`] + } +})); + +// middleware app.use(contentFilter()); // filter URL query attacks app.use(express.json({ limit: '5mb'})); app.use(express.urlencoded({ extended: false, limit: '5mb' })); @@ -71,7 +101,7 @@ app.use('/', require('./routes/measurement')); app.use('/static', express.static('static')); // Swagger UI -app.use('/api-doc', api.serve(), api.setup()); +app.use('/api-doc', api()); app.use((req, res) => { // 404 error handling res.status(404).json({status: 'Not found'}); diff --git a/src/routes/template.ts b/src/routes/template.ts index 20f1b3b..5641d1b 100644 --- a/src/routes/template.ts +++ b/src/routes/template.ts @@ -44,7 +44,14 @@ router.put('/template/:collection(measurement|condition|material)/' + IdValidate const {error, value: template} = TemplateValidate.input(req.body, 'change'); if (error) return res400(error, res); - const templateData = await model(req).findById(req.params.id).lean().exec().catch(err => {next(err);}) as any; + // find given template + const templateRef = await model(req).findById(req.params.id).lean().exec().catch(err => {next(err);}) as any; + if (templateRef instanceof Error) return; + if (!templateRef) { + return res.status(404).json({status: 'Not found'}); + } + // find latest version + const templateData = await model(req).findOne({first_id: templateRef.first_id}).sort({version: -1}).lean().exec().catch(err => {next(err);}) as any; if (templateData instanceof Error) return; if (!templateData) { return res.status(404).json({status: 'Not found'}); diff --git a/static/img/favicon.ico b/static/img/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..41ab51387eac958f34ed8db0be6c968e860bec98 GIT binary patch literal 1150 zcma))e`phD7{_mH^N%s6Fx+s^bxbLnF#lK?4iQG@WDFIHXv#|4SxxC`u=T`qZE&T; zSdVzS#u(GAh7i(lT(i)WtXRn|RXdZ@3YuXTZC7h)(_MRMa=+U&G_CL3E#S%qyW@NB z-E+_9`9AmDiy$w7bJHdST;D^!eFZ_@LJ;HwAP@qPzv5s)5b$pOvAVj7NMio=>8V`N zvx%kR@C|KmU$1)5Ppi7?{n}Sdc;O2nv%C@J{g)mmvL#n-lA(i;(EgCR&+AcY&bNuJ z*PL?Qj}Ez>rql}V&)nPp#?Q?zZ|>_=%CFjF!xgLC2pIh(T*d-^?eMu~q229Lj=8!N zeW*`6@LOE^XnhT7SStnGNytGjkY5Y^LH|d7ut;ZGjlu<=SE+6_ie{hhr>_%JnTHYVh4nR*ot>`Y{5_a~qKy=z?8jMDx+2irl@I3!!p@!s@ zswKB{lmgz+2k?i${K{!cses>enUqk8^3PT*nKZIF4f!MO8p`+B*%Lg~Jxqh1Vb-kH>ce z0)ayoiv@#uutzYbYUl%W3dVuXIGs*?ho$56C^3po|2ng4N>bl}JXFLTIZ8RHx*odc z$lrZ7fqB)pwY7Z@)C$Yh&70&d(iAIa2j9E$gDL z=&_(V*mB!(yPoy3RlJQiq`m2?1_{kq1vkY5S;NhCdWHu&~$t~On_u)J< z|9NUSRmu%MM-60%iz8HpRq2sb}_cN_74g*vP(-FCR6F6*>q;} z#9XQvYBD3eJ0YpXV}iPEgiCGzd0_D1Bikc`Ovx2_Ilnf)0uR^h^74k^kwj^T8QjlA z*|P8*c2DHiP#JUWR$Ua2VgfE;i+2}4d68Lv55M8*lcy!3Q`C#3*d&7eq=mIT`CNW& b&;2tW0rN+Y6`<8`fPz5J5acF&{vUb{Q9#4% literal 0 HcmV?d00001 diff --git a/static/styles/swagger-ui.css b/static/styles/swagger-ui.css new file mode 100644 index 0000000..9372efb --- /dev/null +++ b/static/styles/swagger-ui.css @@ -0,0 +1,323 @@ +/*Bosch styling for swagger*/ + +/*GET: dark blue*/ +/*POST: dark green*/ +/*PUT: turquoise*/ +/*DELETE: fuchsia*/ + +:root { + --red: #ea0016; + --dark-blue: #005691; + --dark-blue-w75: #bfd5e3; + --dark-green: #006249; + --dark-green-w75: #bfd8d1; + --turquoise: #00a8b0; + --turquoise-w75: #bfe9eb; + --fuchsia: #b90276; + --fuchsia-w75: #edc0dd; + --light-grey: #bfc0c2; + --light-grey-w75: #efeff0; + --light-green: #78be20; +} + +body { + background: #fff; +} + +body:before { + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 16px; + content: ''; + background-repeat: no-repeat; + background-size: cover; + background-image: url(/static/img/header.svg); +} + +body:after { + position: absolute; + right: 25px; + top: 36px; + width: 135px; + height: 48px; + content: ''; + background-repeat: no-repeat; + background-size: cover; + background-image: url(/static/img/bosch-logo.svg); +} + +.swagger-ui { + font-family: "Bosch Sans", sans-serif; +} + +/*custom docs*/ +.docs { + position: relative; + font-size: 14px; +} + +.docs > summary { + position: absolute; + right: 0; + top: -25px; + cursor: pointer; +} + +.docs-open:hover { + text-decoration: underline; +} + +/*Remove topbar*/ +.swagger-ui .topbar { + display: none +} + +/*Remove models view*/ +.swagger-ui .models { + display: none; +} + +/*Remove application/json select*/ +.swagger-ui .opblock .opblock-section-header > label, .swagger-ui .response-controls { + display: none; +} + +/*Remove border radius*/ +.swagger-ui .opblock, .swagger-ui .opblock .opblock-summary-method, .swagger-ui select { + border-radius: 0; + box-shadow: none; +} + +/*remove links in response*/ +.swagger-ui .response-col_links { + display: none; +} + +/*remove version*/ +.swagger-ui .info .title span { + display: none; +} + +/*separator before methods*/ +.swagger-ui .scheme-container { + box-shadow: none; + border-bottom: 1px solid var(--light-grey); +} + +/*tag separator*/ +.swagger-ui .opblock-tag { + border-bottom: 1px solid var(--light-grey); +} + +/*parameters/responses bar*/ +.swagger-ui .opblock .opblock-section-header { + box-shadow: none; + background: #fff; +} + +/*select*/ +.swagger-ui select { + background-color: var(--light-grey-w75); + border: none; + height: 36px; +} + +/*button*/ +.swagger-ui .btn { + border-radius: 0; + box-shadow: none; +} + +.swagger-ui .btn:hover { + box-shadow: none; +} + +/*authorize button */ +.swagger-ui .btn.authorize { + color: var(--light-green); + border-color: var(--light-green); +} + +.swagger-ui .btn.authorize svg { + fill: var(--light-green); +} + +/*auth inputs*/ +.swagger-ui .auth-container input[type="password"], .swagger-ui .auth-container input[type="text"] { + border-radius: 0; + box-shadow: none; + border-color: var(--light-grey); +} + +.swagger-ui .dialog-ux .modal-ux { + border-radius: 0; +} + +/*cancel button*/ +.swagger-ui .btn.cancel { + color: var(--red); + border-color: var(--red); +} + +/*download button*/ +.swagger-ui .download-contents { + border-radius: 0; + height: 28px; + width: 80px; +} + +/*model*/ +.swagger-ui .model-box { + border-radius: 0; +} + +/*execute button*/ +.swagger-ui .btn.execute { + background-color: var(--dark-blue); + border-color: var(--dark-blue); + height: 30px; + line-height: 0.7; +} + +.swagger-ui .btn-group .btn:last-child { + border-radius: 0; + height: 30px; + border-color: var(--dark-blue); +} + +.swagger-ui .btn-group .btn:first-child { + border-radius: 0; +} + +.swagger-ui .btn-group { + padding: 0 20px; +} + +/*parameter input*/ +.swagger-ui .parameters-col_description input[type="text"] { + border-radius: 0; +} + +/*required label*/ +.swagger-ui .parameter__name.required > span { + color: var(--red) !important; +} + +.swagger-ui .parameter__name.required::after { + color: var(--red); +} +/*Remove colored parameters bar*/ +.swagger-ui .opblock.opblock-get .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-post .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-put .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-delete .tab-header .tab-item.active h4 span::after { + background: none; +} + +/*code*/ +.swagger-ui .opblock-body pre.microlight { + border-radius: 0; +} + +.swagger-ui .highlight-code > .microlight { + min-height: 0; +} + +/*request body*/ +.swagger-ui textarea { + border-radius: 0; +} + +/*parameters smaller padding*/ +.swagger-ui .execute-wrapper { + padding-top: 0; + padding-bottom: 0; +} + +.swagger-ui .btn.execute { + margin-bottom: 20px; +} + +.swagger-ui .opblock-description-wrapper { + margin-top: 20px; +} + +.swagger-ui .opblock-description-wrapper { + margin-top: 5px; +} + +.opblock-section .opblock-section-request-body > div > div { + padding-top: 18px; +} + +/*response element positions*/ +.swagger-ui .model-example { + position: relative; + margin-top: 0; +} + +.swagger-ui .tab { + position: absolute; + top: -35px; + right: 0; +} + +.swagger-ui table tbody tr td { + padding: 0; +} + +.swagger-ui .renderedMarkdown p { + margin: 8px auto; +} + +/*Method colors*/ +.swagger-ui .opblock.opblock-get .opblock-summary-method { + background: var(--dark-blue); +} + +.swagger-ui .opblock.opblock-get .opblock-summary { + border-color: var(--dark-blue); +} + +.swagger-ui .opblock.opblock-get { + background: var(--dark-blue-w75); + border-color: var(--dark-blue); +} + +.swagger-ui .opblock.opblock-post .opblock-summary-method { + background: var(--dark-green); +} + +.swagger-ui .opblock.opblock-post .opblock-summary { + border-color: var(--dark-green); +} + +.swagger-ui .opblock.opblock-post { + background: var(--dark-green-w75); + border-color: var(--dark-green); +} + +.swagger-ui .opblock.opblock-put .opblock-summary-method { + background: var(--turquoise); +} + +.swagger-ui .opblock.opblock-put .opblock-summary { + border-color: var(--turquoise); +} + +.swagger-ui .opblock.opblock-put { + background: var(--turquoise-w75); + border-color: var(--turquoise); +} + +.swagger-ui .opblock.opblock-delete .opblock-summary-method { + background: var(--fuchsia); +} + +.swagger-ui .opblock.opblock-delete .opblock-summary { + border-color: var(--fuchsia); +} + +.swagger-ui .opblock.opblock-delete { + background: var(--fuchsia-w75); + border-color: var(--fuchsia); +} \ No newline at end of file diff --git a/static/styles/swagger.css b/static/styles/swagger.css deleted file mode 100644 index 9760ed4..0000000 --- a/static/styles/swagger.css +++ /dev/null @@ -1,323 +0,0 @@ -/*Bosch styling for swagger*/ - -/*GET: dark blue*/ -/*POST: dark green*/ -/*PUT: turquoise*/ -/*DELETE: fuchsia*/ - -:root { - --red: #ea0016; - --dark-blue: #005691; - --dark-blue-w75: #bfd5e3; - --dark-green: #006249; - --dark-green-w75: #bfd8d1; - --turquoise: #00a8b0; - --turquoise-w75: #bfe9eb; - --fuchsia: #b90276; - --fuchsia-w75: #edc0dd; - --light-grey: #bfc0c2; - --light-grey-w75: #efeff0; - --light-green: #78be20; -} - -body { - background: #fff; -} - -body:before { - position: absolute; - left: 0; - top: 0; - width: 100%; - height: 16px; - content: ''; - background-repeat: no-repeat; - background-size: cover; - background-image: url(data:image/svg+xml;base64,PHN2ZwogIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICB4bWw6c3BhY2U9InByZXNlcnZlIgogIGhlaWdodD0iMzAwIgogIHdpZHRoPSI3MjAiCiAgdmVyc2lvbj0iMS4xIgogIHk9IjAiCiAgeD0iMCIKICB2aWV3Qm94PSIwIDAgNzIwIDMwMCI+CiAgPHN0eWxlIHR5cGU9InRleHQvY3NzIj4KICAgIC5zdDAgewogICAgICBmaWxsOiB1cmwoIiNTVkdJRF8xXyIpOwogICAgfQogICAgLnN0MSB7CiAgICAgIGZpbGw6IHVybCgiI1NWR0lEXzJfIik7CiAgICB9CiAgICAuc3QyIHsKICAgICAgZmlsbDogdXJsKCIjU1ZHSURfM18iKTsKICAgIH0KICAgIC5zdDMgewogICAgICBmaWxsOiB1cmwoIiNTVkdJRF80XyIpOwogICAgfQogICAgLnN0NCB7CiAgICAgIGZpbGw6IHVybCgiI1NWR0lEXzVfIik7CiAgICB9CiAgICAuc3Q1IHsKICAgICAgZmlsbDogI0FGMjAyNDsKICAgIH0KICAgIC5zdDYgewogICAgICBmaWxsOiB1cmwoIiNTVkdJRF82XyIpOwogICAgfQogICAgLnN0NyB7CiAgICAgIGZpbGw6ICM5NDFCMUU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LTE2MC44aC00Mi4ybC0wLjEgMzA2LjRoMjguM2MtMS0zNS4xIDMuOC0xMDIuMSA3LTE0NS42eiIgY2xhc3M9InN0MjAiIGZpbGw9InVybCgjU1ZHSURfMTRfKSIvPjwvZz4KPC9zdmc+Cg==); -} - -body:after { - position: absolute; - right: 25px; - top: 36px; - width: 135px; - height: 48px; - content: ''; - background-repeat: no-repeat; - background-size: cover; - background-image: url(/static/img/bosch-logo.svg); -} - -.swagger-ui { - font-family: "Bosch Sans", sans-serif; -} - -/*custom docs*/ -.docs { - position: relative; - font-size: 14px; -} - -.docs > summary { - position: absolute; - right: 0; - top: -25px; - cursor: pointer; -} - -.docs-open:hover { - text-decoration: underline; -} - -/*Remove topbar*/ -.swagger-ui .topbar { - display: none -} - -/*Remove models view*/ -.swagger-ui .models { - display: none; -} - -/*Remove application/json select*/ -.swagger-ui .opblock .opblock-section-header > label, .swagger-ui .response-controls { - display: none; -} - -/*Remove border radius*/ -.swagger-ui .opblock, .swagger-ui .opblock .opblock-summary-method, .swagger-ui select { - border-radius: 0; - box-shadow: none; -} - -/*remove links in response*/ -.swagger-ui .response-col_links { - display: none; -} - -/*remove version*/ -.swagger-ui .info .title span { - display: none; -} - -/*separator before methods*/ -.swagger-ui .scheme-container { - box-shadow: none; - border-bottom: 1px solid var(--light-grey); -} - -/*tag separator*/ -.swagger-ui .opblock-tag { - border-bottom: 1px solid var(--light-grey); -} - -/*parameters/responses bar*/ -.swagger-ui .opblock .opblock-section-header { - box-shadow: none; - background: #fff; -} - -/*select*/ -.swagger-ui select { - background-color: var(--light-grey-w75); - border: none; - height: 36px; -} - -/*button*/ -.swagger-ui .btn { - border-radius: 0; - box-shadow: none; -} - -.swagger-ui .btn:hover { - box-shadow: none; -} - -/*authorize button */ -.swagger-ui .btn.authorize { - color: var(--light-green); - border-color: var(--light-green); -} - -.swagger-ui .btn.authorize svg { - fill: var(--light-green); -} - -/*auth inputs*/ -.swagger-ui .auth-container input[type="password"], .swagger-ui .auth-container input[type="text"] { - border-radius: 0; - box-shadow: none; - border-color: var(--light-grey); -} - -.swagger-ui .dialog-ux .modal-ux { - border-radius: 0; -} - -/*cancel button*/ -.swagger-ui .btn.cancel { - color: var(--red); - border-color: var(--red); -} - -/*download button*/ -.swagger-ui .download-contents { - border-radius: 0; - height: 28px; - width: 80px; -} - -/*model*/ -.swagger-ui .model-box { - border-radius: 0; -} - -/*execute button*/ -.swagger-ui .btn.execute { - background-color: var(--dark-blue); - border-color: var(--dark-blue); - height: 30px; - line-height: 0.7; -} - -.swagger-ui .btn-group .btn:last-child { - border-radius: 0; - height: 30px; - border-color: var(--dark-blue); -} - -.swagger-ui .btn-group .btn:first-child { - border-radius: 0; -} - -.swagger-ui .btn-group { - padding: 0 20px; -} - -/*parameter input*/ -.swagger-ui .parameters-col_description input[type="text"] { - border-radius: 0; -} - -/*required label*/ -.swagger-ui .parameter__name.required > span { - color: var(--red) !important; -} - -.swagger-ui .parameter__name.required::after { - color: var(--red); -} -/*Remove colored parameters bar*/ -.swagger-ui .opblock.opblock-get .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-post .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-put .tab-header .tab-item.active h4 span::after, .swagger-ui .opblock.opblock-delete .tab-header .tab-item.active h4 span::after { - background: none; -} - -/*code*/ -.swagger-ui .opblock-body pre.microlight { - border-radius: 0; -} - -.swagger-ui .highlight-code > .microlight { - min-height: 0; -} - -/*request body*/ -.swagger-ui textarea { - border-radius: 0; -} - -/*parameters smaller padding*/ -.swagger-ui .execute-wrapper { - padding-top: 0; - padding-bottom: 0; -} - -.swagger-ui .btn.execute { - margin-bottom: 20px; -} - -.swagger-ui .opblock-description-wrapper { - margin-top: 20px; -} - -.swagger-ui .opblock-description-wrapper { - margin-top: 5px; -} - -.opblock-section .opblock-section-request-body > div > div { - padding-top: 18px; -} - -/*response element positions*/ -.swagger-ui .model-example { - position: relative; - margin-top: 0; -} - -.swagger-ui .tab { - position: absolute; - top: -35px; - right: 0; -} - -.swagger-ui table tbody tr td { - padding: 0; -} - -.swagger-ui .renderedMarkdown p { - margin: 8px auto; -} - -/*Method colors*/ -.swagger-ui .opblock.opblock-get .opblock-summary-method { - background: var(--dark-blue); -} - -.swagger-ui .opblock.opblock-get .opblock-summary { - border-color: var(--dark-blue); -} - -.swagger-ui .opblock.opblock-get { - background: var(--dark-blue-w75); - border-color: var(--dark-blue); -} - -.swagger-ui .opblock.opblock-post .opblock-summary-method { - background: var(--dark-green); -} - -.swagger-ui .opblock.opblock-post .opblock-summary { - border-color: var(--dark-green); -} - -.swagger-ui .opblock.opblock-post { - background: var(--dark-green-w75); - border-color: var(--dark-green); -} - -.swagger-ui .opblock.opblock-put .opblock-summary-method { - background: var(--turquoise); -} - -.swagger-ui .opblock.opblock-put .opblock-summary { - border-color: var(--turquoise); -} - -.swagger-ui .opblock.opblock-put { - background: var(--turquoise-w75); - border-color: var(--turquoise); -} - -.swagger-ui .opblock.opblock-delete .opblock-summary-method { - background: var(--fuchsia); -} - -.swagger-ui .opblock.opblock-delete .opblock-summary { - border-color: var(--fuchsia); -} - -.swagger-ui .opblock.opblock-delete { - background: var(--fuchsia-w75); - border-color: var(--fuchsia); -} \ No newline at end of file From 149a0aec6d430e8daee6ef7e34e8bcae68ced4e7 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Tue, 28 Jul 2020 13:59:13 +0200 Subject: [PATCH 4/5] api and headers --- src/api.ts | 2 +- src/index.ts | 22 +++++++++++++--------- static/styles/swagger-ui.css | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/api.ts b/src/api.ts index d82a99e..8988cf1 100644 --- a/src/api.ts +++ b/src/api.ts @@ -125,7 +125,7 @@ window.onload = function() { plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], - layout: 'StandaloneLayout' + layout: "StandaloneLayout", }); } `; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index b7b5e2e..6771860 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import cors from 'cors'; import api from './api'; import db from './db'; -// TODO: working demo branch +// TODO: check header, also in UI // tell if server is running in debug or production environment console.info(process.env.NODE_ENV === 'production' ? '===== PRODUCTION =====' : process.env.NODE_ENV === 'test' ? '' :'===== DEVELOPMENT ====='); @@ -25,7 +25,7 @@ app.disable('x-powered-by'); const port = process.env.PORT || 3000; // security headers -app.use(helmet({ +const defaultHeaderConfig = { contentSecurityPolicy: { directives: { defaultSrc: [`'none'`], @@ -33,23 +33,27 @@ app.use(helmet({ formAction: [`'none'`], frameAncestors: [`'none'`] } - } -})); + }, + frameguard: { + action: 'deny' + }, + permittedCrossDomainPolicies: true, + refererPolicy: true +}; +app.use(helmet(defaultHeaderConfig)); // special CSP header for api-doc app.use('/api-doc', helmet.contentSecurityPolicy({ + ...defaultHeaderConfig, directives: { - defaultSrc: [`'none'`], scriptSrc: [`'self'`], connectSrc: [`'self'`], styleSrc: [`'self'`, `'unsafe-inline'`], - imgSrc: [`'self'`, 'data:'], - baseUri: [`'self'`], - formAction: [`'none'`], - frameAncestors: [`'none'`] + imgSrc: [`'self'`, 'data:'] } })); // special CSP header for the bosch-logo.svg app.use('/static/img/bosch-logo.svg', helmet.contentSecurityPolicy({ + ...defaultHeaderConfig, directives: { styleSrc: [`'unsafe-inline'`] } diff --git a/static/styles/swagger-ui.css b/static/styles/swagger-ui.css index 9372efb..70bf2b8 100644 --- a/static/styles/swagger-ui.css +++ b/static/styles/swagger-ui.css @@ -161,6 +161,26 @@ body:after { border-color: var(--red); } +/*clipboard button*/ +.swagger-ui .copy-to-clipboard { + border-radius: 0; + top: 19px; + height: 28px; +} +.swagger-ui .copy-to-clipboard > button { + position: relative; + bottom: 3px; +} +.swagger-ui .curl-command .copy-to-clipboard { + border-radius: 0; + top: 24px; +} +.swagger-ui .curl-command .copy-to-clipboard > button { + position: relative; + bottom: 7px; + right: 1px; +} + /*download button*/ .swagger-ui .download-contents { border-radius: 0; @@ -216,6 +236,8 @@ body:after { /*code*/ .swagger-ui .opblock-body pre.microlight { border-radius: 0; + background: #41444e !important; + padding: 0.5em; } .swagger-ui .highlight-code > .microlight { From 4f7eb6f92fa322d879afdd56f653d997af5a364f Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 30 Jul 2020 11:36:03 +0200 Subject: [PATCH 5/5] minor fixes --- data_import/import.js | 11 +++--- src/index.ts | 1 + src/routes/user.ts | 1 + static/img/header.svg | 82 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 static/img/header.svg diff --git a/data_import/import.js b/data_import/import.js index aa84bf3..0f8d867 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -158,6 +158,9 @@ async function importCsv(doc) { newE[field] = ''; } }); + // if(newE['materialname'] === '') { // TODO: is this replacement okay? + // newE['materialname'] = newE['material']; + // } if (newE['supplier'] === '') { // empty supplier fields newE['supplier'] = 'unknown'; } @@ -208,7 +211,7 @@ async function allDpts() { res.data.forEach(sample => { sampleIds[sample.number] = sample._id; }); - const dptRegex = /(.*?)_(.*?)_(\d+|\w+_\d+).DPT/; + const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+_\d+).DPT/; const dpts = fs.readdirSync(dptFiles); for (let i in dpts) { const regexRes = dptRegex.exec(dpts[i]) @@ -269,8 +272,8 @@ async function allKfVz() { password: 'Abc123!#' } }); - const kf_template = res.data.find(e => e.name === 'kf')._id; - const vz_template = res.data.find(e => e.name === 'vz')._id; + const kf_template = res.data.filter(e => e.name === 'kf').sort((a, b) => b.version - a.version)[0]._id; + const vz_template = res.data.filter(e => e.name === 'vz').sort((a, b) => b.version - a.version)[0]._id; res = await axios({ method: 'get', url: host + '/samples?status=all', @@ -380,7 +383,7 @@ async function allSamples() { continue; } samples.push({ - number: sample['samplenumber'], + number: sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, ''), // remove leading An_01 and Eh_01 type: sampleType(sample['granulate/part']), batch: sample['charge/batch'], material_id: material._id, diff --git a/src/index.ts b/src/index.ts index 6771860..3fc4ef8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ app.use(helmet(defaultHeaderConfig)); app.use('/api-doc', helmet.contentSecurityPolicy({ ...defaultHeaderConfig, directives: { + defaultSrc: [`'none'`], scriptSrc: [`'self'`], connectSrc: [`'self'`], styleSrc: [`'self'`, `'unsafe-inline'`], diff --git a/src/routes/user.ts b/src/routes/user.ts index 65c41d5..2393150 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -65,6 +65,7 @@ router.put('/user:username([/](?!key|new).?*|/?)', async (req, res, next) => { }); }); +// TODO: only possible if no data is linked to user, otherwise change status, etc. router.delete('/user:username([/](?!key|new).?*|/?)', (req, res, next) => { // this path matches /user, /user/ and /user/xxx, but not /user/key or user/new. See https://forbeslindesay.github.io/express-route-tester/ for the generated regex if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'basic')) return; diff --git a/static/img/header.svg b/static/img/header.svg new file mode 100644 index 0000000..85e56b9 --- /dev/null +++ b/static/img/header.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file