Commit b63a5b18 authored by Fernando Erd's avatar Fernando Erd 👌

Merge branch 'development' of gitlab.c3sl.ufpr.br:simcaq/simcaq-node into development

parents ded48256 9adcb872
Pipeline #21909 failed with stage
in 60 minutes
......@@ -37,8 +37,7 @@ regression_tests:
- git clone https://gitlab.c3sl.ufpr.br/simcaq/lde-api-regression-test.git
- cd lde-api-regression-test
- git checkout development
- pip install -r requirements.txt
- python manage.py compare
- python manage.py compare --verbose
tags:
- node
......@@ -31,16 +31,15 @@ const LDE_API_URL = config.lde_api.url;
function auth(origin) {
return (req, res, next) => {
const options = {
url: `${LDE_API_URL}/verifyDownload`,
url: `${LDE_API_URL}/validateToken`,
headers: {
'Authorization': req.header('Authorization'),
'origin': origin
}
};
request.get(options, (err, response, body) => {
console.log("--------------->> "+body);
request.post(options, (err, response, body) => {
if(err)
console.log("ERRO!");
log.err("auth error");
let resp;
try {
resp = JSON.parse(body);
......@@ -51,7 +50,10 @@ function auth(origin) {
req.name = resp.name;
req.email = resp.email;
req.userId = resp.userId;
console.log("==========>"+req.userId);
req.user = {};
req.user.origin = resp.origin;
req.user.adminSimcaqNode = resp.adminSimcaqNode;
req.user.adminLDE = resp.adminLDE;
return next();
}
res.json({access: 'Unauthorized'});
......
......@@ -8,4 +8,4 @@ function checkAdmin() {
}
}
module.exports = checkAdmin;
\ No newline at end of file
module.exports = checkAdmin;
......@@ -42,9 +42,11 @@ const config = require(`${libs}/config`);
const auth = require(`${libs}/middlewares/auth`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
const checkAdmin = require(`${libs}/middlewares/checkAdmin`);
simulationApp.use(cache('15 day'));
//const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
//simulationApp.use(cache('15 day'));
simulationApp.get('/time', (req, res, next) => {
const maxTime = parseInt(req.query.max_time, 10);
......@@ -71,19 +73,13 @@ simulationApp.get('/pqr', (req, res) => {
});
});
simulationApp.put('/pqr', auth("SimCAQ"), (req, res, next) => {
simulationApp.put('/pqr', auth("SimCAQ"), checkAdmin(), (req, res, next) => {
PQR.findOne((err, pqr) => {
if(err) {
log.error(err)
return next({err});
}
if(!req.adminSimcaqNode) {
log.info(`Usuário ${req.email} tentou alterar o PQR, mas não tem privilégio`);
res.statusCode = 401;
return next({err: { msg: 'Unauthorized'}});
}
pqr.content = req.body.content || pqr.content;
pqr.save((err) => {
if(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment