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

Commit

Permalink
Merge pull request #484 from appirio-tech/tom-noauth-against-master
Browse files Browse the repository at this point in the history
Tom noauth against master
  • Loading branch information
tladendo authored Aug 16, 2016
2 parents 6f317a6 + 40855a4 commit e8d29a7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 9 deletions.
30 changes: 21 additions & 9 deletions actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ exports.getChallengeTerms = {
description: "getChallengeTerms",
inputs: {
required: ["challengeId"],
optional: ["role"]
optional: ["role", "noauth"]
},
blockedConnectionTypes: [],
outputExample: {},
Expand All @@ -2251,14 +2251,26 @@ exports.getChallengeTerms = {
var challengeId = Number(connection.params.challengeId), role = connection.params.role, error;
async.waterfall([
function (cb) {
api.challengeHelper.getChallengeTerms(
connection,
challengeId,
role,
true,
connection.dbConnectionMap,
cb
);
if (connection.params.noauth) {
api.challengeHelper.getChallengeTermsNoAuth(
connection,
challengeId,
role,
true,
connection.dbConnectionMap,
cb
);
}
else {
api.challengeHelper.getChallengeTerms(
connection,
challengeId,
role,
true,
connection.dbConnectionMap,
cb
);
}
}, function (results, cb) {
var res = _.find(results, function (row) {
return row.agreeabilityType === 'DocuSignable' && !row.templateId;
Expand Down
89 changes: 89 additions & 0 deletions initializers/challengeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,96 @@ exports.challengeHelper = function (api, next) {
}
next(null, result.terms);
});
},
getChallengeTermsNoAuth : function (connection, challengeId, role, requireRegOpen, dbConnectionMap, next) {

var helper = api.helper,
sqlParams = {},
result = {},
userId = connection.caller.userId;

async.waterfall([
function (cb) {

//Simple validations of the incoming parameters
var error = helper.checkPositiveInteger(challengeId, 'challengeId') ||
helper.checkMaxInt(challengeId, 'challengeId');

if (error) {
cb(error);
return;
}

sqlParams.challengeId = challengeId;

// We are here. So all validations have passed.
// Next we get all roles
api.dataAccess.executeQuery("all_resource_roles", {}, dbConnectionMap, cb);
}, function (rows, cb) {
// Prepare a comma separated string of resource role names that must match
var commaSepRoleIds = "",
compiled = _.template("<%= resource_role_id %>,"),
ctr = 0,
resourceRoleFound;
if (_.isUndefined(role)) {
rows.forEach(function (row) {
commaSepRoleIds += compiled({resource_role_id: row.resource_role_id});
ctr += 1;
if (ctr === rows.length) {
commaSepRoleIds = commaSepRoleIds.slice(0, -1);
}
});
} else {
resourceRoleFound = _.find(rows, function (row) {
return (row.name === role);
});
if (_.isUndefined(resourceRoleFound)) {
//The role passed in is not recognized
cb(new BadRequestError("The role: " + role + " was not found."));
return;
}
commaSepRoleIds = resourceRoleFound.resource_role_id;
}

// Get the terms
sqlParams.resourceRoleIds = commaSepRoleIds;
api.dataAccess.executeQuery("challenge_terms_of_use_noauth", sqlParams, dbConnectionMap, cb);
}, function (rows, cb) {
//We could just have down result.data = rows; but we need to change keys to camel case as per requirements
result.terms = [];
_.each(rows, function (row) {

result.terms.push({
termsOfUseId: row.terms_of_use_id,
title: row.title,
url: row.url,
agreeabilityType: row.agreeability_type,
agreed: row.agreed,
templateId: row.docusign_template_id
});
});

var ids = {};
result.terms = result.terms.filter(function(row) {
if (ids[row.termsOfUseId]) {
return false;
} else {
ids[row.termsOfUseId] = true;
return true;
}
});

cb();
}
], function (err) {
if (err) {
next(err);
return;
}
next(null, result.terms);
});
}

};

next();
Expand Down
13 changes: 13 additions & 0 deletions queries/challenge_terms_of_use_noauth
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SELECT tou.terms_of_use_id as terms_of_use_id,
tou.title as title,
tou.url as url,
touat.name as agreeability_type,
dtx.docusign_template_id
FROM project_role_terms_of_use_xref
INNER JOIN terms_of_use tou ON project_role_terms_of_use_xref.terms_of_use_id = tou.terms_of_use_id
INNER JOIN terms_of_use_agreeability_type_lu touat ON touat.terms_of_use_agreeability_type_id = tou.terms_of_use_agreeability_type_id
LEFT JOIN user_terms_of_use_xref utuox ON utuox.terms_of_use_id = tou.terms_of_use_id
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
WHERE project_id = @challengeId@ AND
resource_role_id IN (@resourceRoleIds@)
ORDER BY group_ind, sort_order
5 changes: 5 additions & 0 deletions queries/challenge_terms_of_use_noauth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "challenge_terms_of_use_noauth",
"db" : "common_oltp",
"sqlfile" : "challenge_terms_of_use_noauth"
}

0 comments on commit e8d29a7

Please sign in to comment.