Skip to content

fix(PM-1273): Send canApplyAsCopilot to check if the user can apply for the opportunity #824

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

Merged
merged 10 commits into from
Jun 19, 2025

Conversation

hentrymartin
Copy link
Collaborator

@hentrymartin hentrymartin commented Jun 18, 2025

What's in this PR?

  • Send project members as part of copilot request get API

Ticket link - https://topcoder.atlassian.net/browse/PM-1273

@@ -20,6 +20,13 @@ module.exports = [
model: models.Project,
as: 'project',
attributes: ['name'],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attributes array on line 22 originally included 'members', which has now been moved to a separate include block. Ensure that this change aligns with the intended data structure and that the 'members' attribute is correctly populated in the response.

@@ -34,6 +34,10 @@ module.exports = function defineProjectMember(sequelize, DataTypes) {
],
});

ProjectMember.associate = (models) => {
ProjectMember.belongsTo(models.Project, { foreignKey: 'projectId' });
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding validation or error handling for the association to ensure that the projectId foreign key is valid and exists in the Project model. This can help prevent potential runtime errors if the association is used with invalid data.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using !!!existingMember is confusing and can lead to readability issues. Consider using !existingMember to clearly express the intent of checking for non-existence.

const existingMember = plainOpportunity.project.members.find(item => item.userId === req.authUser.userId);
canApplyAsCopilot = !!!existingMember;
}
// This shouldn't be exposed to the clientside

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 40 suggests that plainOpportunity.project.members should not be exposed to the client-side. Ensure that this deletion is handled securely and that no sensitive information is inadvertently exposed elsewhere in the code.

},
],
})
.then((copilotOpportunity) => {
const plainOpportunity = copilotOpportunity.get({ plain: true });
const formattedOpportunity = Object.assign({}, plainOpportunity,
let canApplyAsCopilot = false;
req.log.info(plainOpportunity.project.members);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging sensitive information such as project members can lead to security issues. Consider removing or sanitizing this log statement.

const formattedOpportunity = Object.assign({}, plainOpportunity,
let canApplyAsCopilot = false;
req.log.info(plainOpportunity.project.members);
req.log.info(req.authUser, 'authuser');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the entire authUser object may expose sensitive user information. Consider logging only non-sensitive parts of the object.

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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that logging existingMember does not expose any sensitive information. Consider logging only necessary details or removing this log statement.

},
],
})
.then((copilotOpportunity) => {
const plainOpportunity = copilotOpportunity.get({ plain: true });
const formattedOpportunity = Object.assign({}, plainOpportunity,
const memberIds = plainOpportunity.project.members.map((member) => member.userId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable memberIds is being created by mapping over plainOpportunity.project.members. Ensure that plainOpportunity.project.members is defined before attempting to map over it to avoid potential runtime errors.

const formattedOpportunity = Object.assign({}, plainOpportunity,
const memberIds = plainOpportunity.project.members.map((member) => member.userId);
// This shouldn't be exposed to the clientside
delete plainOpportunity.project.members;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a check to ensure plainOpportunity.project exists before attempting to delete plainOpportunity.project.members to prevent potential errors if project is undefined.

@hentrymartin hentrymartin changed the title [Work in progress] fix(PM-1273): Send project members as part of copilot request get API fix(PM-1273): Send project members as part of copilot request get API Jun 18, 2025
@hentrymartin hentrymartin requested a review from kkartunov June 18, 2025 15:39
},
],
})
.then((copilotOpportunity) => {
const plainOpportunity = copilotOpportunity.get({ plain: true });
const formattedOpportunity = Object.assign({}, plainOpportunity,
req.log.info("authUser", req.authUser);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging sensitive information such as authUser can pose security risks if it contains personal or sensitive data. Consider reviewing what information is being logged and ensure it complies with security best practices.

const formattedOpportunity = Object.assign({}, plainOpportunity,
req.log.info("authUser", req.authUser);
const memberIds = plainOpportunity.project.members.map((member) => member.userId);
const canApplyAsCopilot = !memberIds.includes(req.authUser.userId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a check to ensure req.authUser and req.authUser.userId are defined before attempting to access userId. This will prevent potential runtime errors if req.authUser is undefined.

},
],
})
.then((copilotOpportunity) => {
const plainOpportunity = copilotOpportunity.get({ plain: true });
const formattedOpportunity = Object.assign({}, plainOpportunity,
req.log.info("authUser", req.authUser);
const memberIds = plainOpportunity.project.members && plainOpportunity.project.members.map((member) => member.userId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a null check for plainOpportunity.project before accessing members to prevent potential runtime errors if project is undefined.

const memberIds = plainOpportunity.project.members && plainOpportunity.project.members.map((member) => member.userId);
let canApplyAsCopilot = false;
if (req.authUser) {
canApplyAsCopilot = !memberIds.includes(req.authUser.userId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure memberIds is properly initialized before calling includes to avoid errors if plainOpportunity.project.members is null or undefined.

@hentrymartin hentrymartin changed the title fix(PM-1273): Send project members as part of copilot request get API fix(PM-1273): Send canApplyAsCopilot to check if the user can apply for the opportunity Jun 19, 2025
@kkartunov kkartunov merged commit 8e30d1b into develop Jun 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants