From 21fb2daf42d2856377c2bc89bd208a2dbf63e1b4 Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Mon, 8 Mar 2021 17:42:15 +0100 Subject: [PATCH 1/4] Fixed issue #17154: Cannot edit answer options on active surveys --- .../QuestionAdministrationController.php | 92 ++++++++++++++----- .../answerOptionRow.twig | 25 ++--- 2 files changed, 82 insertions(+), 35 deletions(-) diff --git a/application/controllers/QuestionAdministrationController.php b/application/controllers/QuestionAdministrationController.php index ad59c549a0a..3f67fe4c4a0 100644 --- a/application/controllers/QuestionAdministrationController.php +++ b/application/controllers/QuestionAdministrationController.php @@ -452,7 +452,12 @@ public function actionSaveQuestionData() } } else { // TODO: Update subquestions. - // TODO: Update answer options. + if ($question->questionType->answerscales > 0) { + $this->updateAnswerOptions( + $question, + $request->getPost('answeroptions') + ); + } } $transaction->commit(); @@ -2828,38 +2833,77 @@ private function storeAnswerOptions($question, $answerOptionsArray) } } } - /* - foreach ($dataSet as $aAnswerOptions) { - foreach ($aAnswerOptions as $iScaleId => $aAnswerOptionDataSet) { - $aAnswerOptionDataSet['sortorder'] = (int)$aAnswerOptionDataSet['sortorder']; - $oAnswer = Answer::model()->findByPk($aAnswerOptionDataSet['aid']); - if ($oAnswer == null || $isCopyProcess) { - $oAnswer = new Answer(); - $oAnswer->qid = $question->qid; - unset($aAnswerOptionDataSet['aid']); - unset($aAnswerOptionDataSet['qid']); - } + return true; + } - $codeIsEmpty = (!isset($aAnswerOptionDataSet['code'])); - if ($codeIsEmpty) { - throw new CHttpException( - 500, - "Answer option code cannot be empty" + /** + * Like storeAnswerOptions, but adapted for when survey is active (not allowed to change codes). + * + * @param Question $question + * @param array $answerOptionsArray + * @return void + * @throws CHttpException + */ + private function updateAnswerOptions(Question $question, array $answerOptionsArray) + { + $i = 0; + foreach ($answerOptionsArray as $answerOptionId => $answerOptionArray) { + foreach ($answerOptionArray as $scaleId => $data) { + if (!isset($data['code'])) { + throw new Exception( + 'code is not set in data: ' . json_encode($data) ); } - $oAnswer->setAttributes($aAnswerOptionDataSet); - $answerSaved = $oAnswer->save(); - if (!$answerSaved) { + $answer = Answer::model()->findByAttributes( + [ + 'qid' => $question->qid, + 'code' => $data['code'] + ] + ); + if (empty($answer)) { + throw new Exception( + 'Found no answer option with code ' . $data['code'] + ); + } + $answer->sortorder = $i; + $i++; + if (isset($data['assessment'])) { + $answer->assessment_value = $data['assessment']; + } else { + $answer->assessment_value = 0; + } + $answer->scale_id = $scaleId; + if (!$answer->update()) { throw new CHttpException( 500, - "Answer option couldn't be saved. Error: " - . print_r($oAnswer->getErrors(), true) + gT("Could not save answer option") . PHP_EOL + . print_r($answer->getErrors(), true) ); } - $this->applyAnswerI10N($oAnswer, $question, $aAnswerOptionDataSet); + $answer->refresh(); + foreach ($data['answeroptionl10n'] as $lang => $answerOptionText) { + $l10n = AnswerL10n::model()->findByAttributes( + [ + 'aid' => $answer->aid, + 'language' => $lang + ] + ); + if (empty($l10n)) { + $l10n = new AnswerL10n(); + } + $l10n->aid = $answer->aid; + $l10n->language = $lang; + $l10n->answer = $answerOptionText; + if (!$l10n->save()) { + throw new CHttpException( + 500, + gT("Could not save answer option") . PHP_EOL + . print_r($l10n->getErrors(), true) + ); + } + } } } - */ return true; } diff --git a/application/views/questionAdministration/answerOptionRow.twig b/application/views/questionAdministration/answerOptionRow.twig index 836b7d529dd..620f2938c64 100644 --- a/application/views/questionAdministration/answerOptionRow.twig +++ b/application/views/questionAdministration/answerOptionRow.twig @@ -47,17 +47,20 @@ /> {% endif %} - + {# If survey is not active, and it's not the first language : no move button, code not editable #} {% else %} From 1d91e97f5bf126452c727d7eb0188e951aed46a1 Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Mon, 8 Mar 2021 17:50:48 +0100 Subject: [PATCH 2/4] Revert "Fixed issue #17154: Cannot edit answer options on active surveys" This reverts commit 21fb2daf42d2856377c2bc89bd208a2dbf63e1b4. --- .../QuestionAdministrationController.php | 92 +++++-------------- .../answerOptionRow.twig | 25 +++-- 2 files changed, 35 insertions(+), 82 deletions(-) diff --git a/application/controllers/QuestionAdministrationController.php b/application/controllers/QuestionAdministrationController.php index 3f67fe4c4a0..ad59c549a0a 100644 --- a/application/controllers/QuestionAdministrationController.php +++ b/application/controllers/QuestionAdministrationController.php @@ -452,12 +452,7 @@ public function actionSaveQuestionData() } } else { // TODO: Update subquestions. - if ($question->questionType->answerscales > 0) { - $this->updateAnswerOptions( - $question, - $request->getPost('answeroptions') - ); - } + // TODO: Update answer options. } $transaction->commit(); @@ -2833,77 +2828,38 @@ private function storeAnswerOptions($question, $answerOptionsArray) } } } - return true; - } - - /** - * Like storeAnswerOptions, but adapted for when survey is active (not allowed to change codes). - * - * @param Question $question - * @param array $answerOptionsArray - * @return void - * @throws CHttpException - */ - private function updateAnswerOptions(Question $question, array $answerOptionsArray) - { - $i = 0; - foreach ($answerOptionsArray as $answerOptionId => $answerOptionArray) { - foreach ($answerOptionArray as $scaleId => $data) { - if (!isset($data['code'])) { - throw new Exception( - 'code is not set in data: ' . json_encode($data) - ); - } - $answer = Answer::model()->findByAttributes( - [ - 'qid' => $question->qid, - 'code' => $data['code'] - ] - ); - if (empty($answer)) { - throw new Exception( - 'Found no answer option with code ' . $data['code'] - ); - } - $answer->sortorder = $i; - $i++; - if (isset($data['assessment'])) { - $answer->assessment_value = $data['assessment']; - } else { - $answer->assessment_value = 0; + /* + foreach ($dataSet as $aAnswerOptions) { + foreach ($aAnswerOptions as $iScaleId => $aAnswerOptionDataSet) { + $aAnswerOptionDataSet['sortorder'] = (int)$aAnswerOptionDataSet['sortorder']; + $oAnswer = Answer::model()->findByPk($aAnswerOptionDataSet['aid']); + if ($oAnswer == null || $isCopyProcess) { + $oAnswer = new Answer(); + $oAnswer->qid = $question->qid; + unset($aAnswerOptionDataSet['aid']); + unset($aAnswerOptionDataSet['qid']); } - $answer->scale_id = $scaleId; - if (!$answer->update()) { + + $codeIsEmpty = (!isset($aAnswerOptionDataSet['code'])); + if ($codeIsEmpty) { throw new CHttpException( 500, - gT("Could not save answer option") . PHP_EOL - . print_r($answer->getErrors(), true) + "Answer option code cannot be empty" ); } - $answer->refresh(); - foreach ($data['answeroptionl10n'] as $lang => $answerOptionText) { - $l10n = AnswerL10n::model()->findByAttributes( - [ - 'aid' => $answer->aid, - 'language' => $lang - ] + $oAnswer->setAttributes($aAnswerOptionDataSet); + $answerSaved = $oAnswer->save(); + if (!$answerSaved) { + throw new CHttpException( + 500, + "Answer option couldn't be saved. Error: " + . print_r($oAnswer->getErrors(), true) ); - if (empty($l10n)) { - $l10n = new AnswerL10n(); - } - $l10n->aid = $answer->aid; - $l10n->language = $lang; - $l10n->answer = $answerOptionText; - if (!$l10n->save()) { - throw new CHttpException( - 500, - gT("Could not save answer option") . PHP_EOL - . print_r($l10n->getErrors(), true) - ); - } } + $this->applyAnswerI10N($oAnswer, $question, $aAnswerOptionDataSet); } } + */ return true; } diff --git a/application/views/questionAdministration/answerOptionRow.twig b/application/views/questionAdministration/answerOptionRow.twig index 620f2938c64..836b7d529dd 100644 --- a/application/views/questionAdministration/answerOptionRow.twig +++ b/application/views/questionAdministration/answerOptionRow.twig @@ -47,20 +47,17 @@ /> {% endif %} - + {# If survey is not active, and it's not the first language : no move button, code not editable #} {% else %} From af49a2ed369b3c921433732cf8c0bcbbeeb1ea81 Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Mon, 8 Mar 2021 14:44:33 -0300 Subject: [PATCH 3/4] Fixed issue #17090: Email continue not shown clearly after activation (#1763) --- .../views/admin/token/emailwarning.php | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/application/views/admin/token/emailwarning.php b/application/views/admin/token/emailwarning.php index 444d4387c5d..f60eeb8da92 100644 --- a/application/views/admin/token/emailwarning.php +++ b/application/views/admin/token/emailwarning.php @@ -8,7 +8,7 @@

