-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from all commits
f8a6786
596d9b1
9d70104
2eb2d21
f6138fe
8612e02
81effa6
25b4d80
6080e8e
6557460
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 |
---|---|---|
|
@@ -20,12 +20,30 @@ module.exports = [ | |
model: models.Project, | ||
as: 'project', | ||
attributes: ['name'], | ||
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 |
||
include: [ | ||
{ | ||
model: models.ProjectMember, | ||
as: 'members', | ||
attributes: ['id', 'userId', 'role'], | ||
}, | ||
] | ||
}, | ||
], | ||
}) | ||
.then((copilotOpportunity) => { | ||
const plainOpportunity = copilotOpportunity.get({ plain: true }); | ||
const formattedOpportunity = Object.assign({}, plainOpportunity, | ||
req.log.info("authUser", req.authUser); | ||
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. Logging sensitive information such as |
||
const memberIds = plainOpportunity.project.members && plainOpportunity.project.members.map((member) => member.userId); | ||
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 adding a null check for |
||
let canApplyAsCopilot = false; | ||
if (req.authUser) { | ||
canApplyAsCopilot = !memberIds.includes(req.authUser.userId) | ||
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. Ensure |
||
} | ||
// This shouldn't be exposed to the clientside | ||
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 comment on line 40 suggests that |
||
delete plainOpportunity.project.members; | ||
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 adding a check to ensure |
||
const formattedOpportunity = Object.assign({ | ||
members: memberIds, | ||
canApplyAsCopilot, | ||
}, plainOpportunity, | ||
plainOpportunity.copilotRequest ? plainOpportunity.copilotRequest.data : {}, | ||
{ copilotRequest: undefined }, | ||
); | ||
|
There was a problem hiding this comment.
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 theProject
model. This can help prevent potential runtime errors if the association is used with invalid data.