-
Notifications
You must be signed in to change notification settings - Fork 55
[Hot Fix]Pm 1836 prod #856
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
Changes from all commits
eb99b14
b31d5c7
b4d23b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |
|
|
||
| import models from '../../models'; | ||
| import util from '../../util'; | ||
| import DEFAULT_PAGE_SIZE from '../../constants'; | ||
| import DEFAULT_PAGE_SIZE, { USER_ROLE } from '../../constants'; | ||
|
|
||
| module.exports = [ | ||
| (req, res, next) => { | ||
|
|
@@ -15,6 +15,7 @@ module.exports = [ | |
| return util.handleError('Invalid sort criteria', null, req, next); | ||
| } | ||
| const sortParams = sort.split(' '); | ||
| const isAdminOrManager = util.hasRoles(req, [USER_ROLE.CONNECT_ADMIN, USER_ROLE.TOPCODER_ADMIN, USER_ROLE.PROJECT_MANAGER]); | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Extract pagination parameters | ||
| const page = parseInt(req.query.page, 10) || 1; | ||
|
|
@@ -42,7 +43,7 @@ module.exports = [ | |
| baseOrder.push([sortParams[0], sortParams[1]]); | ||
|
|
||
| return models.CopilotOpportunity.findAll({ | ||
| include: [ | ||
| include: isAdminOrManager ? [ | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| model: models.CopilotRequest, | ||
| as: 'copilotRequest', | ||
|
|
@@ -52,6 +53,11 @@ module.exports = [ | |
| as: 'project', | ||
| attributes: ['name'], | ||
| }, | ||
| ] : [ | ||
| { | ||
| model: models.CopilotRequest, | ||
| as: 'copilotRequest', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider specifying the attributes you need from the |
||
| }, | ||
| ], | ||
| order: baseOrder, | ||
| limit, | ||
|
|
@@ -60,10 +66,17 @@ module.exports = [ | |
| .then((copilotOpportunities) => { | ||
| const formattedOpportunities = copilotOpportunities.map((opportunity) => { | ||
| const plainOpportunity = opportunity.get({ plain: true }); | ||
| return Object.assign({}, plainOpportunity, | ||
| const formatted = Object.assign({}, plainOpportunity, | ||
| plainOpportunity.copilotRequest ? plainOpportunity.copilotRequest.data : {}, | ||
| { copilotRequest: undefined }, | ||
| ); | ||
|
|
||
| // For users who are not admin or manager, we dont want to expose | ||
| // the project id | ||
| if (!isAdminOrManager) { | ||
| delete formatted.projectId; | ||
| } | ||
| return formatted; | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| return util.setPaginationHeaders(req, res, { | ||
| count: copilotOpportunities.count, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { Op, Sequelize } from 'sequelize'; | |
| import models from '../../models'; | ||
| import util from '../../util'; | ||
| import { PERMISSION } from '../../permissions/constants'; | ||
| import { DEFAULT_PAGE_SIZE } from '../../constants'; | ||
| import { DEFAULT_PAGE_SIZE, USER_ROLE } from '../../constants'; | ||
|
|
||
| module.exports = [ | ||
| (req, res, next) => { | ||
|
|
@@ -17,6 +17,7 @@ module.exports = [ | |
| return next(err); | ||
| } | ||
|
|
||
| const isAdminOrManager = util.hasRoles(req, [USER_ROLE.CONNECT_ADMIN, USER_ROLE.TOPCODER_ADMIN, USER_ROLE.PROJECT_MANAGER]); | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const page = parseInt(req.query.page, 10) || 1; | ||
| const pageSize = parseInt(req.query.pageSize, 10) || DEFAULT_PAGE_SIZE; | ||
| const offset = (page - 1) * pageSize; | ||
|
|
@@ -46,7 +47,7 @@ module.exports = [ | |
| let order = [[sortParams[0], sortParams[1]]]; | ||
| const relationBasedSortParams = ['projectName']; | ||
| const jsonBasedSortParams = ['opportunityTitle', 'projectType']; | ||
| if (relationBasedSortParams.includes(sortParams[0])) { | ||
| if (relationBasedSortParams.includes(sortParams[0]) && isAdminOrManager) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition now includes |
||
| order = [ | ||
| [{model: models.Project, as: 'project'}, 'name', sortParams[1]], | ||
| ['id', 'DESC'] | ||
|
|
@@ -64,9 +65,11 @@ module.exports = [ | |
|
|
||
| return models.CopilotRequest.findAndCountAll({ | ||
| where: whereCondition, | ||
| include: [ | ||
| include: isAdminOrManager ? [ | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { model: models.CopilotOpportunity, as: 'copilotOpportunity', required: false }, | ||
| { model: models.Project, as: 'project', required: false }, | ||
| ] : [ | ||
| { model: models.CopilotOpportunity, as: 'copilotOpportunity', required: false }, | ||
| ], | ||
| order, | ||
| limit: pageSize, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.