Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 5bd7bc1

Browse files
authored
Merge pull request #514 from appirio-tech/revert-512-revise_user_challenge_eligibility_logic
Revert "revise user challenge eligibility check"
2 parents 1ed0b21 + 92cf6d8 commit 5bd7bc1

File tree

1 file changed

+4
-66
lines changed

1 file changed

+4
-66
lines changed

initializers/v3client.js

+4-66
Original file line numberDiff line numberDiff line change
@@ -181,85 +181,23 @@ function getGroupMembers(connection, groupId, callback) {
181181
});
182182
}
183183

184-
185-
/**
186-
* Get groups that the current user can access.
187-
*
188-
* @param {Object} connection - the connection object provided by ActionHero
189-
* @param {Function<err, groupIds>} callback - the callback. Receives either an error
190-
* or the list of group's users an array of numeric IDs
191-
*/
192-
function getMemberGroups(connection, callback) {
193-
getToken(connection, function (err, token) {
194-
if (err) {
195-
callback(err);
196-
return;
197-
}
198-
199-
var userId = (connection.caller.userId || 0);
200-
201-
// calls
202-
callService({
203-
url: v3url + 'groups?membershipType=user&memberId=' + userId,
204-
method: 'GET',
205-
headers: {
206-
'Authorization': 'Bearer ' + token
207-
}
208-
}, function (err, body) {
209-
if (err) {
210-
callback(err);
211-
} else {
212-
var groupIds = body.result.content.map(function (item) {
213-
return item.id;
214-
});
215-
216-
var result = [];
217-
218-
groupIds.forEach(function(groupId) {
219-
result.push(groupId);
220-
callService({
221-
url: v3url + 'groups/' + groupId + '/getParentGroup?oneLevel=false',
222-
method: 'GET',
223-
headers: {
224-
'Authorization': 'Bearer ' + token
225-
}
226-
}, function (err, body) {
227-
if (err) {
228-
callback(err);
229-
} else {
230-
var groupResponse = body.result.content;
231-
while(groupResponse) {
232-
result.push(groupResponse.id);
233-
groupResponse = groupResponse.parentGroup;
234-
}
235-
}
236-
})
237-
});
238-
239-
callback(null, result);
240-
}
241-
});
242-
});
243-
}
244-
245-
246-
247184
exports.v3client = function (api, next) {
248185
api.v3client = {
249186
/**
250187
* Check if the user belongs to the group
251188
*
252189
* @param {Object} connection - the connection object provided by ActionHero
190+
* @param {Number} userId - the user ID
253191
* @param {Number} groupId - the group ID
254192
* @param {Function<err, isIn>} callback - the callback. The second parameter
255193
* is boolean vwhich is true if the user is found in the group.
256194
*/
257-
isUserInGroup: function (connection, groupId, callback) {
258-
getMemberGroups(connection, groupId, function (err, groupIds) {
195+
isUserInGroup: function (connection, userId, groupId, callback) {
196+
getGroupMembers(connection, groupId, function (err, members) {
259197
if (err) {
260198
callback(err);
261199
} else {
262-
callback(null, groupIds.indexOf(groupId) >= 0);
200+
callback(null, members.indexOf(userId) >= 0);
263201
}
264202
});
265203
}

0 commit comments

Comments
 (0)