- +     @@ -57,13 +57,18 @@ $('#countdown-progress').css('-moz-animation-duration', '1s'); $('#countdown-progress').css('animation-duration', '1s'); window.countdownTimerTokenSend = " . Yii::app()->getConfig('sendingrate') . "; + + var submitInviteForm = function() { + $('body').append('
'); + $('#sendTokenInvitationsNow').after('

'); + $('#cancelAutomaticSubmission').remove(); + $('#sendTokenInvitationsNow').remove(); + $('#tokenSubmitInviteForm').trigger('submit'); + }; + var intervaltoRenew = window.setInterval(function(){ if(window.countdownTimerTokenSend === 0){ - $('body').append('
'); - $('#sendTokenInvitationsNow').after('

'); - $('#cancelAutomaticSubmission').remove(); - $('#sendTokenInvitationsNow').remove(); - $('#tokenSubmitInviteForm').trigger('submit'); + submitInviteForm(); clearInterval(intervaltoRenew); return; } @@ -72,6 +77,16 @@ $('#tokenSendCounter').text(window.countdownTimerTokenSend); },1000); + $('#sendTokenInvitationsNow').on('click', function(evt){ + clearInterval(intervaltoRenew); + $('#countdown-progress').css('-webkit-animation-duration', '500ms'); + $('#countdown-progress').css('-moz-animation-duration', '500ms'); + $('#countdown-progress').css('animation-duration', '500ms'); + $('#countdown-progress').css('width', '0'); + $('#tokensendcounter').text('0'); + submitInviteForm(); + }); + $('#cancelAutomaticSubmission').on('click', function(evt){ evt.preventDefault(); clearInterval(intervaltoRenew); From 12cd8e5a2ca9975a3a45a0b10ca0630344d55e7d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Mar 2021 01:27:27 +0100 Subject: [PATCH 4/4] Dev Bump elliptic from 6.4.0 to 6.5.4 in /assets/packages/questions/timer (#1796) --- .../questions/timer/package-lock.json | 32 +++++++++---- assets/packages/questions/timer/yarn.lock | 46 ++++++++++--------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/assets/packages/questions/timer/package-lock.json b/assets/packages/questions/timer/package-lock.json index cb0dd34480f..eae94c26eea 100644 --- a/assets/packages/questions/timer/package-lock.json +++ b/assets/packages/questions/timer/package-lock.json @@ -1778,18 +1778,32 @@ "dev": true }, "elliptic": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", - "integrity": "sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", "dev": true, "requires": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", + "bn.js": "^4.11.9", + "brorand": "^1.1.0", "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + } } }, "emoji-regex": { diff --git a/assets/packages/questions/timer/yarn.lock b/assets/packages/questions/timer/yarn.lock index 29a3063530e..d5a58bcbae4 100644 --- a/assets/packages/questions/timer/yarn.lock +++ b/assets/packages/questions/timer/yarn.lock @@ -795,9 +795,9 @@ bluebird@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" -bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: - version "4.11.8" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.9: + version "4.12.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" brace-expansion@^1.1.7: version "1.1.11" @@ -829,7 +829,7 @@ braces@^2.3.0, braces@^2.3.1: split-string "^3.0.2" to-regex "^3.0.1" -brorand@^1.0.1: +brorand@^1.0.1, brorand@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" @@ -1303,16 +1303,16 @@ electron-to-chromium@^1.3.47: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.50.tgz#7438b76f92b41b919f3fbdd350fbd0757dacddf7" elliptic@^6.0.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df" + version "6.5.4" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" dependencies: - bn.js "^4.4.0" - brorand "^1.0.1" + bn.js "^4.11.9" + brorand "^1.1.0" hash.js "^1.0.0" - hmac-drbg "^1.0.0" - inherits "^2.0.1" - minimalistic-assert "^1.0.0" - minimalistic-crypto-utils "^1.0.0" + hmac-drbg "^1.0.1" + inherits "^2.0.4" + minimalistic-assert "^1.0.1" + minimalistic-crypto-utils "^1.0.1" emojis-list@^2.0.0: version "2.1.0" @@ -1678,13 +1678,13 @@ hash-base@^3.0.0: safe-buffer "^5.0.1" hash.js@^1.0.0, hash.js@^1.0.3: - version "1.1.4" - resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.4.tgz#8b50e1f35d51bd01e5ed9ece4dbe3549ccfa0a3c" + version "1.1.7" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" dependencies: inherits "^2.0.3" - minimalistic-assert "^1.0.0" + minimalistic-assert "^1.0.1" -hmac-drbg@^1.0.0: +hmac-drbg@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" dependencies: @@ -1745,14 +1745,18 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" +inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" inherits@2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" +inherits@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -2150,11 +2154,11 @@ mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" -minimalistic-assert@^1.0.0: +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" -minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: +minimalistic-crypto-utils@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"