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

Commit 2598a5a

Browse files
committed
Merge branch 'dev' of github.com:appirio-tech/tc-api into dev
2 parents ea5b9e7 + 4cf63ba commit 2598a5a

10 files changed

+161
-17
lines changed

actions/challenges.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ exports.getChallengeTerms = {
22372237
description: "getChallengeTerms",
22382238
inputs: {
22392239
required: ["challengeId"],
2240-
optional: ["role"]
2240+
optional: ["role", "noauth"]
22412241
},
22422242
blockedConnectionTypes: [],
22432243
outputExample: {},
@@ -2251,14 +2251,26 @@ exports.getChallengeTerms = {
22512251
var challengeId = Number(connection.params.challengeId), role = connection.params.role, error;
22522252
async.waterfall([
22532253
function (cb) {
2254-
api.challengeHelper.getChallengeTerms(
2255-
connection,
2256-
challengeId,
2257-
role,
2258-
true,
2259-
connection.dbConnectionMap,
2260-
cb
2261-
);
2254+
if (connection.params.noauth) {
2255+
api.challengeHelper.getChallengeTermsNoAuth(
2256+
connection,
2257+
challengeId,
2258+
role,
2259+
true,
2260+
connection.dbConnectionMap,
2261+
cb
2262+
);
2263+
}
2264+
else {
2265+
api.challengeHelper.getChallengeTerms(
2266+
connection,
2267+
challengeId,
2268+
role,
2269+
true,
2270+
connection.dbConnectionMap,
2271+
cb
2272+
);
2273+
}
22622274
}, function (results, cb) {
22632275
var res = _.find(results, function (row) {
22642276
return row.agreeabilityType === 'DocuSignable' && !row.templateId;

actions/terms.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,25 @@ function validateTermsOfUseId(connection, helper, sqlParams, callback) {
4949
var getTermsOfUse = function (api, connection, dbConnectionMap, next) {
5050
var helper = api.helper,
5151
sqlParams = {},
52-
result = {};
52+
result = {},
53+
noauth = connection.params.noauth == "true";
5354

5455
//Check if the user is logged-in
55-
if (connection.caller.accessLevel === "anon") {
56+
if (!noauth && connection.caller.accessLevel === "anon") {
5657
helper.handleError(api, connection, new UnauthorizedError("Authentication credential was missing."));
5758
next(connection, true);
5859
return;
5960
}
6061

61-
sqlParams.userId = connection.caller.userId;
62+
sqlParams.userId = connection.caller ? connection.caller.userId || '' : '';
6263

6364
async.waterfall([
6465
function (cb) {
6566
// validate termsOfUseId parameter and set sql parameter
6667
validateTermsOfUseId(connection, helper, sqlParams, cb);
6768
},
6869
function (cb) {
69-
api.dataAccess.executeQuery("get_terms_of_use", sqlParams, dbConnectionMap, cb);
70+
api.dataAccess.executeQuery(noauth ? "get_terms_of_use_noauth" : "get_terms_of_use", sqlParams, dbConnectionMap, cb);
7071
}, function (rows, cb) {
7172
if (rows.length === 0) {
7273
cb(new NotFoundError('No such terms of use exists.'));
@@ -211,7 +212,7 @@ exports.getTermsOfUse = {
211212
description: "getTermsOfUse",
212213
inputs: {
213214
required: ["termsOfUseId"],
214-
optional: []
215+
optional: ["noauth"]
215216
},
216217
blockedConnectionTypes: [],
217218
outputExample: {},

initializers/challengeHelper.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,96 @@ exports.challengeHelper = function (api, next) {
228228
}
229229
next(null, result.terms);
230230
});
231+
},
232+
getChallengeTermsNoAuth : function (connection, challengeId, role, requireRegOpen, dbConnectionMap, next) {
233+
234+
var helper = api.helper,
235+
sqlParams = {},
236+
result = {},
237+
userId = connection.caller.userId;
238+
239+
async.waterfall([
240+
function (cb) {
241+
242+
//Simple validations of the incoming parameters
243+
var error = helper.checkPositiveInteger(challengeId, 'challengeId') ||
244+
helper.checkMaxInt(challengeId, 'challengeId');
245+
246+
if (error) {
247+
cb(error);
248+
return;
249+
}
250+
251+
sqlParams.challengeId = challengeId;
252+
253+
// We are here. So all validations have passed.
254+
// Next we get all roles
255+
api.dataAccess.executeQuery("all_resource_roles", {}, dbConnectionMap, cb);
256+
}, function (rows, cb) {
257+
// Prepare a comma separated string of resource role names that must match
258+
var commaSepRoleIds = "",
259+
compiled = _.template("<%= resource_role_id %>,"),
260+
ctr = 0,
261+
resourceRoleFound;
262+
if (_.isUndefined(role)) {
263+
rows.forEach(function (row) {
264+
commaSepRoleIds += compiled({resource_role_id: row.resource_role_id});
265+
ctr += 1;
266+
if (ctr === rows.length) {
267+
commaSepRoleIds = commaSepRoleIds.slice(0, -1);
268+
}
269+
});
270+
} else {
271+
resourceRoleFound = _.find(rows, function (row) {
272+
return (row.name === role);
273+
});
274+
if (_.isUndefined(resourceRoleFound)) {
275+
//The role passed in is not recognized
276+
cb(new BadRequestError("The role: " + role + " was not found."));
277+
return;
278+
}
279+
commaSepRoleIds = resourceRoleFound.resource_role_id;
280+
}
281+
282+
// Get the terms
283+
sqlParams.resourceRoleIds = commaSepRoleIds;
284+
api.dataAccess.executeQuery("challenge_terms_of_use_noauth", sqlParams, dbConnectionMap, cb);
285+
}, function (rows, cb) {
286+
//We could just have down result.data = rows; but we need to change keys to camel case as per requirements
287+
result.terms = [];
288+
_.each(rows, function (row) {
289+
290+
result.terms.push({
291+
termsOfUseId: row.terms_of_use_id,
292+
title: row.title,
293+
url: row.url,
294+
agreeabilityType: row.agreeability_type,
295+
agreed: row.agreed,
296+
templateId: row.docusign_template_id
297+
});
298+
});
299+
300+
var ids = {};
301+
result.terms = result.terms.filter(function(row) {
302+
if (ids[row.termsOfUseId]) {
303+
return false;
304+
} else {
305+
ids[row.termsOfUseId] = true;
306+
return true;
307+
}
308+
});
309+
310+
cb();
311+
}
312+
], function (err) {
313+
if (err) {
314+
next(err);
315+
return;
316+
}
317+
next(null, result.terms);
318+
});
231319
}
320+
232321
};
233322

234323
next();

local/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '2'
2+
services:
3+
tc-api:
4+
image: "node"
5+
ports:
6+
- "7777:7777"

queries/challenge_registration_validations

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ left outer join (
4848
-- Check coder's country
4949
left outer join (
5050
informixoltp:coder coder join informixoltp:country country
51-
on coder.comp_country_code=country.country_code
52-
and country.country_name in ( "Iran", "North Korea", "Cuba", "Sudan", "Syria" )
51+
on (
52+
coder.comp_country_code=country.country_code OR
53+
coder.home_country_code=country.country_code
54+
) and country.country_name in ( "Iran", "North Korea", "Cuba", "Sudan", "Syria" )
5355
) on coder.coder_id = @userId@
5456
-- Get coder to check comp_country_code
5557
left outer join informixoltp:coder coder2 on coder2.coder_id = @userId@

queries/challenge_terms_of_use_noauth

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SELECT tou.terms_of_use_id as terms_of_use_id,
2+
tou.title as title,
3+
tou.url as url,
4+
touat.name as agreeability_type,
5+
dtx.docusign_template_id
6+
FROM project_role_terms_of_use_xref
7+
INNER JOIN terms_of_use tou ON project_role_terms_of_use_xref.terms_of_use_id = tou.terms_of_use_id
8+
INNER JOIN terms_of_use_agreeability_type_lu touat ON touat.terms_of_use_agreeability_type_id = tou.terms_of_use_agreeability_type_id
9+
LEFT JOIN user_terms_of_use_xref utuox ON utuox.terms_of_use_id = tou.terms_of_use_id
10+
LEFT JOIN terms_of_use_docusign_template_xref dtx ON dtx.terms_of_use_id = project_role_terms_of_use_xref.terms_of_use_id
11+
WHERE project_id = @challengeId@ AND
12+
resource_role_id IN (@resourceRoleIds@)
13+
ORDER BY group_ind, sort_order
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "challenge_terms_of_use_noauth",
3+
"db" : "common_oltp",
4+
"sqlfile" : "challenge_terms_of_use_noauth"
5+
}

queries/get_terms_of_use_noauth

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT tou.terms_of_use_id as terms_of_use_id,
2+
tou.title as title,
3+
tou.url as url,
4+
tou.terms_text as text,
5+
touat.terms_of_use_agreeability_type_id as agreeability_type_id,
6+
toudtx.docusign_template_id as docusign_template_id
7+
FROM terms_of_use tou
8+
INNER JOIN terms_of_use_agreeability_type_lu touat ON touat.terms_of_use_agreeability_type_id = tou.terms_of_use_agreeability_type_id
9+
LEFT JOIN terms_of_use_docusign_template_xref toudtx ON toudtx.terms_of_use_id = tou.terms_of_use_id
10+
WHERE tou.terms_of_use_id = @termsOfUseId@

queries/get_terms_of_use_noauth.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "get_terms_of_use_noauth",
3+
"db" : "common_oltp",
4+
"sqlfile" : "get_terms_of_use_noauth"
5+
}

queries/get_user_basic_profile_achievements

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ SELECT
44
, -1 as id
55
FROM user_achievement ua
66
JOIN coder AS c ON c.coder_id = ua.coder_id
7-
WHERE ua.achievement_type_id in (1,4,5,6,7,8,9) AND handle_lower = LOWER('@handle@') AND c.status = 'A'
7+
INNER JOIN achievement_type_lu atl ON atl.achievement_type_id = ua.achievement_type_id
8+
WHERE atl.badge = 1 AND handle_lower = LOWER('@handle@') AND c.status = 'A'
89

910
UNION
1011
SELECT

0 commit comments

Comments
 (0)