Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sonar #277

Merged
merged 75 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1014a61
sonar changes
BrandonSharratt Jan 30, 2020
ed5b6c8
a few more
BrandonSharratt Jan 30, 2020
e315c88
a few more
BrandonSharratt Jan 30, 2020
f432599
added more tests for v2
BrandonSharratt Jan 30, 2020
f9f44c6
added more tests for v2
BrandonSharratt Jan 30, 2020
8a38138
added more tests for v2
BrandonSharratt Jan 30, 2020
ceff088
more test coverage
BrandonSharratt Jan 30, 2020
56a98f8
test tweaks
BrandonSharratt Jan 31, 2020
2338112
test tweaks
BrandonSharratt Jan 31, 2020
f0c9849
test tweaks
BrandonSharratt Jan 31, 2020
4c5a0c8
test tweaks
BrandonSharratt Jan 31, 2020
6b1b841
sonar tweaks
BrandonSharratt Jan 31, 2020
619a7b8
adding more tests
BrandonSharratt Jan 31, 2020
6a13c4c
test tweaks
BrandonSharratt Jan 31, 2020
269715f
tweak
BrandonSharratt Jan 31, 2020
b348da4
debug
BrandonSharratt Jan 31, 2020
6bcc60f
test tweaks
BrandonSharratt Jan 31, 2020
c796a32
test tweaks
BrandonSharratt Jan 31, 2020
e5d6cdd
debug
BrandonSharratt Jan 31, 2020
ca92313
debug
BrandonSharratt Jan 31, 2020
5ca4424
debug
BrandonSharratt Jan 31, 2020
4ba48d0
fix
BrandonSharratt Jan 31, 2020
27bdd4f
fixes
BrandonSharratt Feb 3, 2020
29d3ac4
fixes
BrandonSharratt Feb 3, 2020
cc2ea91
fixes
BrandonSharratt Feb 3, 2020
7e2f1f0
fixes
BrandonSharratt Feb 3, 2020
d850c4a
debug
BrandonSharratt Feb 3, 2020
515d37f
debug
BrandonSharratt Feb 3, 2020
a723732
fixes
BrandonSharratt Feb 3, 2020
dda9794
debug
BrandonSharratt Feb 3, 2020
882e05b
debug
BrandonSharratt Feb 3, 2020
f315564
test fixes
BrandonSharratt Feb 3, 2020
60cf205
fixed tests
BrandonSharratt Feb 3, 2020
c0bea86
caught the case when an invalid object id is passed
BrandonSharratt Feb 3, 2020
0bf997a
fixes
BrandonSharratt Feb 3, 2020
abca432
syntax error
BrandonSharratt Feb 3, 2020
279b51d
more test coverage
BrandonSharratt Feb 3, 2020
dc3a474
debug
BrandonSharratt Feb 3, 2020
6b4e4a4
debug
BrandonSharratt Feb 3, 2020
dea27a1
debug
BrandonSharratt Feb 3, 2020
39d8bd9
fix tests
BrandonSharratt Feb 3, 2020
a1c6575
update python for request api, added a lot more tests
BrandonSharratt Feb 3, 2020
debd15d
fixes for some of the edge cases
BrandonSharratt Feb 3, 2020
eb93d49
fix 2 broken tests
BrandonSharratt Feb 3, 2020
1cbca22
more tests and using python 3.5
BrandonSharratt Feb 4, 2020
c393c27
bug fixes and test tweaks
BrandonSharratt Feb 4, 2020
8c8a871
fix syntax
BrandonSharratt Feb 4, 2020
3501277
debug
BrandonSharratt Feb 4, 2020
1ce5540
debug
BrandonSharratt Feb 4, 2020
76ea853
added version to models for debugging
BrandonSharratt Feb 4, 2020
13885b8
debug
BrandonSharratt Feb 4, 2020
22cbc92
debug
BrandonSharratt Feb 4, 2020
b795ec3
debug
BrandonSharratt Feb 4, 2020
722d8f7
debug
BrandonSharratt Feb 4, 2020
aea8ba2
test tweaks
BrandonSharratt Feb 4, 2020
1f93ccd
tweaks
BrandonSharratt Feb 4, 2020
b0a7005
debug
BrandonSharratt Feb 4, 2020
539da66
insanity
BrandonSharratt Feb 4, 2020
d24eba4
debug
BrandonSharratt Feb 4, 2020
327aa63
fixes to some form sub routes
BrandonSharratt Feb 4, 2020
40130e5
fix test error
BrandonSharratt Feb 5, 2020
b17e90f
couple of tweaks
BrandonSharratt Feb 5, 2020
4847971
fixed some bugs, changed the log level of some stuff and removed test…
BrandonSharratt Feb 5, 2020
dd5db07
fixing some more things
BrandonSharratt Feb 5, 2020
0d4738f
tweaks
BrandonSharratt Feb 5, 2020
ce4876b
test tweaks
BrandonSharratt Feb 5, 2020
1350981
fixed a bug
BrandonSharratt Feb 5, 2020
870a9d2
test tweaks
BrandonSharratt Feb 5, 2020
3028721
tweaks
BrandonSharratt Feb 5, 2020
3bcb425
tweaks to log levels
BrandonSharratt Feb 5, 2020
6009bdf
removed some duplicated code
BrandonSharratt Feb 5, 2020
2744eba
bug fixes
BrandonSharratt Feb 5, 2020
153ece6
test tweak
BrandonSharratt Feb 5, 2020
9a72997
test fix
BrandonSharratt Feb 5, 2020
6d2a661
increment file wait time
BrandonSharratt Feb 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ matrix:
packages:
- g++-4.8
- python3-pip
- python3.5
before_script:
- |-
wget -q ${HELM_URL}/${HELM_TGZ}
Expand Down Expand Up @@ -192,19 +193,21 @@ matrix:
export MINIO_SECRET_KEY="secretkey"
./minio server /tmp &
- |-
alias python3=python3.5
cd /home/travis/build/bcgov/OCWA/microservices/validateApi
sudo pip3 install -U setuptools
sudo pip3 install -r requirements.txt
cp config/default.json.template config/default.json
sudo pip3 install -e .
python3 wsgi.py &
python3.5 wsgi.py &
- |-
alias python3=python3.5
cd /home/travis/build/bcgov/OCWA/microservices/policyApi
sudo pip3 install -U setuptools
sudo pip3 install -r requirements.txt
cp config/default.json.template config/default.json
sudo pip3 install -e .
python3 wsgi.py &
python3.5 wsgi.py &
- |-
cd /home/travis/build/bcgov/OCWA/microservices/requestApi
NODE_ENV=test npm start &
Expand Down
12 changes: 5 additions & 7 deletions microservices/forumApi/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ mongoose.set('useCreateIndex', true);

