-
Notifications
You must be signed in to change notification settings - Fork 55
feat: allow existing project member to be invited as copilot #835
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
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
25b8b34
fix: removed logic to allow inviting user even if they are already a …
hentrymartin 7831f54
fix: allow copilots to be added even if the existing member
hentrymartin 57a8d00
fix: allow copilots to be added even if the existing member
hentrymartin 1b21d3b
fix: allow copilots to be added even if the existing member
hentrymartin fa13330
fix: allow copilots to be added even if the existing member
hentrymartin 0536910
fix: allow copilots to be added even if the existing member
hentrymartin b67a6ba
fix: allow copilots to be added even if the existing member
hentrymartin f26de03
fix: just switch role if user is already a member
hentrymartin 50d2dac
fix: just switch role if user is already a member
hentrymartin 347caae
fix: debug logs
hentrymartin d4e4033
fix: debug logs
hentrymartin ecb836c
fix: debug logs
hentrymartin 279d2f1
fix: update kafka
hentrymartin 3998114
fix: update kafka
hentrymartin b7c5f95
revert
hentrymartin bebe265
fix: build
hentrymartin 9385156
fix: added error string and already assigned role
hentrymartin fdb09e3
fix: added error string and already assigned role
hentrymartin 2dc0ea2
fix: added error string and already assigned role
hentrymartin 13c8c39
fix: added error string and already assigned role
hentrymartin f73f444
feat: modifications on copilot addition to project
hentrymartin 7fce661
feat: modifications on copilot addition to project
hentrymartin 1f2cba4
feat: modifications on copilot addition to project
hentrymartin 1266652
feat: modifications on copilot addition to project
hentrymartin c701b1e
fix: complete the copilot requests if the incoming role is observer o…
hentrymartin 1d19d15
fix: complete the copilot requests if the incoming role is observer o…
hentrymartin af842b0
fix: complete the copilot requests if the incoming role is observer o…
hentrymartin 0d02782
fix: complete the copilot requests if the incoming role is observer o…
hentrymartin ce575c7
fix: action string
hentrymartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import _ from 'lodash'; | |
import Joi from 'joi'; | ||
import config from 'config'; | ||
import { middleware as tcMiddleware } from 'tc-core-library-js'; | ||
import { Op } from 'sequelize'; | ||
import models from '../../models'; | ||
import util from '../../util'; | ||
import { | ||
|
@@ -299,7 +300,7 @@ module.exports = [ | |
|
||
return []; | ||
}) | ||
.then((inviteUsers) => { | ||
.then(async (inviteUsers) => { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const members = req.context.currentProjectMembers; | ||
const projectId = _.parseInt(req.params.projectId); | ||
// check user handle exists in returned result | ||
|
@@ -322,13 +323,39 @@ module.exports = [ | |
const errorMessageForAlreadyMemberUser = 'User with such handle is already a member of the team.'; | ||
|
||
if (inviteUserIds) { | ||
// remove members already in the team | ||
const existingMembers = _.filter(members, (m) => { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return inviteUserIds.includes(m.userId); | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
req.log.debug(`Existing members: ${JSON.stringify(existingMembers)}`); | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const projectMembers = await models.ProjectMember.findAll({ | ||
where: { | ||
userId: { | ||
[Op.in]: existingMembers.map(item => item.userId), | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
projectId, | ||
} | ||
}); | ||
|
||
req.log.debug(`Existing Project Members: ${JSON.stringify(projectMembers)}`); | ||
|
||
const existingProjectMembersMap = projectMembers.reduce((acc, current) => { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Object.assign({}, acc, { | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[current.userId]: current, | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}, {}); | ||
|
||
req.log.debug(`Existing Project Members Map: ${JSON.stringify(existingProjectMembersMap)}`); | ||
|
||
_.remove(inviteUserIds, u => _.some(members, (m) => { | ||
const isPresent = m.userId === u; | ||
if (isPresent) { | ||
failed.push(_.assign({}, { | ||
handle: getUserHandleById(m.userId, inviteUsers), | ||
message: errorMessageForAlreadyMemberUser, | ||
error: "ALREADY_MEMBER", | ||
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 using a constant or an enum for the error code |
||
role: existingProjectMembersMap[m.userId].role, | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})); | ||
} | ||
return isPresent; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.