From f8a6786660f2a4eadc8b446d1b015a390ba72c42 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 14:47:51 +0530 Subject: [PATCH 01/10] fix: send members as part of opportunity --- src/routes/copilotOpportunity/get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index a968af13..145d90a8 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -19,7 +19,7 @@ module.exports = [ { model: models.Project, as: 'project', - attributes: ['name'], + attributes: ['name', 'members'], }, ], }) From 596d9b13cb02853fa105e67b765733b9a2245e7f Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 14:49:30 +0530 Subject: [PATCH 02/10] fix: send members as part of opportunity --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc40edcd..8c07e37e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup', 'pm-1356'] + only: ['develop', 'migration-setup', 'pm-1273'] - deployProd: context : org-global filters: From 9d7010402713f57a5dce9fb02986a41dec4defd5 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 16:22:47 +0530 Subject: [PATCH 03/10] fix: send members as part of opportunity --- src/routes/copilotOpportunity/get.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index 145d90a8..11949adb 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -19,7 +19,14 @@ module.exports = [ { model: models.Project, as: 'project', - attributes: ['name', 'members'], + attributes: ['name'], + include: [ + { + model: models.ProjectMember, + as: 'members', + attributes: ['id', 'userId', 'role'], + }, + ] }, ], }) From 2eb2d21e02059625a7f96fd60cbbbf91a00f866c Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 16:24:27 +0530 Subject: [PATCH 04/10] fix: send members as part of opportunity --- src/models/projectMember.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/models/projectMember.js b/src/models/projectMember.js index bf213a3d..627f9531 100644 --- a/src/models/projectMember.js +++ b/src/models/projectMember.js @@ -34,6 +34,10 @@ module.exports = function defineProjectMember(sequelize, DataTypes) { ], }); + ProjectMember.associate = (models) => { + ProjectMember.belongsTo(models.Project, { foreignKey: 'projectId' }); + }; + ProjectMember.getProjectIdsForUser = userId => ProjectMember.findAll({ where: { deletedAt: { $eq: null }, From f6138fe492409c2830e75a2a39006dc6731d2d90 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 17:40:33 +0530 Subject: [PATCH 05/10] fix: send members as part of opportunity --- src/routes/copilotOpportunity/get.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index 11949adb..37f36837 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -32,7 +32,16 @@ module.exports = [ }) .then((copilotOpportunity) => { const plainOpportunity = copilotOpportunity.get({ plain: true }); - const formattedOpportunity = Object.assign({}, plainOpportunity, + let canApplyAsCopilot = false; + if (plainOpportunity && plainOpportunity.project && plainOpportunity.project.members && req.authUser) { + const existingMember = plainOpportunity.project.members.find(item => item.userId === req.authUser.userId); + canApplyAsCopilot = !!!existingMember; + } + // This shouldn't be exposed to the clientside + delete plainOpportunity.project.members; + const formattedOpportunity = Object.assign({ + canApplyAsCopilot, + }, plainOpportunity, plainOpportunity.copilotRequest ? plainOpportunity.copilotRequest.data : {}, { copilotRequest: undefined }, ); From 8612e0281dce4890f9f3ed816d2d0a87ae8cd296 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 18:04:08 +0530 Subject: [PATCH 06/10] fix: send members as part of opportunity --- src/routes/copilotOpportunity/get.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index 37f36837..c574b26d 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -33,8 +33,11 @@ module.exports = [ .then((copilotOpportunity) => { const plainOpportunity = copilotOpportunity.get({ plain: true }); let canApplyAsCopilot = false; + req.log.info(plainOpportunity.project.members); + req.log.info(req.authUser, 'authuser'); if (plainOpportunity && plainOpportunity.project && plainOpportunity.project.members && req.authUser) { const existingMember = plainOpportunity.project.members.find(item => item.userId === req.authUser.userId); + req.log.info(existingMember, 'existingMember'); canApplyAsCopilot = !!!existingMember; } // This shouldn't be exposed to the clientside From 81effa61744eebed8bcd5e60aa55fe03d17da253 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 18:51:35 +0530 Subject: [PATCH 07/10] fix: send members as part of opportunity --- src/routes/copilotOpportunity/get.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index c574b26d..061d403b 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -32,18 +32,11 @@ module.exports = [ }) .then((copilotOpportunity) => { const plainOpportunity = copilotOpportunity.get({ plain: true }); - let canApplyAsCopilot = false; - req.log.info(plainOpportunity.project.members); - req.log.info(req.authUser, 'authuser'); - if (plainOpportunity && plainOpportunity.project && plainOpportunity.project.members && req.authUser) { - const existingMember = plainOpportunity.project.members.find(item => item.userId === req.authUser.userId); - req.log.info(existingMember, 'existingMember'); - canApplyAsCopilot = !!!existingMember; - } + const memberIds = plainOpportunity.project.members.map((member) => member.userId); // This shouldn't be exposed to the clientside delete plainOpportunity.project.members; const formattedOpportunity = Object.assign({ - canApplyAsCopilot, + members: memberIds, }, plainOpportunity, plainOpportunity.copilotRequest ? plainOpportunity.copilotRequest.data : {}, { copilotRequest: undefined }, From 25b4d80a9e31aa9090b33a53618d4ad3bd9ad696 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 22:16:28 +0530 Subject: [PATCH 08/10] debug auth user --- src/routes/copilotOpportunity/get.js | 1 + src/routes/index.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index 061d403b..2d6af5fa 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -32,6 +32,7 @@ module.exports = [ }) .then((copilotOpportunity) => { const plainOpportunity = copilotOpportunity.get({ plain: true }); + req.log.info("authUser", req.authUser); const memberIds = plainOpportunity.project.members.map((member) => member.userId); // This shouldn't be exposed to the clientside delete plainOpportunity.project.members; diff --git a/src/routes/index.js b/src/routes/index.js index 54df9280..ab3b6308 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -35,9 +35,14 @@ const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator; router.all( RegExp(`\\/${apiVersion}\\/(copilots|projects|timelines|orgConfig|customer-payments)(?!\\/health).*`), (req, res, next) => { - if (publicRoutes.some(routeRegex => routeRegex.test(req.path))) { + let token + if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') { + token = req.headers.authorization.split(' ')[1] + } + if (publicRoutes.some(routeRegex => routeRegex.test(req.path)) && !token) { return next(); } + req.log.info("token available", token); // JWT authentication return jwtAuth(config)(req, res, next); }, From 6080e8e4f1c98e4d4fc785de587593c1894c71ba Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Wed, 18 Jun 2025 23:15:26 +0530 Subject: [PATCH 09/10] debug auth user --- src/routes/copilotOpportunity/get.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index 2d6af5fa..a87a6f98 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -34,10 +34,12 @@ module.exports = [ const plainOpportunity = copilotOpportunity.get({ plain: true }); req.log.info("authUser", req.authUser); const memberIds = plainOpportunity.project.members.map((member) => member.userId); + const canApplyAsCopilot = !memberIds.includes(req.authUser.userId) // This shouldn't be exposed to the clientside delete plainOpportunity.project.members; const formattedOpportunity = Object.assign({ members: memberIds, + canApplyAsCopilot, }, plainOpportunity, plainOpportunity.copilotRequest ? plainOpportunity.copilotRequest.data : {}, { copilotRequest: undefined }, From 6557460df9bbc7ee24714caa47220985e1c18444 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 19 Jun 2025 09:27:33 +0530 Subject: [PATCH 10/10] debug auth user --- src/routes/copilotOpportunity/get.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/copilotOpportunity/get.js b/src/routes/copilotOpportunity/get.js index a87a6f98..2fd1856c 100644 --- a/src/routes/copilotOpportunity/get.js +++ b/src/routes/copilotOpportunity/get.js @@ -33,8 +33,11 @@ module.exports = [ .then((copilotOpportunity) => { const plainOpportunity = copilotOpportunity.get({ plain: true }); req.log.info("authUser", req.authUser); - const memberIds = plainOpportunity.project.members.map((member) => member.userId); - const canApplyAsCopilot = !memberIds.includes(req.authUser.userId) + const memberIds = plainOpportunity.project.members && plainOpportunity.project.members.map((member) => member.userId); + let canApplyAsCopilot = false; + if (req.authUser) { + canApplyAsCopilot = !memberIds.includes(req.authUser.userId) + } // This shouldn't be exposed to the clientside delete plainOpportunity.project.members; const formattedOpportunity = Object.assign({