const dbProps = config.get('database');

dbHost = dbProps.host;
dbUser = dbProps.username;
dbPass = dbProps.password;
dbName = dbProps.dbName;
const dbHost = dbProps.host;
const dbUser = dbProps.username;
const dbPass = dbProps.password;
const dbName = dbProps.dbName;

var db = {};

Expand Down Expand Up @@ -37,9 +37,7 @@ db.init = function(){
db.Permission = require('./model/permission');
db.User = require('./model/user');

var collections = Object.keys(db.db.collections);

};
}



Expand Down
8 changes: 5 additions & 3 deletions microservices/forumApi/db/model/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ model.getAll = function(query, limit, page, user, callback){
checkGroups.splice(index,1);
}

var index = checkGroups.indexOf('/oc');
index = checkGroups.indexOf('/oc');
if (index !== -1){
checkGroups.splice(index,1);
}
Expand All @@ -54,7 +54,8 @@ model.getAll = function(query, limit, page, user, callback){
from: "permissions",
let: { topicId: "$_id", parent: "$parent_id"},
pipeline: [
{$match: {
{
$match: {
$expr: {
$and: [
{$or: [
Expand All @@ -65,7 +66,8 @@ model.getAll = function(query, limit, page, user, callback){
{$eq: ["$allow", true]}
]
}
}},
}
},
{
$match: {
$or: [
Expand Down
6 changes: 3 additions & 3 deletions microservices/forumApi/routes/v1/routes/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ router.post("/:topicId", function(req, res, next){
return;
}

subscribers.subscribe(topic._id, req.user.id, true, (err) => {
if (err) {
subscribers.subscribe(topic._id, req.user.id, true, (err2) => {
if (err2) {
res.status(500);
res.json({error: err.message});
res.json({error: err2.message});
return;
}

Expand Down
4 changes: 0 additions & 4 deletions microservices/forumApi/routes/v1/routes/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ router.post("/", function(req, res, next){

router.delete('/:topicId', function(req, res){
var db = require('../db/db');
var config = require('config');
var logger = require('npmlog');
var mongoose = require('mongoose');
var topicId = mongoose.Types.ObjectId(req.params.topicId);

db.Topic.getAll({_id: topicId}, 1, 1, req.user, function(topicErr, topicRes) {
Expand Down Expand Up @@ -188,7 +186,6 @@ router.delete('/:topicId', function(req, res){

router.put('/:topicId/subscribe', function(req, res){
var db = require('../db/db');
var mongoose = require('mongoose');
var subscribers = require('../subscribers/subscribers');
var topicId = mongoose.Types.ObjectId(req.params.topicId);

Expand All @@ -215,7 +212,6 @@ router.put('/:topicId/subscribe', function(req, res){

router.put('/:topicId/unsubscribe', function(req, res){
var db = require('../db/db');
var mongoose = require('mongoose');
var subscribers = require('../subscribers/subscribers');
var topicId = mongoose.Types.ObjectId(req.params.topicId);

Expand Down
8 changes: 4 additions & 4 deletions microservices/forumApi/routes/v1/subscribers/subscribers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var db = require('../db/db');

var subscribers = {};
var s = {};

subscribers.subscribe = function(topicId, userId, contributed, callback){
s.subscribe = function(topicId, userId, contributed, callback){
db.Topic.findById(topicId).exec((err, topic) => {
if (err || topic == null) {
callback({error:'topic not found'});
Expand Down Expand Up @@ -30,7 +30,7 @@ subscribers.subscribe = function(topicId, userId, contributed, callback){
});
};

subscribers.unsubscribe = function(topicId, userId, callback){
s.unsubscribe = function(topicId, userId, callback){
db.Topic.findById(topicId).exec((err, topic) => {
if (err || topic == null) {
callback({error:'topic not found'});
Expand All @@ -51,4 +51,4 @@ subscribers.unsubscribe = function(topicId, userId, callback){
};


module.exports = subscribers;
module.exports = s;
2 changes: 1 addition & 1 deletion microservices/requestApi/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var auth = function(db){

const isOutputChecker = (user => user.groups.includes(config.get('outputCheckerGroup')))
const isInReportsGroup = (user => user.groups.includes(config.get('reportsGroup')))
const isInGroupToCreateRequest = (user => user.groups.includes(config.get('requiredRoleToCreateRequest')))


passport.use(new JWTStrategy({
jwtFromRequest: ExtractJWT.fromAuthHeaderAsBearerToken(),
Expand Down
4 changes: 2 additions & 2 deletions microservices/requestApi/auth/webhook_auth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var auth = function(){
const passport = require('passport');
const passJwt = require('passport-jwt');

const passApiKey = require('passport-headerapikey');
const HeaderAPIKeyStrategy = passApiKey.HeaderAPIKeyStrategy;
const config = require('config');
const logger = require('npmlog');


passport.use(new HeaderAPIKeyStrategy(
{ header: 'Authorization', prefix: 'Api-Key ' },
Expand Down
20 changes: 10 additions & 10 deletions microservices/requestApi/clients/formio_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ formio.auth = function(callback){
formio.getSubmissions = function(formName, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName+"/submission";

Expand All @@ -85,7 +85,7 @@ formio.getSubmission = function(formName, submissionId, callback) {

this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId;
logger.verbose("formio get submission", url);
Expand All @@ -106,7 +106,7 @@ formio.getSubmission = function(formName, submissionId, callback) {
formio.postSubmission = function(formName, values, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName+"/submission";

Expand Down Expand Up @@ -139,7 +139,7 @@ formio.postSubmission = function(formName, values, callback) {
formio.deleteSubmission = function(formName, submissionId, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId;

Expand All @@ -156,7 +156,7 @@ formio.deleteSubmission = function(formName, submissionId, callback) {
formio.putSubmission = function(formName, submissionId, values, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId;

Expand All @@ -182,7 +182,7 @@ formio.getForms = function(callback) {
}
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/form";

Expand All @@ -208,7 +208,7 @@ formio.getForm = function(formName, callback) {
}
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/"+formName;

Expand All @@ -229,7 +229,7 @@ formio.getForm = function(formName, callback) {
formio.postForm = function(data, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/form";

Expand All @@ -246,7 +246,7 @@ formio.postForm = function(data, callback) {
formio.putForm = function(formName, data, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/form/" + formName;

Expand All @@ -263,7 +263,7 @@ formio.putForm = function(formName, data, callback) {
formio.deleteForm = function(formName, callback) {
this.auth(function(err, jwt){
if (err){
logger.error("Error getting jwt", err);
logger.debug("Error getting jwt", err);
}
var url = config.get('formio.url') + "/" + formName;

Expand Down
10 changes: 5 additions & 5 deletions microservices/requestApi/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ mongoose.set('useCreateIndex', true);

const dbProps = config.get('database');

dbHost = dbProps.host;
dbUser = dbProps.username;
dbPass = dbProps.password;
dbName = dbProps.dbName;
const dbHost = dbProps.host;
const dbUser = dbProps.username;
const dbPass = dbProps.password;
const dbName = dbProps.dbName;

function versionedDB(version){

Expand Down Expand Up @@ -45,7 +45,7 @@ function versionedDB(version){
db.init();

return db;
};
}



Expand Down
21 changes: 16 additions & 5 deletions microservices/requestApi/db/model/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ model.getAll = function(query, limit, page, user, callback){

logger.verbose("getAll ", user.supervisor, user.outputchecker);

var queryRequests = function(err, topicR, projectR){
var queryRequests = function(err2, topicR, projectR){
logger.verbose("get all topics model get all", topicR);
if ('_id' in query) {
query['_id'] = mongoose.Types.ObjectId(query['_id']);
Expand Down Expand Up @@ -399,24 +399,35 @@ model.getAll = function(query, limit, page, user, callback){
];

db.Request.aggregate(q).exec(function(err, results){
if (err){
return callback(err, []);
}
logger.verbose("in topic bind");
if (results){
for (var i=0; i<results.length; i++){
let topicId = results[i].topic;
results[i].projects = projectR.get(topicId);
if ( (typeof(results[i]) !== "undefined") && (typeof(results[i].topic) !== "undefined") ){
let topicId = results[i].topic;
results[i].projects = projectR.get(topicId);
}
}
}
callback(err, results);
});
}

if ('_id' in query) {
db.Request.findById(query['_id'], (err, req) => {
getAllTopics(user, { id: req.topic }, queryRequests);
db.Request.findById(query['_id'], (err3, req) => {
if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){
getAllTopics(user, { id: req.topic }, queryRequests);
}else{
callback(null, []);
}
});
} else {
getAllTopics(user, {}, queryRequests);
}
};

model.VERSION = 1;

module.exports = model;
8 changes: 4 additions & 4 deletions microservices/requestApi/notifications/email/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var notifications = function(db){
var notification = function(db){

var notifications = {};
var fs = require('fs');
Expand Down Expand Up @@ -80,14 +80,14 @@ var notifications = function(db){

if ( (submittedUnclaimed) && (config.has('emailOnInitialSubmit')) ){
var emailList = config.get('emailOnInitialSubmit');
for (var i=0; i<emailList.length; i++){
for (let i=0; i<emailList.length; i++){
sendEmail(request, {name: emailList[i].name, email: emailList[i].email}, user, "emailSubmitTemplate.html");
}
}

logger.verbose("Notification[email] triggered", user);

for (var i=0; i<notifyWho.length; i++){
for (let i=0; i<notifyWho.length; i++){

var who = notifyWho[i];

Expand Down Expand Up @@ -160,4 +160,4 @@ var notifications = function(db){
return notifications;
}

module.exports = notifications;
module.exports = notification;
Loading