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

Commit 0d05e7b

Browse files
authored
Merge pull request #485 from appirio-tech/tom-noauth-against-dev
Tom noauth against dev
2 parents 72c46ef + bce0bc1 commit 0d05e7b

File tree

4 files changed

+128
-9
lines changed

4 files changed

+128
-9
lines changed

actions/challenges.js

+21-9
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;

initializers/challengeHelper.js

+89
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();

queries/challenge_terms_of_use_noauth

+13
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
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+
}

0 commit comments

Comments
 (0)