Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Commit 81fa2bf7 authored by antoine masson's avatar antoine masson
Browse files

v1.0

-Add license
- Fix bug in token validation
- Add poc for invalid token
- New language template
parent 841bc8dd
Copyright © 2021 EAWAG
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
......@@ -528,8 +528,8 @@ exports.getSurveykey = async (req, res) => {
exports.getSurveyInfo= async (req, res) => {
try {
let surveygeneral = await Survey.findById(req.userData.survey_id ,{general:1});
surveygeneral = surveygeneral.general;
const survey = await Survey.findById(req.userData.survey_id );
let surveygeneral = survey.general;
let languages = []
for(let i in surveygeneral.languages) {
......@@ -537,13 +537,13 @@ exports.getSurveyInfo= async (req, res) => {
const lt = await LanguageTrans.findOne({ language: lang },{flag:1});
languages.push({id:lang,flag:lt.flag})
}
let poc = surveygeneral.poc
if (poc.useglobal){
const opt = await GlobalOptions.findById(0,{poc:1});
poc = opt.poc;
}
// let poc = surveygeneral.poc
// if (poc.useglobal){
// const opt = await GlobalOptions.findById(0,{poc:1});
// poc = opt.poc;
// }
const info = {poc:poc,languages:languages,externalurl:surveygeneral.externalurl}
const info = {poc:survey.poc,languages:languages,externalurl:surveygeneral.externalurl}
await res.status(201).json({payload:info,message:"info",status:"OK"});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
......
const mongoose = require('mongoose');
const Token = mongoose.model('Token');
const Survey = mongoose.model('Survey');
const GlobalOptions = mongoose.model('SurveyGlobalOptions');
exports.registerNewToken = async (req, res) => {
try {
......@@ -132,32 +133,36 @@ exports.down_survey_tokens = async (req,res)=>{
exports.loginToken = async (req, res) => {
try {
const token = await Token.findOne({ token:req.body.token });
const gopt = await GlobalOptions.findById(0,{poc:1});
if (!token) {
return res
.status(201)
.json({ message: "This token doesn't exist" ,status: "Error"});
.json({ message: "This token does not exist" ,poc:gopt.poc,status: "Error"});
}
const survey = await Survey.findById(token.survey_id)
let spoc= await survey.poc
if(!token.enable){
return res
.status(201)
.json({ message: "Token disabled!" ,status: "Error"});
.json({ message: "Token disabled!" ,poc:spoc,status: "Error"});
}
const survey = await Survey.findById(token.survey_id)
if(!survey.status && !token.test){
return res
.status(201)
.json({ message: "Survey not online" ,status: "Error"});
.json({ message: "Survey not online" ,poc:spoc,status: "Error"});
}
if(!survey.enable && !token.test){
if(!survey.general.enable && !token.test){
return res
.status(201)
.json({ message: "Survey disabled" ,status: "Error"});
.json({ message: "Survey disabled",poc:spoc ,status: "Error"});
}
if(token.status==="finished"){
return res
.status(201)
.json({ message: "Status : finished" ,status: "Error"});
.json({ message: "Status : finished" ,poc:survey.poc,status: "Error"});
}
const authtoken = await token.generateAuthToken();
res.status(201).json({ token:authtoken, message : "Succeeded Login", status: "OK"});
......@@ -169,15 +174,16 @@ exports.accessToken = async (req, res) => {
if(await Survey.isAccessToken(req.body.survey_id)){
try{
const survey = await Survey.findById(req.body.survey_id)
let spoc= await survey.poc
if(!survey.status && !token.test){
return res
.status(201)
.json({ message: "Survey not online" ,status: "Error"});
.json({ message: "Survey not online" ,poc:spoc,status: "Error"});
}
if(!survey.enable && !token.test){
return res
.status(201)
.json({ message: "Survey disabled" ,status: "Error"});
.json({ message: "Survey disabled" ,poc:spoc,status: "Error"});
}
let token = await Token.findOne({ token:req.body.token });
if (!token) { //create new token if doesn't exist
......@@ -195,7 +201,7 @@ exports.accessToken = async (req, res) => {
if(!token.enable){
return res
.status(201)
.json({ message: "Token disabled!" ,status: "Error"});
.json({ message: "Token disabled!" ,poc:survey.poc,status: "Error"});
}
const authtoken = await token.generateAuthToken();
res.status(201).json({ token:authtoken, message : "Succeeded Login", status: "OK"});
......@@ -203,7 +209,8 @@ exports.accessToken = async (req, res) => {
res.status(400).json({ message: err,status:"Error"});
}
} else {
res.status(400).json({ message: "Forbidden Operation",status:"Error"});
const gopt = await GlobalOptions.findById(0,{poc:1});
res.status(400).json({ message: "Forbidden Operation",poc:gopt.poc,status:"Error"});
}
}
......
......@@ -3,6 +3,7 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const validator = require( "validator");
const textinputs = new Schema({
language:String,
html:{
......@@ -244,6 +245,15 @@ SurveySchema.virtual('status').get(function() {
return check;
});
SurveySchema.virtual('poc').get(async function() {
const GlobalOptions = mongoose.model('SurveyGlobalOptions');
let poc = this.general.poc
if (this.general.poc.useglobal){
const opt = await GlobalOptions.findById(0,{poc:1});
poc = opt.poc;
}
return poc
});
SurveySchema.methods.toJSON = function () {
const survey = this;
const Obj = survey.toObject({virtuals:true});
......
......@@ -414,5 +414,13 @@
"createdAt": "2021-03-26T21:44:32.682Z",
"updatedAt": "2021-03-26T21:44:32.682Z",
"id": "605e55c052816f12906632fa"
},
{
"type": "String",
"field": "ALTRANKING",
"description": "Text on top of alternative ranking on rational conclusion ",
"createdAt": "2021-04-08T16:10:29.001Z",
"updatedAt": "2021-04-08T16:10:29.001Z",
"id": "606f2af4d9374232a4a27276"
}
]
\ No newline at end of file
......@@ -4,326 +4,326 @@
"flag": "gb",
"fields": [
{
"_id": "605e55c952816f12906632fb",
"_id": "6068bf8d56f5cd8a7af23d8a",
"field": "NEXT",
"text": "next",
"id": "605e55c952816f12906632fb"
"id": "6068bf8d56f5cd8a7af23d8a"
},
{
"_id": "605e55c952816f12906632fc",
"_id": "6068bf8d56f5cd8a7af23d8b",
"field": "WELCOME",
"text": "welcome",
"id": "605e55c952816f12906632fc"
"id": "6068bf8d56f5cd8a7af23d8b"
},
{
"_id": "605e55c952816f12906632fd",
"_id": "6068bf8d56f5cd8a7af23d8c",
"field": "ACCEPT",
"text": "accept",
"id": "605e55c952816f12906632fd"
"id": "6068bf8d56f5cd8a7af23d8c"
},
{
"_id": "605e55c952816f12906632fe",
"_id": "6068bf8d56f5cd8a7af23d8d",
"field": "REFUSE",
"text": "refuse",
"id": "605e55c952816f12906632fe"
"id": "6068bf8d56f5cd8a7af23d8d"
},
{
"_id": "605e55c952816f12906632ff",
"_id": "6068bf8d56f5cd8a7af23d8e",
"field": "PREVIOUS",
"text": "previous",
"id": "605e55c952816f12906632ff"
"id": "6068bf8d56f5cd8a7af23d8e"
},
{
"_id": "605e55c952816f1290663300",
"_id": "6068bf8d56f5cd8a7af23d8f",
"field": "POC",
"text": "Person of Contact",
"id": "605e55c952816f1290663300"
"id": "6068bf8d56f5cd8a7af23d8f"
},
{
"_id": "605e55c952816f1290663301",
"_id": "6068bf8d56f5cd8a7af23d90",
"field": "AGREEMENT",
"text": "I accept that my data are used ...",
"id": "605e55c952816f1290663301"
"id": "6068bf8d56f5cd8a7af23d90"
},
{
"_id": "605e55c952816f1290663302",
"_id": "6068bf8d56f5cd8a7af23d91",
"field": "AGREETITLE",
"text": "Data Use Agreements",
"id": "605e55c952816f1290663302"
"id": "6068bf8d56f5cd8a7af23d91"
},
{
"_id": "605e55c952816f1290663303",
"_id": "6068bf8d56f5cd8a7af23d92",
"field": "AGREE",
"text": "agree",
"id": "605e55c952816f1290663303"
"id": "6068bf8d56f5cd8a7af23d92"
},
{
"_id": "605e55c952816f1290663304",
"_id": "6068bf8d56f5cd8a7af23d93",
"field": "SELECTONE",
"text": "You need to select one value",
"id": "605e55c952816f1290663304"
"id": "6068bf8d56f5cd8a7af23d93"
},
{
"_id": "605e55c952816f1290663305",
"_id": "6068bf8d56f5cd8a7af23d94",
"field": "USEMAX",
"text": "Please use maximum",
"id": "605e55c952816f1290663305"
"id": "6068bf8d56f5cd8a7af23d94"
},
{
"_id": "605e55c952816f1290663306",
"_id": "6068bf8d56f5cd8a7af23d95",
"field": "USEMIN",
"text": "Please use maximum",
"id": "605e55c952816f1290663306"
"id": "6068bf8d56f5cd8a7af23d95"
},
{
"_id": "605e55c952816f1290663307",
"_id": "6068bf8d56f5cd8a7af23d96",
"field": "CHARACTERS",
"text": "characters",
"id": "605e55c952816f1290663307"
"id": "6068bf8d56f5cd8a7af23d96"
},
{
"_id": "605e55c952816f1290663308",
"_id": "6068bf8d56f5cd8a7af23d97",
"field": "ALLOWEDMAX",
"text": "Allowed maximum is",
"id": "605e55c952816f1290663308"
"id": "6068bf8d56f5cd8a7af23d97"
},
{
"_id": "605e55c952816f1290663309",
"_id": "6068bf8d56f5cd8a7af23d98",
"field": "ALLOWEDMIN",
"text": "Allowed miniumum is",
"id": "605e55c952816f1290663309"
"id": "6068bf8d56f5cd8a7af23d98"
},
{
"_id": "605e55c952816f129066330a",
"_id": "6068bf8d56f5cd8a7af23d99",
"field": "MANDATORYFIELD",
"text": "Mandatory field",
"id": "605e55c952816f129066330a"
"id": "6068bf8d56f5cd8a7af23d99"
},
{
"_id": "605e55c952816f129066330b",
"_id": "6068bf8d56f5cd8a7af23d9a",
"field": "MOVEBOX",
"text": "You need to sort all the boxes",
"id": "605e55c952816f129066330b"
"id": "6068bf8d56f5cd8a7af23d9a"
},
{
"_id": "605e55c952816f129066330c",
"_id": "6068bf8d56f5cd8a7af23d9b",
"field": "ALTERNATIVES_INPUTS",
"text": "Please move element according to your preference ; one is the most prefered",
"id": "605e55c952816f129066330c"
"id": "6068bf8d56f5cd8a7af23d9b"
},
{
"_id": "605e55c952816f129066330d",
"_id": "6068bf8d56f5cd8a7af23d9c",
"field": "RESTART",
"text": "Restart",
"id": "605e55c952816f129066330d"
"id": "6068bf8d56f5cd8a7af23d9c"
},
{
"_id": "605e55c952816f129066330e",
"_id": "6068bf8d56f5cd8a7af23d9d",
"field": "INTROALT",
"text": "Introduction to Alternatives",
"id": "605e55c952816f129066330e"
"id": "6068bf8d56f5cd8a7af23d9d"
},
{
"_id": "605e55c952816f129066330f",
"_id": "6068bf8d56f5cd8a7af23d9e",
"field": "ALTERNATIVES",
"text": "Alternatives",
"id": "605e55c952816f129066330f"
"id": "6068bf8d56f5cd8a7af23d9e"
},
{
"_id": "605e55c952816f1290663310",
"_id": "6068bf8d56f5cd8a7af23d9f",
"field": "SORTALT",
"text": "Sort Alternatives",
"id": "605e55c952816f1290663310"
"id": "6068bf8d56f5cd8a7af23d9f"
},
{
"_id": "605e55c952816f1290663311",
"_id": "6068bf8d56f5cd8a7af23da0",
"field": "INTROOBJ",
"text": "Introduction to Objectives",
"id": "605e55c952816f1290663311"
"id": "6068bf8d56f5cd8a7af23da0"
},
{
"_id": "605e55c952816f1290663312",
"_id": "6068bf8d56f5cd8a7af23da1",
"field": "MATCH",
"text": "Congrats Swing and Tradeoff match. You can continue.",
"id": "605e55c952816f1290663312"
"id": "6068bf8d56f5cd8a7af23da1"
},
{
"_id": "605e55c952816f1290663313",
"_id": "6068bf8d56f5cd8a7af23da2",
"field": "NOMATCH",
"text": "Sorry Swing and Tradeoff does not match. You cannot continue.",
"id": "605e55c952816f1290663313"
"id": "6068bf8d56f5cd8a7af23da2"
},
{
"_id": "605e55c952816f1290663314",
"_id": "6068bf8d56f5cd8a7af23da3",
"field": "RSWING",
"text": "I would like to restart Swing",
"id": "605e55c952816f1290663314"
"id": "6068bf8d56f5cd8a7af23da3"
},
{
"_id": "605e55c952816f1290663315",
"_id": "6068bf8d56f5cd8a7af23da4",
"field": "RTRADEOFF",
"text": "I would like to restart Tradoff",
"id": "605e55c952816f1290663315"
"id": "6068bf8d56f5cd8a7af23da4"
},
{
"_id": "605e55c952816f1290663316",
"_id": "6068bf8d56f5cd8a7af23da5",
"field": "NEEDVAL",
"text": "You need to choose a value",
"id": "605e55c952816f1290663316"
"id": "6068bf8d56f5cd8a7af23da5"
},
{
"_id": "605e55c952816f1290663317",
"_id": "6068bf8d56f5cd8a7af23da6",
"field": "ERRHIGHER",
"text": "Cannot be higher than a upper element",
"id": "605e55c952816f1290663317"
"id": "6068bf8d56f5cd8a7af23da6"
},
{
"_id": "605e55c952816f1290663318",
"_id": "6068bf8d56f5cd8a7af23da7",
"field": "ERRLOWER",
"text": "Cannot be lower than a lower element",
"id": "605e55c952816f1290663318"
"id": "6068bf8d56f5cd8a7af23da7"
},
{
"_id": "605e55c952816f1290663319",
"_id": "6068bf8d56f5cd8a7af23da8",
"field": "READOBJ",
"text": "Read this objective",
"id": "605e55c952816f1290663319"
"id": "6068bf8d56f5cd8a7af23da8"
},
{
"_id": "605e55c952816f129066331a",
"_id": "6068bf8d56f5cd8a7af23da9",
"field": "READALT",
"text": "Read this alternative",
"id": "605e55c952816f129066331a"
"id": "6068bf8d56f5cd8a7af23da9"
},
{
"_id": "605e55c952816f129066331b",
"_id": "6068bf8d56f5cd8a7af23daa",
"field": "NOMATCHSELECT",
"text": "Please select the method that represents your preference if none of them represents what you would like click \"None\"",
"id": "605e55c952816f129066331b"
"id": "6068bf8d56f5cd8a7af23daa"
},
{
"_id": "605e55c952816f129066331c",
"_id": "6068bf8d56f5cd8a7af23dab",
"field": "CSWING",
"text": "Continuing with Swing values",
"id": "605e55c952816f129066331c"
"id": "6068bf8d56f5cd8a7af23dab"
},
{
"_id": "605e55c952816f129066331d",
"_id": "6068bf8d56f5cd8a7af23dac",
"field": "CTRADEOFF",
"text": "Continuing with TradeOff values",
"id": "605e55c952816f129066331d"
"id": "6068bf8d56f5cd8a7af23dac"
},
{
"_id": "605e55c952816f129066331e",
"_id": "6068bf8d56f5cd8a7af23dad",
"field": "CNONE",
"text": "Either Swing or Tradeoff correspond to my wishes",
"id": "605e55c952816f129066331e"
"id": "6068bf8d56f5cd8a7af23dad"
},
{
"_id": "605e55c952816f129066331f",
"_id": "6068bf8d56f5cd8a7af23dae",
"field": "SWINGTEXT",
"text": "<div><b>This is a presentation of the swing method :</b></div><div><br></div><div>Move sliders and be happy<br></div>",
"id": "605e55c952816f129066331f"
"text": "<p><strong>This is a presentation of the swing method :</strong></p><p>Move sliders and be happy<br>&nbsp;</p>",
"id": "6068bf8d56f5cd8a7af23dae"
},
{
"_id": "605e55c952816f1290663320",
"_id": "6068bf8d56f5cd8a7af23daf",
"field": "TRADEOFFTEXT",
"text": "<div><b>This is a presentation of the Tradeoff method :</b></div><div><br></div><div>Select select<br></div>Move sliders and be happy",
"id": "605e55c952816f1290663320"
"text": "<p><strong>This is a presentation of the Tradeoff method :</strong></p><p>Select select<br>&nbsp;</p><p>Move sliders and be happy</p>",
"id": "6068bf8d56f5cd8a7af23daf"
},
{
"_id": "605e55c952816f1290663321",
"_id": "6068bf8d56f5cd8a7af23db0",
"field": "OBJCAT",
"text": "Objective Category",
"id": "605e55c952816f1290663321"
"id": "6068bf8d56f5cd8a7af23db0"
},
{
"_id": "605e55c952816f1290663322",
"_id": "6068bf8d56f5cd8a7af23db1",
"field": "OBJROOT",
"text": "Objective Root",
"id": "605e55c952816f1290663322"
"id": "6068bf8d56f5cd8a7af23db1"
},
{
"_id": "605e55c952816f1290663323",
"_id": "6068bf8d56f5cd8a7af23db2",
"field": "RATCONC",
"text": "Conclusion",
"id": "605e55c952816f1290663323"
"id": "6068bf8d56f5cd8a7af23db2"
},
{
"_id": "605e55c952816f1290663324",
"_id": "6068bf8d56f5cd8a7af23db3",
"field": "CLICKITEMSEQ",
"text": "Please click on each items sequentially",
"id": "605e55c952816f1290663324"
"id": "6068bf8d56f5cd8a7af23db3"
},
{
"_id": "605e55c952816f1290663325",
"_id": "6068bf8d56f5cd8a7af23db4",
"field": "SORTITEMSEQ",
"text": "Click on each item for sorting, the first element is your preferred",
"id": "605e55c952816f1290663325"
"id": "6068bf8d56f5cd8a7af23db4"
},
{
"_id": "605e55c952816f1290663326",
"_id": "6068bf8d56f5cd8a7af23db5",
"field": "SWINGSORT",
"text": "Sort by clicking the option by order of preference, the first element is your preferred",
"id": "605e55c952816f1290663326"
"id": "6068bf8d56f5cd8a7af23db5"
},
{
"_id": "605e55c952816f1290663327",
"_id": "6068bf8d56f5cd8a7af23db6",
"field": "SWINGMOVESLIDER",
"text": "Move the slider so ...",
"id": "605e55c952816f1290663327"
"id": "6068bf8d56f5cd8a7af23db6"
},
{
"_id": "605e55c952816f1290663328",
"_id": "6068bf8d56f5cd8a7af23db7",
"field": "TRADESEL",
"text": "Select your best option between the two possiblities, if you like them both you can click on equivalent",
"id": "605e55c952816f1290663328"
"id": "6068bf8d56f5cd8a7af23db7"
},
{
"_id": "605e55c952816f1290663329",
"_id": "6068bf8d56f5cd8a7af23db8",
"field": "TRADEMOVESLIDER",
"text": "Move the slider so you like both option alike",
"id": "605e55c952816f1290663329"
"id": "6068bf8d56f5cd8a7af23db8"
},
{
"_id": "605e55c952816f129066332a",
"_id": "6068bf8d56f5cd8a7af23db9",
"field": "EQUIVALENT",
"text": "EQUIVALENT",
"id": "605e55c952816f129066332a"
"id": "6068bf8d56f5cd8a7af23db9"
},
{
"_id": "605e55c952816f129066332b",
"_id": "6068bf8d56f5cd8a7af23dba",
"field": "NOMATCHCONTINUE",
"text": "Sorry Swing and Tradeoff does not match, but you can continue or restart one of the method.",
"id": "605e55c952816f129066332b"
"id": "6068bf8d56f5cd8a7af23dba"
},
{
"_id": "605e55c952816f129066332c",
"_id": "6068bf8d56f5cd8a7af23dbb",
"field": "RATIONAL_CONCLUSION_OBJANAL",
"text": "Here are your favorite objectives sorted by order of preference<br>",
"id": "605e55c952816f129066332c"
"text": "<p>Here are your favorite objectives sorted by order of preference<br>&nbsp;</p>",
"id": "6068bf8d56f5cd8a7af23dbb"
},
{
"_id": "605e55c952816f129066332d",
"_id": "6068bf8d56f5cd8a7af23dbc",
"field": "RATIONAL_CONCLUSION_MATCH",
"text": "It's a match <br>",
"id": "605e55c952816f129066332d"
"text": "<p>It's a match&nbsp;<br>&nbsp;</p>",
"id": "6068bf8d56f5cd8a7af23dbc"
},
{
"_id": "605e55c952816f129066332e",
"_id": "6068bf8d56f5cd8a7af23dbd",
"field": "RATIONAL_CONCLUSION_NOMATCH",
"text": "Sorry it doesn't match<br>",
"id": "605e55c952816f129066332e"
"text": "<p>Sorry it doesn't match<br>&nbsp;</p><p>Maybe you can try again …</p>",