Skip to content

Commit

Permalink
sonar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonSharratt committed Jan 30, 2020
1 parent aeb8faf commit 1014a61
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 109 deletions.
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
4 changes: 2 additions & 2 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 @@ -411,7 +411,7 @@ model.getAll = function(query, limit, page, user, callback){
}

if ('_id' in query) {
db.Request.findById(query['_id'], (err, req) => {
db.Request.findById(query['_id'], (err3, req) => {
getAllTopics(user, { id: req.topic }, queryRequests);
});
} else {
Expand Down
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;
12 changes: 6 additions & 6 deletions microservices/requestApi/notifications/gitops/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var gitops = function(db){
var gitop = function(db){

var gitops = {};

Expand Down Expand Up @@ -26,9 +26,9 @@ var gitops = function(db){

let transition = this.getTransition(request);

if (transition == "1-2" /* WIP to Awaiting Review */|| transition == "1-3" /* WIP to In Review */ ) {
} else if (transition == "-0" /* Created */ ) {
} else if (transition == "0-1" /* Draft to WIP */ && request.mergeRequestStatus.code == 0) {
//if (transition == "1-2" /* WIP to Awaiting Review */|| transition == "1-3" /* WIP to In Review */ ) {
//} else if (transition == "-0" /* Created */ ) {
/*} else */if (transition == "0-1" /* Draft to WIP */ && request.mergeRequestStatus.code == 0) {
let payload = {
direction: request.type,
repository: request.repository,
Expand Down Expand Up @@ -179,7 +179,7 @@ var gitops = function(db){
gitops.updateRequest = function(request, link, code, message) {
let id = request._id;
return new Promise(function(resolve, reject) {
db.Request.findById(id, (err, requestForUpdate) => {
db.Request.findById(id, (err2, requestForUpdate) => {
requestForUpdate.mergeRequestLink = link;
requestForUpdate.mergeRequestStatus = {
code: code,
Expand All @@ -201,4 +201,4 @@ var gitops = function(db){
return gitops;
}

module.exports = gitops;
module.exports = gitop;
4 changes: 2 additions & 2 deletions microservices/requestApi/notifications/notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var notifications = function(db){
var notification = function(db){
const email = require('./email')(db);
const gitops = require('./gitops')(db);

Expand All @@ -19,4 +19,4 @@ var notifications = function(db){
return notifications;
}

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

0 comments on commit 1014a61

Please sign in to comment.