-
Notifications
You must be signed in to change notification settings - Fork 56
fix(PM-1168): invite user when assigning as copilot #809
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 4 commits
69eb97a
675858b
613defe
e3303fe
d83097b
68fdf7b
7383c70
aaea12c
35d27e0
1102fdc
fe085cf
42485c5
2d20d16
3ec8ebd
364e74b
d691100
3a4fc53
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import _ from 'lodash'; | ||
import validate from 'express-validation'; | ||
import Joi from 'joi'; | ||
import config from 'config'; | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import models from '../../models'; | ||
import util from '../../util'; | ||
import { PERMISSION } from '../../permissions/constants'; | ||
import { COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS } from '../../constants'; | ||
import { createEvent } from '../../services/busApi'; | ||
import { CONNECT_NOTIFICATION_EVENT, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, EVENT, INVITE_STATUS, PROJECT_MEMBER_ROLE, RESOURCES } from '../../constants'; | ||
|
||
const assignCopilotOpportunityValidations = { | ||
body: Joi.object().keys({ | ||
|
@@ -73,6 +75,63 @@ module.exports = [ | |
throw err; | ||
} | ||
|
||
const project = await models.Project.findOne({ | ||
where: { | ||
id: projectId, | ||
}, | ||
}); | ||
|
||
const applicationUser = await util.getMemberDetailsByUserIds([userId], req.log, req.id)[0]; | ||
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. It seems like |
||
|
||
req.log.info("before create", applicationUser) | ||
|
||
const invite = await models.ProjectMemberInvite.create({ | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
status: INVITE_STATUS.PENDING, | ||
role: PROJECT_MEMBER_ROLE.COPILOT, | ||
userId, | ||
email: applicationUser.email, | ||
}) | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
req.log.info("aftr create", invite) | ||
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 correcting the typo in the log message from 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. Typo in log message: 'aftr' should be corrected to 'after'. |
||
|
||
util.sendResourceToKafkaBus( | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
req, | ||
EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED, | ||
RESOURCES.PROJECT_MEMBER_INVITE, | ||
invite.toJSON()); | ||
|
||
const initiator = await util.getMemberDetailsByUserIds([req.authUser.userId], req.log, req.id); | ||
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. Check if |
||
|
||
const emailEventType = CONNECT_NOTIFICATION_EVENT.PROJECT_MEMBER_EMAIL_INVITE_CREATED; | ||
await createEvent(emailEventType, { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data: { | ||
workManagerUrl: config.get('workManagerUrl'), | ||
accountsAppURL: config.get('accountsAppUrl'), | ||
subject: config.get('inviteEmailSubject'), | ||
projects: [{ | ||
name: project.name, | ||
projectId, | ||
sections: [ | ||
{ | ||
EMAIL_INVITES: true, | ||
title: config.get('inviteEmailSectionTitle'), | ||
projectName: project.name, | ||
projectId, | ||
initiator, | ||
isSSO: util.isSSO(project), | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
], | ||
}], | ||
}, | ||
recipients: [applicationUser.email], | ||
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. It seems like the recipient email has been changed from |
||
version: 'v3', | ||
from: { | ||
name: config.get('EMAIL_INVITE_FROM_NAME'), | ||
email: config.get('EMAIL_INVITE_FROM_EMAIL'), | ||
}, | ||
categories: [`${process.env.NODE_ENV}:${emailEventType}`.toLowerCase()], | ||
}, req.log); | ||
|
||
await models.CopilotRequest.update( | ||
{ status: COPILOT_REQUEST_STATUS.FULFILLED }, | ||
{ where: { id: opportunity.copilotRequestId }, transaction: t }, | ||
|
Uh oh!
There was an error while loading. Please reload this page.