From 1740a1d9492c96916d97db9e6244fc006df3c717 Mon Sep 17 00:00:00 2001 From: DAVID Titouan Date: Mon, 20 Nov 2017 10:54:34 +0100 Subject: [PATCH 1/3] issue 240 desactivation checkbox resultat public changement du nom de l'option "resultat visible" dans password en "seul les votes sont proteges" correction de l'ajout du js pour issue240 correction test pour desactivation dynamique du champ --- adminstuds.php | 6 +++++- js/app/studs.js | 4 ++++ locale/br.json | 1 + locale/de.json | 1 + locale/en.json | 1 + locale/es.json | 1 + locale/fr.json | 1 + locale/it.json | 1 + locale/nl.json | 1 + locale/oc.json | 1 + tpl/part/poll_info.tpl | 4 ++-- 11 files changed, 19 insertions(+), 3 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index a6f22ef..02fe5b5 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -137,6 +137,7 @@ if (isset($_POST['update_poll_info'])) { $hidden = isset($_POST['hidden']) ? $inputService->filterBoolean($_POST['hidden']) : false; if ($hidden !== $poll->hidden) { $poll->hidden = $hidden; + $poll->results_publicly_visible = false; $updated = true; } } elseif ($field === 'removePassword') { @@ -153,7 +154,10 @@ if (isset($_POST['update_poll_info'])) { $poll->password_hash = PasswordHasher::hash($password); $updated = true; } - if ($resultsPubliclyVisible !== $poll->results_publicly_visible) { + if ($poll->password_hash == null || $poll->hidden == true){ + $poll->results_publicly_visible = false; + } + if ($resultsPubliclyVisible != $poll->results_publicly_visible && $poll->password_hash != null && $poll->hidden == false) { $poll->results_publicly_visible = $resultsPubliclyVisible; $updated = true; } diff --git a/js/app/studs.js b/js/app/studs.js index 71e360c..9ee6696 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -103,4 +103,8 @@ $(document).ready(function () { return false; }); + $('#password').on('keyup change', function () { + if($('#password').val() && !($('#hidden').attr('checked'))){$('#resultsPubliclyVisible').removeAttr('disabled');} + else {$('#resultsPubliclyVisible').attr('disabled','disabled');}; + }); }); diff --git a/locale/br.json b/locale/br.json index e51dde2..9f8990a 100644 --- a/locale/br.json +++ b/locale/br.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Nullañ embann an aotreoù", "Results are hidden.": "Kuzhet eo an disoc'hoù.", "Results are visible.": "Gwelus eo an disoc'hoù.", + "Only votes are protected": "Only votes are protected", "Password protected": "Gwarezet gant ur ger-tremen", "Votes protected by password": "Gwarezet eo ar mouezhioù gant ur ger-tremen", "No password": "Ger-tremen ebet", diff --git a/locale/de.json b/locale/de.json index d79b339..8b32bb7 100644 --- a/locale/de.json +++ b/locale/de.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Abbruch, Regeln nicht ändern", "Results are hidden": "Ergebnisse werden ausgeblendet", "Results are visible": "Ergebnisse sind sichtbar", + "Only votes are protected": "Only votes are protected", "Password protected": "Passwortgeschützt", "Votes protected by password": "Wertungen sind passwortgeschützt", "No password": "Kein Passwort", diff --git a/locale/en.json b/locale/en.json index 75cc5a7..cf005a9 100644 --- a/locale/en.json +++ b/locale/en.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Cancel the rules edit", "Results are hidden": "Results are hidden", "Results are visible": "Results are visible", + "Only votes are protected": "Only votes are protected", "Password protected": "Password protected", "Votes protected by password": "Votes protected by password", "No password": "No password", diff --git a/locale/es.json b/locale/es.json index f9067e3..a267524 100644 --- a/locale/es.json +++ b/locale/es.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "ES_Annuler le changement de permissions", "Results are hidden": "Los resutaldos no son visibles", "Results are visible": "Los resultados son visibles", + "Only votes are protected": "Only votes are protected", "Password protected": "ES_Protégé par mot de passe", "Votes protected by password": "ES_Votes protégés par mot de passe", "No password": "ES_Pas de mot de passe", diff --git a/locale/fr.json b/locale/fr.json index c1d67df..d6288a4 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Annuler le changement de permissions", "Results are hidden": "Les résultats sont cachés", "Results are visible": "Les résultats sont visibles", + "Only votes are protected": "Seul les votes sont protégés", "Password protected": "Protégé par mot de passe", "Votes protected by password": "Votes protégés par mot de passe", "No password": "Pas de mot de passe", diff --git a/locale/it.json b/locale/it.json index 3299d08..112a881 100644 --- a/locale/it.json +++ b/locale/it.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Annullare le modifica dei permessi", "Results are hidden": "I risultati sono nascosti", "Results are visible": "I risultati sono visibili", + "Only votes are protected": "Solo voti sono protetti", "Password protected": "Protetto da una password", "Votes protected by password": "Voti protetti da una password", "No password": "Nessuna password", diff --git a/locale/nl.json b/locale/nl.json index 1ca27e4..3f17a53 100644 --- a/locale/nl.json +++ b/locale/nl.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Regels bewerken annuleren", "Results are hidden": "Resultaten zijn verborgen.", "Results are visible": "Resultaten zijn zichtbaar.", + "Only votes are protected": "Only votes are protected", "Password protected": "Beveiligd met een wachtwoord", "Votes protected by password": "Stemmen beveiligd met een wachtwoord", "No password": "Geen wachtwoord", diff --git a/locale/oc.json b/locale/oc.json index 18cd661..e2a9811 100644 --- a/locale/oc.json +++ b/locale/oc.json @@ -128,6 +128,7 @@ "Cancel the rules edit": "Anullar lo cambiament de permissions", "Results are hidden": "Los resultats son amagats", "Results are visible": "Los resultats son visibles", + "Only votes are protected": "Only votes are protected", "Password protected": "Protegit per senhal", "Votes protected by password": "Vòtes protegits per senhal", "No password": "Pas cap de senhal", diff --git a/tpl/part/poll_info.tpl b/tpl/part/poll_info.tpl index ebf3562..51a43de 100644 --- a/tpl/part/poll_info.tpl +++ b/tpl/part/poll_info.tpl @@ -154,8 +154,8 @@ {/if}
- results_publicly_visible}checked="checked"{/if}/> - + results_publicly_visible && $poll->hidden == false && (!empty($poll->password_hash))}checked="checked" {elseif ($poll->hidden == true || empty($poll->password_hash))} disabled="disabled"{/if}/> +
From e9deb8d22e8145884bd8011a815ae63b00c2338b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 20 Feb 2018 10:58:50 +0100 Subject: [PATCH 2/3] run CS Signed-off-by: Thomas Citharel --- adminstuds.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 02fe5b5..b642d84 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -154,10 +154,10 @@ if (isset($_POST['update_poll_info'])) { $poll->password_hash = PasswordHasher::hash($password); $updated = true; } - if ($poll->password_hash == null || $poll->hidden == true){ + if ($poll->password_hash === null || $poll->hidden === true){ $poll->results_publicly_visible = false; } - if ($resultsPubliclyVisible != $poll->results_publicly_visible && $poll->password_hash != null && $poll->hidden == false) { + if ($resultsPubliclyVisible !== $poll->results_publicly_visible && $poll->password_hash !== null && $poll->hidden === false) { $poll->results_publicly_visible = $resultsPubliclyVisible; $updated = true; } From 2310333f8d0e219c9a01e0b2ac13bcf60ba576e5 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 20 Feb 2018 11:55:14 +0100 Subject: [PATCH 3/3] Adds some comments to understand the logic Signed-off-by: Thomas Citharel --- adminstuds.php | 21 ++++++++++++++++++--- js/app/studs.js | 14 ++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index b642d84..0d03059 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -149,14 +149,29 @@ if (isset($_POST['update_poll_info'])) { } } elseif ($field === 'password') { $password = isset($_POST['password']) ? $_POST['password'] : null; + + /** + * Did the user choose results to be publicly visible ? + */ $resultsPubliclyVisible = isset($_POST['resultsPubliclyVisible']) ? $inputService->filterBoolean($_POST['resultsPubliclyVisible']) : false; + /** + * If there's one, save the password + */ if (!empty($password)) { $poll->password_hash = PasswordHasher::hash($password); $updated = true; } - if ($poll->password_hash === null || $poll->hidden === true){ - $poll->results_publicly_visible = false; - } + + /** + * If not pasword was set and the poll should be hidden, hide the results + */ + if ($poll->password_hash === null || $poll->hidden === true) { + $poll->results_publicly_visible = false; + } + + /** + * We don't have a password, the poll is hidden and we change the results public visibility + */ if ($resultsPubliclyVisible !== $poll->results_publicly_visible && $poll->password_hash !== null && $poll->hidden === false) { $poll->results_publicly_visible = $resultsPubliclyVisible; $updated = true; diff --git a/js/app/studs.js b/js/app/studs.js index 9ee6696..7ebef8c 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -103,8 +103,14 @@ $(document).ready(function () { return false; }); - $('#password').on('keyup change', function () { - if($('#password').val() && !($('#hidden').attr('checked'))){$('#resultsPubliclyVisible').removeAttr('disabled');} - else {$('#resultsPubliclyVisible').attr('disabled','disabled');}; - }); + /** + * Disable view public results option when there's a password and the poll is not hidden + */ + $('#password').on('keyup change', function () { + if($('#password').val() && !($('#hidden').attr('checked'))){ + $('#resultsPubliclyVisible').removeAttr('disabled'); + } else { + $('#resultsPubliclyVisible').attr('disabled','disabled'); + } + }); });