diff --git a/actions/challenges.js b/actions/challenges.js index f4c342168..0c40bbf2b 100755 --- a/actions/challenges.js +++ b/actions/challenges.js @@ -2237,7 +2237,7 @@ exports.getChallengeTerms = { description: "getChallengeTerms", inputs: { required: ["challengeId"], - optional: ["role"] + optional: ["role", "noauth"] }, blockedConnectionTypes: [], outputExample: {}, @@ -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; diff --git a/initializers/challengeHelper.js b/initializers/challengeHelper.js index 1a0d16748..0f53489a3 100644 --- a/initializers/challengeHelper.js +++ b/initializers/challengeHelper.js @@ -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(); diff --git a/queries/challenge_terms_of_use_noauth b/queries/challenge_terms_of_use_noauth new file mode 100644 index 000000000..315661747 --- /dev/null +++ b/queries/challenge_terms_of_use_noauth @@ -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 diff --git a/queries/challenge_terms_of_use_noauth.json b/queries/challenge_terms_of_use_noauth.json new file mode 100644 index 000000000..c5e697f4b --- /dev/null +++ b/queries/challenge_terms_of_use_noauth.json @@ -0,0 +1,5 @@ +{ + "name" : "challenge_terms_of_use_noauth", + "db" : "common_oltp", + "sqlfile" : "challenge_terms_of_use_noauth" +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy