Skip to content

Commit

Permalink
fix(reports): invalid group reporting. #290
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Dec 23, 2019
1 parent 1f9291e commit faa25b3
Showing 1 changed file with 78 additions and 29 deletions.
107 changes: 78 additions & 29 deletions src/controllers/api/v1/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,19 @@ apiReports.generate.ticketsByPriority = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)
return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down Expand Up @@ -232,11 +241,19 @@ apiReports.generate.ticketsByStatus = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down Expand Up @@ -313,11 +330,19 @@ apiReports.generate.ticketsByTags = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down Expand Up @@ -393,11 +418,19 @@ apiReports.generate.ticketsByType = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down Expand Up @@ -473,11 +506,19 @@ apiReports.generate.ticketsByUser = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down Expand Up @@ -522,11 +563,19 @@ apiReports.generate.ticketsByAssignee = function (req, res) {
[
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
if (req.user.role.isAdmin || req.user.role.isAgent) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
groupSchema.getAllGroupsOfUser(req.user._id, function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
}
} else {
return done(null, postData.groups)
}
Expand Down

0 comments on commit faa25b3

Please sign in to comment.