Skip to content

Commit c44dd43

Browse files
authored
feat: remove copilot members and invites (#594)
* feat: remove copilot members and invites * fix: unit test * fix: invite create unit test and debug * fix: debug unit tests * fix: more debug * fix: more debug * fix: more debug * fix: more debug * fix: Copilot Manager token for unit tests * fix: remove debugging
1 parent 8d2b09a commit c44dd43

File tree

10 files changed

+200
-73
lines changed

10 files changed

+200
-73
lines changed

docs/permissions.html

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -523,19 +523,19 @@ <h2 class="anchor-container">
523523
<div class="row border-top">
524524
<div class="col py-2">
525525
<div class="permission-title anchor-container">
526-
<a href="#UPDATE_PROJECT_MEMBER_TO_COPILOT" name="UPDATE_PROJECT_MEMBER_TO_COPILOT" class="anchor"></a>Update Project Member (to copilot)
526+
<a href="#DELETE_PROJECT_MEMBER_CUSTOMER" name="DELETE_PROJECT_MEMBER_CUSTOMER" class="anchor"></a>Delete Project Member (customer)
527527
</div>
528-
<div class="permission-variable"><small><code>UPDATE_PROJECT_MEMBER_TO_COPILOT</code></small></div>
529-
<div class="text-black-50 small-text">Who can update project member role to &quot;copilot&quot;.</div>
528+
<div class="permission-variable"><small><code>DELETE_PROJECT_MEMBER_CUSTOMER</code></small></div>
529+
<div class="text-black-50 small-text">Who can delete project members with &quot;customer&quot; role.</div>
530530
</div>
531531
<div class="col-9 py-2">
532532
<div>
533+
<span class="badge badge-primary" title="Allowed">Any Project Member</span>
533534
</div>
534535

535536
<div>
536537
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Admin</span>
537538
<span class="badge badge-success" title="Allowed Topcoder Role">administrator</span>
538-
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Copilot Manager</span>
539539
</div>
540540

541541
<div>
@@ -548,14 +548,19 @@ <h2 class="anchor-container">
548548
<div class="row border-top">
549549
<div class="col py-2">
550550
<div class="permission-title anchor-container">
551-
<a href="#DELETE_PROJECT_MEMBER_CUSTOMER" name="DELETE_PROJECT_MEMBER_CUSTOMER" class="anchor"></a>Delete Project Member (customer)
551+
<a href="#DELETE_PROJECT_MEMBER_TOPCODER" name="DELETE_PROJECT_MEMBER_TOPCODER" class="anchor"></a>Delete Project Member (topcoder)
552552
</div>
553-
<div class="permission-variable"><small><code>DELETE_PROJECT_MEMBER_CUSTOMER</code></small></div>
554-
<div class="text-black-50 small-text">Who can delete project members with &quot;customer&quot; role.</div>
553+
<div class="permission-variable"><small><code>DELETE_PROJECT_MEMBER_TOPCODER</code></small></div>
554+
<div class="text-black-50 small-text">Who can delete project members with some topcoder role like &quot;manager&quot; etc.</div>
555555
</div>
556556
<div class="col-9 py-2">
557557
<div>
558-
<span class="badge badge-primary" title="Allowed">Any Project Member</span>
558+
<span class="badge badge-primary" title="Allowed Project Role">manager</span>
559+
<span class="badge badge-primary" title="Allowed Project Role">account_manager</span>
560+
<span class="badge badge-primary" title="Allowed Project Role">program_manager</span>
561+
<span class="badge badge-primary" title="Allowed Project Role">account_executive</span>
562+
<span class="badge badge-primary" title="Allowed Project Role">solution_architect</span>
563+
<span class="badge badge-primary" title="Allowed Project Role">project_manager</span>
559564
</div>
560565

561566
<div>
@@ -573,24 +578,20 @@ <h2 class="anchor-container">
573578
<div class="row border-top">
574579
<div class="col py-2">
575580
<div class="permission-title anchor-container">
576-
<a href="#DELETE_PROJECT_MEMBER_NON_CUSTOMER" name="DELETE_PROJECT_MEMBER_NON_CUSTOMER" class="anchor"></a>Delete Project Member (non-customer)
581+
<a href="#DELETE_PROJECT_MEMBER_COPILOT" name="DELETE_PROJECT_MEMBER_COPILOT" class="anchor"></a>Delete Project Member (copilot)
577582
</div>
578-
<div class="permission-variable"><small><code>DELETE_PROJECT_MEMBER_NON_CUSTOMER</code></small></div>
579-
<div class="text-black-50 small-text">Who can delete project members with non &quot;customer&quot; role.</div>
583+
<div class="permission-variable"><small><code>DELETE_PROJECT_MEMBER_COPILOT</code></small></div>
584+
<div class="text-black-50 small-text">Who can delete project members with &quot;copilot&quot; role.</div>
580585
</div>
581586
<div class="col-9 py-2">
582587
<div>
583-
<span class="badge badge-primary" title="Allowed Project Role">manager</span>
584-
<span class="badge badge-primary" title="Allowed Project Role">account_manager</span>
585-
<span class="badge badge-primary" title="Allowed Project Role">program_manager</span>
586-
<span class="badge badge-primary" title="Allowed Project Role">account_executive</span>
587-
<span class="badge badge-primary" title="Allowed Project Role">solution_architect</span>
588-
<span class="badge badge-primary" title="Allowed Project Role">project_manager</span>
588+
<span class="badge badge-primary" title="Allowed">Any Project Member</span>
589589
</div>
590590

591591
<div>
592592
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Admin</span>
593593
<span class="badge badge-success" title="Allowed Topcoder Role">administrator</span>
594+
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Copilot Manager</span>
594595
</div>
595596

596597
<div>
@@ -680,15 +681,6 @@ <h2 class="anchor-container">
680681
<div>
681682
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Admin</span>
682683
<span class="badge badge-success" title="Allowed Topcoder Role">administrator</span>
683-
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Manager</span>
684-
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Account Manager</span>
685-
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Copilot Manager</span>
686-
<span class="badge badge-success" title="Allowed Topcoder Role">Business Development Representative</span>
687-
<span class="badge badge-success" title="Allowed Topcoder Role">Presales</span>
688-
<span class="badge badge-success" title="Allowed Topcoder Role">Account Executive</span>
689-
<span class="badge badge-success" title="Allowed Topcoder Role">Program Manager</span>
690-
<span class="badge badge-success" title="Allowed Topcoder Role">Solution Architect</span>
691-
<span class="badge badge-success" title="Allowed Topcoder Role">Project Manager</span>
692684
</div>
693685

694686
<div>
@@ -701,10 +693,10 @@ <h2 class="anchor-container">
701693
<div class="row border-top">
702694
<div class="col py-2">
703695
<div class="permission-title anchor-container">
704-
<a href="#CREATE_PROJECT_INVITE_NON_CUSTOMER" name="CREATE_PROJECT_INVITE_NON_CUSTOMER" class="anchor"></a>Create Project Invite (non-customer)
696+
<a href="#CREATE_PROJECT_INVITE_TOPCODER" name="CREATE_PROJECT_INVITE_TOPCODER" class="anchor"></a>Create Project Invite (topcoder)
705697
</div>
706-
<div class="permission-variable"><small><code>CREATE_PROJECT_INVITE_NON_CUSTOMER</code></small></div>
707-
<div class="text-black-50 small-text">Who can invite project members with non &quot;customer&quot; role.</div>
698+
<div class="permission-variable"><small><code>CREATE_PROJECT_INVITE_TOPCODER</code></small></div>
699+
<div class="text-black-50 small-text">Who can invite project members with topcoder role like &quot;manager&quot; etc.</div>
708700
</div>
709701
<div class="col-9 py-2">
710702
<div>
@@ -731,9 +723,9 @@ <h2 class="anchor-container">
731723
<div class="row border-top">
732724
<div class="col py-2">
733725
<div class="permission-title anchor-container">
734-
<a href="#CREATE_PROJECT_INVITE_COPILOT_DIRECTLY" name="CREATE_PROJECT_INVITE_COPILOT_DIRECTLY" class="anchor"></a>Create Project Invite (copilot)
726+
<a href="#CREATE_PROJECT_INVITE_COPILOT" name="CREATE_PROJECT_INVITE_COPILOT" class="anchor"></a>Create Project Invite (copilot)
735727
</div>
736-
<div class="permission-variable"><small><code>CREATE_PROJECT_INVITE_COPILOT_DIRECTLY</code></small></div>
728+
<div class="permission-variable"><small><code>CREATE_PROJECT_INVITE_COPILOT</code></small></div>
737729
<div class="text-black-50 small-text">Who can invite user with &quot;copilot&quot; role directly without requesting.</div>
738730
</div>
739731
<div class="col-9 py-2">
@@ -876,10 +868,40 @@ <h2 class="anchor-container">
876868
<div class="row border-top">
877869
<div class="col py-2">
878870
<div class="permission-title anchor-container">
879-
<a href="#DELETE_PROJECT_INVITE_NOT_OWN_NON_CUSTOMER" name="DELETE_PROJECT_INVITE_NOT_OWN_NON_CUSTOMER" class="anchor"></a>Delete Project Invite (not own, non-customer)
871+
<a href="#DELETE_PROJECT_INVITE_NOT_OWN_TOPCODER" name="DELETE_PROJECT_INVITE_NOT_OWN_TOPCODER" class="anchor"></a>Delete Project Invite (not own, topcoder)
872+
</div>
873+
<div class="permission-variable"><small><code>DELETE_PROJECT_INVITE_NOT_OWN_TOPCODER</code></small></div>
874+
<div class="text-black-50 small-text">Who can delete project invites for other members with some topcoder role like &quot;manager&quot; etc.</div>
875+
</div>
876+
<div class="col-9 py-2">
877+
<div>
878+
<span class="badge badge-primary" title="Allowed Project Role">manager</span>
879+
<span class="badge badge-primary" title="Allowed Project Role">account_manager</span>
880+
<span class="badge badge-primary" title="Allowed Project Role">program_manager</span>
881+
<span class="badge badge-primary" title="Allowed Project Role">account_executive</span>
882+
<span class="badge badge-primary" title="Allowed Project Role">solution_architect</span>
883+
<span class="badge badge-primary" title="Allowed Project Role">project_manager</span>
884+
</div>
885+
886+
<div>
887+
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Admin</span>
888+
<span class="badge badge-success" title="Allowed Topcoder Role">administrator</span>
889+
</div>
890+
891+
<div>
892+
<span class="badge badge-dark" title="Allowed Topcoder Role">all:connect_project</span>
893+
<span class="badge badge-dark" title="Allowed Topcoder Role">all:project-invites</span>
894+
<span class="badge badge-dark" title="Allowed Topcoder Role">write:project-invites</span>
895+
</div>
896+
</div>
897+
</div>
898+
<div class="row border-top">
899+
<div class="col py-2">
900+
<div class="permission-title anchor-container">
901+
<a href="#DELETE_PROJECT_INVITE_NOT_OWN_COPILOT" name="DELETE_PROJECT_INVITE_NOT_OWN_COPILOT" class="anchor"></a>Delete Project Invite (not own, copilot)
880902
</div>
881-
<div class="permission-variable"><small><code>DELETE_PROJECT_INVITE_NOT_OWN_NON_CUSTOMER</code></small></div>
882-
<div class="text-black-50 small-text">Who can delete project invites for other members with non &quot;customer&quot; role.</div>
903+
<div class="permission-variable"><small><code>DELETE_PROJECT_INVITE_NOT_OWN_COPILOT</code></small></div>
904+
<div class="text-black-50 small-text">Who can delete invites for other members with &quot;copilot&quot; role.</div>
883905
</div>
884906
<div class="col-9 py-2">
885907
<div>
@@ -894,6 +916,7 @@ <h2 class="anchor-container">
894916
<div>
895917
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Admin</span>
896918
<span class="badge badge-success" title="Allowed Topcoder Role">administrator</span>
919+
<span class="badge badge-success" title="Allowed Topcoder Role">Connect Copilot Manager</span>
897920
</div>
898921

899922
<div>

src/permissions/constants.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,6 @@ export const PERMISSION = { // eslint-disable-line import/prefer-default-export
306306
scopes: SCOPES_PROJECT_MEMBERS_WRITE,
307307
},
308308

309-
UPDATE_PROJECT_MEMBER_TO_COPILOT: {
310-
meta: {
311-
title: 'Update Project Member (to copilot)',
312-
group: 'Project Member',
313-
description: 'Who can update project member role to "copilot".',
314-
},
315-
topcoderRoles: [
316-
...TOPCODER_ROLES_ADMINS,
317-
USER_ROLE.COPILOT_MANAGER,
318-
],
319-
scopes: SCOPES_PROJECT_MEMBERS_WRITE,
320-
},
321-
322309
DELETE_PROJECT_MEMBER_CUSTOMER: {
323310
meta: {
324311
title: 'Delete Project Member (customer)',
@@ -330,17 +317,31 @@ export const PERMISSION = { // eslint-disable-line import/prefer-default-export
330317
scopes: SCOPES_PROJECT_MEMBERS_WRITE,
331318
},
332319

333-
DELETE_PROJECT_MEMBER_NON_CUSTOMER: {
320+
DELETE_PROJECT_MEMBER_TOPCODER: {
334321
meta: {
335-
title: 'Delete Project Member (non-customer)',
322+
title: 'Delete Project Member (topcoder)',
336323
group: 'Project Member',
337-
description: 'Who can delete project members with non "customer" role.',
324+
description: 'Who can delete project members with some topcoder role like "manager" etc.',
338325
},
339326
topcoderRoles: TOPCODER_ROLES_ADMINS,
340327
projectRoles: PROJECT_ROLES_MANAGEMENT,
341328
scopes: SCOPES_PROJECT_MEMBERS_WRITE,
342329
},
343330

331+
DELETE_PROJECT_MEMBER_COPILOT: {
332+
meta: {
333+
title: 'Delete Project Member (copilot)',
334+
group: 'Project Member',
335+
description: 'Who can delete project members with "copilot" role.',
336+
},
337+
topcoderRoles: [
338+
...TOPCODER_ROLES_ADMINS,
339+
USER_ROLE.COPILOT_MANAGER,
340+
],
341+
projectRoles: ALL,
342+
scopes: SCOPES_PROJECT_MEMBERS_WRITE,
343+
},
344+
344345
/*
345346
* Project Invite
346347
*/
@@ -371,23 +372,23 @@ export const PERMISSION = { // eslint-disable-line import/prefer-default-export
371372
group: 'Project Invite',
372373
description: 'Who can invite project members with "customer" role.',
373374
},
374-
topcoderRoles: TOPCODER_ROLES_MANAGERS_AND_ADMINS,
375+
topcoderRoles: TOPCODER_ROLES_ADMINS,
375376
projectRoles: ALL,
376377
scopes: SCOPES_PROJECT_INVITES_WRITE,
377378
},
378379

379-
CREATE_PROJECT_INVITE_NON_CUSTOMER: {
380+
CREATE_PROJECT_INVITE_TOPCODER: {
380381
meta: {
381-
title: 'Create Project Invite (non-customer)',
382+
title: 'Create Project Invite (topcoder)',
382383
group: 'Project Invite',
383-
description: 'Who can invite project members with non "customer" role.',
384+
description: 'Who can invite project members with topcoder role like "manager" etc.',
384385
},
385386
topcoderRoles: TOPCODER_ROLES_ADMINS,
386387
projectRoles: PROJECT_ROLES_MANAGEMENT,
387388
scopes: SCOPES_PROJECT_INVITES_WRITE,
388389
},
389390

390-
CREATE_PROJECT_INVITE_COPILOT_DIRECTLY: {
391+
CREATE_PROJECT_INVITE_COPILOT: {
391392
meta: {
392393
title: 'Create Project Invite (copilot)',
393394
group: 'Project Invite',
@@ -454,17 +455,31 @@ export const PERMISSION = { // eslint-disable-line import/prefer-default-export
454455
scopes: SCOPES_PROJECT_INVITES_WRITE,
455456
},
456457

457-
DELETE_PROJECT_INVITE_NOT_OWN_NON_CUSTOMER: {
458+
DELETE_PROJECT_INVITE_NOT_OWN_TOPCODER: {
458459
meta: {
459-
title: 'Delete Project Invite (not own, non-customer)',
460+
title: 'Delete Project Invite (not own, topcoder)',
460461
group: 'Project Invite',
461-
description: 'Who can delete project invites for other members with non "customer" role.',
462+
description: 'Who can delete project invites for other members with some topcoder role like "manager" etc.',
462463
},
463464
topcoderRoles: TOPCODER_ROLES_ADMINS,
464465
projectRoles: PROJECT_ROLES_MANAGEMENT,
465466
scopes: SCOPES_PROJECT_INVITES_WRITE,
466467
},
467468

469+
DELETE_PROJECT_INVITE_NOT_OWN_COPILOT: {
470+
meta: {
471+
title: 'Delete Project Invite (not own, copilot)',
472+
group: 'Project Invite',
473+
description: 'Who can delete invites for other members with "copilot" role.',
474+
},
475+
topcoderRoles: [
476+
...TOPCODER_ROLES_ADMINS,
477+
USER_ROLE.COPILOT_MANAGER,
478+
],
479+
projectRoles: PROJECT_ROLES_MANAGEMENT,
480+
scopes: SCOPES_PROJECT_INVITES_WRITE,
481+
},
482+
468483
DELETE_PROJECT_INVITE_REQUESTED: {
469484
meta: {
470485
title: 'Delete Project Invite (requested)',

src/permissions/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ module.exports = () => {
3131
]));
3232
Authorizer.setPolicy('projectMember.delete', generalPermission([
3333
PERMISSION.DELETE_PROJECT_MEMBER_CUSTOMER,
34-
PERMISSION.DELETE_PROJECT_MEMBER_NON_CUSTOMER,
34+
PERMISSION.DELETE_PROJECT_MEMBER_TOPCODER,
35+
PERMISSION.DELETE_PROJECT_MEMBER_COPILOT,
3536
]));
3637

3738
Authorizer.setPolicy('projectMemberInvite.create', generalPermission([
3839
PERMISSION.CREATE_PROJECT_INVITE_CUSTOMER,
39-
PERMISSION.CREATE_PROJECT_INVITE_NON_CUSTOMER,
40+
PERMISSION.CREATE_PROJECT_INVITE_TOPCODER,
41+
PERMISSION.CREATE_PROJECT_INVITE_COPILOT,
4042
]));
4143
Authorizer.setPolicy('projectMemberInvite.view', generalPermission([
4244
PERMISSION.READ_PROJECT_INVITE_OWN,
@@ -49,7 +51,8 @@ module.exports = () => {
4951
Authorizer.setPolicy('projectMemberInvite.delete', generalPermission([
5052
PERMISSION.DELETE_PROJECT_INVITE_OWN,
5153
PERMISSION.DELETE_PROJECT_INVITE_NOT_OWN_CUSTOMER,
52-
PERMISSION.DELETE_PROJECT_INVITE_NOT_OWN_NON_CUSTOMER,
54+
PERMISSION.DELETE_PROJECT_INVITE_NOT_OWN_COPILOT,
55+
PERMISSION.DELETE_PROJECT_INVITE_NOT_OWN_TOPCODER,
5356
]));
5457

5558
Authorizer.setPolicy('projectAttachment.create', generalPermission(PERMISSION.CREATE_PROJECT_ATTACHMENT));

src/routes/projectMemberInvites/create.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,14 @@ module.exports = [
274274
}
275275

276276
if (
277-
invite.role !== PROJECT_MEMBER_ROLE.CUSTOMER &&
278-
!util.hasPermissionByReq(PERMISSION.CREATE_PROJECT_INVITE_NON_CUSTOMER, req)
277+
( // if cannot invite non-customer user
278+
invite.role !== PROJECT_MEMBER_ROLE.CUSTOMER &&
279+
!util.hasPermissionByReq(PERMISSION.CREATE_PROJECT_INVITE_TOPCODER, req)
280+
) && !(
281+
// and if cannot invite copilot directly
282+
invite.role === PROJECT_MEMBER_ROLE.COPILOT &&
283+
util.hasPermissionByReq(PERMISSION.CREATE_PROJECT_INVITE_COPILOT, req)
284+
)
279285
) {
280286
const err = new Error(`You are not allowed to invite user as ${invite.role}.`);
281287
err.status = 403;
@@ -373,7 +379,7 @@ module.exports = [
373379
role: invite.role,
374380
// invite copilots directly if user has permissions
375381
status: (invite.role !== PROJECT_MEMBER_ROLE.COPILOT ||
376-
util.hasPermissionByReq(PERMISSION.CREATE_PROJECT_INVITE_COPILOT_DIRECTLY, req))
382+
util.hasPermissionByReq(PERMISSION.CREATE_PROJECT_INVITE_COPILOT, req))
377383
? INVITE_STATUS.PENDING
378384
: INVITE_STATUS.REQUESTED,
379385
createdBy: req.authUser.userId,

0 commit comments

Comments
 (0)