Skip to content

Commit 19bf7fb

Browse files
author
Maksym Mykhailenko
committed
fix: progressive registration for Topcoder users
We don't ask Topcoder User for "Company Name" and "Title" but server requires them, so if they are not yet defined, we set them automatically
1 parent b6423ae commit 19bf7fb

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

src/helpers/permissions.js

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,81 @@
11
import store from '../config/store'
22
import _ from 'lodash'
3+
import {
4+
PROJECT_ROLE_COPILOT,
5+
PROJECT_ROLE_MANAGER,
6+
PROJECT_ROLE_ACCOUNT_MANAGER,
7+
PROJECT_ROLE_CUSTOMER,
8+
PROJECT_ROLE_ACCOUNT_EXECUTIVE,
9+
PROJECT_ROLE_PROGRAM_MANAGER,
10+
PROJECT_ROLE_SOLUTION_ARCHITECT,
11+
PROJECT_ROLE_PROJECT_MANAGER,
12+
13+
ROLE_TOPCODER_USER,
14+
ROLE_CONNECT_COPILOT,
15+
ROLE_CONNECT_MANAGER,
16+
ROLE_CONNECT_ACCOUNT_MANAGER,
17+
ROLE_CONNECT_ADMIN,
18+
ROLE_ADMINISTRATOR,
19+
ROLE_CONNECT_COPILOT_MANAGER,
20+
ROLE_BUSINESS_DEVELOPMENT_REPRESENTATIVE,
21+
ROLE_PRESALES,
22+
ROLE_ACCOUNT_EXECUTIVE,
23+
ROLE_PROGRAM_MANAGER,
24+
ROLE_SOLUTION_ARCHITECT,
25+
ROLE_PROJECT_MANAGER,
26+
} from '../config/constants'
27+
28+
/**
29+
* This list determines default Project Role by Topcoder Role.
30+
*
31+
* - The order of items in this list is IMPORTANT.
32+
* - To determine default Project Role we have to go from TOP to END
33+
* and find the first record which has the Topcoder Role of the user.
34+
* - Always define default Project Role which is allowed for such Topcoder Role
35+
* as per `PROJECT_TO_TOPCODER_ROLES_MATRIX`
36+
*/
37+
export const DEFAULT_PROJECT_ROLE = [
38+
{
39+
topcoderRole: ROLE_ADMINISTRATOR,
40+
projectRole: PROJECT_ROLE_MANAGER,
41+
}, {
42+
topcoderRole: ROLE_CONNECT_ADMIN,
43+
projectRole: PROJECT_ROLE_MANAGER,
44+
}, {
45+
topcoderRole: ROLE_CONNECT_MANAGER,
46+
projectRole: PROJECT_ROLE_MANAGER,
47+
}, {
48+
topcoderRole: ROLE_CONNECT_ACCOUNT_MANAGER,
49+
projectRole: PROJECT_ROLE_ACCOUNT_MANAGER,
50+
}, {
51+
topcoderRole: ROLE_BUSINESS_DEVELOPMENT_REPRESENTATIVE,
52+
projectRole: PROJECT_ROLE_ACCOUNT_MANAGER,
53+
}, {
54+
topcoderRole: ROLE_PRESALES,
55+
projectRole: PROJECT_ROLE_ACCOUNT_MANAGER,
56+
}, {
57+
topcoderRole: ROLE_ACCOUNT_EXECUTIVE,
58+
projectRole: PROJECT_ROLE_ACCOUNT_EXECUTIVE,
59+
}, {
60+
topcoderRole: ROLE_PROGRAM_MANAGER,
61+
projectRole: PROJECT_ROLE_PROGRAM_MANAGER,
62+
}, {
63+
topcoderRole: ROLE_SOLUTION_ARCHITECT,
64+
projectRole: PROJECT_ROLE_SOLUTION_ARCHITECT,
65+
}, {
66+
topcoderRole: ROLE_PROJECT_MANAGER,
67+
projectRole: PROJECT_ROLE_PROJECT_MANAGER,
68+
}, {
69+
topcoderRole: ROLE_CONNECT_COPILOT_MANAGER,
70+
projectRole: PROJECT_ROLE_CUSTOMER,
71+
}, {
72+
topcoderRole: ROLE_CONNECT_COPILOT,
73+
projectRole: PROJECT_ROLE_COPILOT,
74+
}, {
75+
topcoderRole: ROLE_TOPCODER_USER,
76+
projectRole: PROJECT_ROLE_CUSTOMER,
77+
},
78+
]
379

480
/**
581
* Check if user has permission.
@@ -145,4 +221,24 @@ const matchPermissionRule = (permissionRule, user, project) => {
145221
}
146222

147223
return hasProjectRole || hasTopcoderRole
148-
}
224+
}
225+
226+
/**
227+
* Get default Topcoder Roles.
228+
*
229+
* @param {Object} user user
230+
* @param {Array} user.roles user Topcoder roles
231+
*
232+
* @returns {String} project role
233+
*/
234+
export const getDefaultTopcoderRole = (user) => {
235+
for (let i = 0; i < DEFAULT_PROJECT_ROLE.length; i += 1) {
236+
const rule = DEFAULT_PROJECT_ROLE[i]
237+
238+
if (matchPermissionRule({ topcoderRoles: [rule.topcoderRole] }, user)) {
239+
return rule.topcoderRole
240+
}
241+
}
242+
243+
return undefined
244+
}

src/projects/create/components/FillProjectDetails.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
uploadProfilePhoto,
1717
resetProfileSetting,
1818
} from '../../../routes/settings/actions/index'
19+
import { getDefaultTopcoderRole } from '../../../helpers/permissions'
1920
import {
2021
ROLE_CONNECT_COPILOT,
2122
ROLE_CONNECT_MANAGER,
@@ -305,6 +306,14 @@ const mapStateToProps = ({ settings, loadUser }) => {
305306
let isMissingUserInfo = true
306307
const profileSettings = formatProfileSettings(settings.profile.traits)
307308
if (isTopcoderUser) {
309+
// We don't ask Topcoder User for "Company Name" and "Title"
310+
// but server requires them, so if they are not yet defined, we set them automatically
311+
if (!profileSettings.companyName) {
312+
profileSettings.companyName = 'Topcoder'
313+
}
314+
if (!profileSettings.title) {
315+
profileSettings.title = getDefaultTopcoderRole(loadUser.user)
316+
}
308317
isMissingUserInfo =
309318
!profileSettings.firstName ||
310319
!profileSettings.lastName ||

0 commit comments

Comments
 (0)