Skip to content

Commit da9209c

Browse files
authored
Merge pull request #91 from topcoder-platform/justin-fixes
Justin fixes
2 parents d330ccc + 7788ed6 commit da9209c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

app-constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* App constants
33
*/
44
const ADMIN_ROLES = ['administrator', 'admin']
5+
const AUTOCOMPLETE_ROLES = ['copilot', 'administrator', 'admin', 'Connect Copilot', 'Connect Account Manager', 'Connect Admin', 'Account Executive']
56

67
const EVENT_ORIGINATOR = 'topcoder-member-api'
78

@@ -26,6 +27,7 @@ const MAMBO_GET_REWARDS_ALLOWED_FIELDS = [
2627

2728
module.exports = {
2829
ADMIN_ROLES,
30+
AUTOCOMPLETE_ROLES,
2931
EVENT_ORIGINATOR,
3032
EVENT_MIME_TYPE,
3133
TOPICS,

src/common/helper.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ function hasAdminRole (authUser) {
111111
return false
112112
}
113113

114+
/**
115+
* Check if the user has autocomplete role
116+
* @param {Object} authUser the user
117+
* @returns {Boolean} whether the user has autocomplete role
118+
*/
119+
function hasAutocompleteRole (authUser) {
120+
if (!authUser.roles) {
121+
return false
122+
}
123+
for (let i = 0; i < authUser.roles.length; i += 1) {
124+
for (let j = 0; j < constants.AUTOCOMPLETE_ROLES.length; j += 1) {
125+
if (authUser.roles[i].toLowerCase() === constants.AUTOCOMPLETE_ROLES[j].toLowerCase()) {
126+
return true
127+
}
128+
}
129+
}
130+
return false
131+
}
132+
114133
/**
115134
* Check if exists.
116135
*
@@ -751,6 +770,7 @@ module.exports = {
751770
autoWrapExpress,
752771
checkIfExists,
753772
hasAdminRole,
773+
hasAutocompleteRole,
754774
getMemberByHandle,
755775
getEntityByHashKey,
756776
getEntityByHashRangeKey,

src/routes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = {
2828
controller: 'SearchController',
2929
method: 'autocomplete',
3030
auth: 'jwt',
31-
allowNoToken: true,
3231
scopes: [MEMBERS.READ, MEMBERS.ALL]
3332
}
3433
},
@@ -37,7 +36,6 @@ module.exports = {
3736
controller: 'SearchController',
3837
method: 'autocomplete',
3938
auth: 'jwt',
40-
allowNoToken: true,
4139
scopes: [MEMBERS.READ, MEMBERS.ALL]
4240
}
4341
},

src/services/SearchService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MEMBER_FIELDS = ['userId', 'handle', 'handleLower', 'firstName', 'lastName
1414
'description', 'email', 'tracks', 'maxRating', 'wins', 'createdAt', 'createdBy',
1515
'updatedAt', 'updatedBy', 'skills', 'stats']
1616

17-
const MEMBER_AUTOCOMPLETE_FIELDS = ['userId', 'handle', 'handleLower', 'firstName', 'lastName',
17+
const MEMBER_AUTOCOMPLETE_FIELDS = ['userId', 'handle', 'handleLower',
1818
'status', 'email', 'createdAt', 'updatedAt']
1919

2020
var MEMBER_STATS_FIELDS = ['userId', 'handle', 'handleLower', 'maxRating',
@@ -124,11 +124,11 @@ searchMembers.schema = {
124124
async function autocomplete (currentUser, query) {
125125
// validate and parse fields param
126126
let fields = helper.parseCommaSeparatedString(query.fields, MEMBER_AUTOCOMPLETE_FIELDS) || MEMBER_AUTOCOMPLETE_FIELDS
127-
// // if current user is not admin and not M2M, then exclude the admin/M2M only fields
128-
// if (!currentUser || (!currentUser.isMachine && !helper.hasAdminRole(currentUser))) {
129-
// fields = _.without(fields, ...config.SEARCH_SECURE_FIELDS)
130-
// // MEMBER_AUTOCOMPLETE_FIELDS = _.without(MEMBER_AUTOCOMPLETE_FIELDS, ...config.STATISTICS_SECURE_FIELDS)
131-
// }
127+
// if current user is not autocomplete role and not M2M, then exclude the autocomplete/M2M only fields
128+
if (!currentUser || (!currentUser.isMachine && !helper.hasAutocompleteRole(currentUser))) {
129+
fields = _.without(fields, ...config.SEARCH_SECURE_FIELDS)
130+
// MEMBER_AUTOCOMPLETE_FIELDS = _.without(MEMBER_AUTOCOMPLETE_FIELDS, ...config.STATISTICS_SECURE_FIELDS)
131+
}
132132
// get suggestion based on querys term
133133
const docsSuggestions = await eshelper.getSuggestion(query, esClient, currentUser)
134134
if (docsSuggestions.hasOwnProperty('suggest')) {

0 commit comments

Comments
 (0)