From 9c194995939c4a04d2acb38cf261cce2b4aec418 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Thu, 14 Jul 2022 14:02:37 +0200 Subject: [PATCH 1/3] Add setting for allowing anonymous forums --- lang/en/moodleoverflow.php | 2 +- mod_form.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php index e8e64de575..1c1a83b008 100644 --- a/lang/en/moodleoverflow.php +++ b/lang/en/moodleoverflow.php @@ -412,7 +412,7 @@ $string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)'; $string['anonym_you'] = 'Anonymous (You)'; $string['allowanonymous'] = 'Allow anonymous'; -$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode'; +$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode. Once enabled, anonymous forums will stay anonymous, even when this setting is disabled.'; $string['questioner'] = 'Questioner'; $string['answerer'] = 'Answerer #{$a}'; $string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.'; diff --git a/mod_form.php b/mod_form.php index ae37dd5cc1..9410776316 100644 --- a/mod_form.php +++ b/mod_form.php @@ -82,9 +82,11 @@ public function definition() { $possiblesettings[anonymous::NOT_ANONYMOUS] = get_string('no'); } - $mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings); - $mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow'); - $mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS); + if (get_config('moodleoverflow', 'allowanonymous') == '1') { + $mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings); + $mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow'); + $mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS); + } // Attachments. $mform->addElement('header', 'attachmentshdr', get_string('attachments', 'moodleoverflow')); @@ -220,7 +222,7 @@ public function definition() { * @param array $data data from the form. */ public function data_postprocessing($data) { - if ($data->anonymous != anonymous::NOT_ANONYMOUS) { + if (isset($data->anonymous) && $data->anonymous != anonymous::NOT_ANONYMOUS) { $data->coursewidereputation = false; } } From a7e2d7dc688a3c49cfacf66c15612c8ee30462ac Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Thu, 14 Jul 2022 21:00:08 +0200 Subject: [PATCH 2/3] Add option for admin to reset anonymity for all forums --- lang/en/moodleoverflow.php | 3 +- resetanonymous.php | 60 ++++++++++++++++++++++++++++++++++++++ settings.php | 4 ++- styles.css | 11 +++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 resetanonymous.php diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php index 1c1a83b008..7d672d455f 100644 --- a/lang/en/moodleoverflow.php +++ b/lang/en/moodleoverflow.php @@ -412,8 +412,9 @@ $string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)'; $string['anonym_you'] = 'Anonymous (You)'; $string['allowanonymous'] = 'Allow anonymous'; -$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode. Once enabled, anonymous forums will stay anonymous, even when this setting is disabled.'; +$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode. Once enabled, anonymous forums will stay anonymous, even when this setting is disabled. If you really want to, you can reset anonymity in all forums here.'; $string['questioner'] = 'Questioner'; $string['answerer'] = 'Answerer #{$a}'; $string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.'; $string['desc:anonymous'] = 'No names will be displayed.'; +$string['resetanonymous_warning'] = 'Are you sure? If you are in production, this is most certainly a bad decision, because your students and teachers posted their questions and answers believing they would remain anonymous.

{$a->fullanoncount} forums are currently fully anonymized, and in {$a->questionanoncount} additional forums the questioners are anonymized.

In all these forums, the real names of posters will be displayed again, even in already existing posts!'; diff --git a/resetanonymous.php b/resetanonymous.php new file mode 100644 index 0000000000..f130b33392 --- /dev/null +++ b/resetanonymous.php @@ -0,0 +1,60 @@ +. + +/** + * Resets all forums anonymity level, if the admin really wants to. + * + * @package mod_moodleoverflow + * @copyright 2022 Justus Dieckmann WWU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use mod_moodleoverflow\anonymous; + +require_once('../../config.php'); + +global $DB, $PAGE, $OUTPUT; + +$PAGE->set_url('/mod/moodleoverflow/resetanonymous.php'); +$PAGE->set_context(context_system::instance()); + +require_admin(); + +$confirmed = optional_param('confirmed', false, PARAM_BOOL); + +$returnurl = new moodle_url('/admin/settings.php?section=modsettingmoodleoverflow'); + +if ($confirmed !== 1) { + $a = new stdClass(); + $a->fullanoncount = $DB->count_records('moodleoverflow', + ['anonymous' => anonymous::EVERYTHING_ANONYMOUS]); + $a->questionanoncount = $DB->count_records('moodleoverflow', + ['anonymous' => anonymous::QUESTION_ANONYMOUS]); + echo $OUTPUT->header(); + echo html_writer::div( + $OUTPUT->confirm(get_string('resetanonymous_warning', 'moodleoverflow', $a), + new moodle_url($PAGE->url, ['confirmed' => true, 'sesskey' => sesskey()]), $returnurl), + 'mod_moodleoverflow-hack-primary-to-danger-btn' + ); + echo $OUTPUT->footer(); + die(); +} + +require_sesskey(); + +$DB->execute('UPDATE {moodleoverflow} SET anonymous = ?', [anonymous::NOT_ANONYMOUS]); + +redirect($returnurl); diff --git a/settings.php b/settings.php index cad6481acc..09957e082f 100644 --- a/settings.php +++ b/settings.php @@ -77,9 +77,11 @@ $settings->add(new admin_setting_configselect('moodleoverflow/cleanreadtime', get_string('cleanreadtime', 'moodleoverflow'), get_string('configcleanreadtime', 'moodleoverflow'), 2, $options)); + $url = new moodle_url('/mod/moodleoverflow/resetanonymous.php'); + $settings->add(new admin_setting_configcheckbox('moodleoverflow/allowanonymous', get_string('allowanonymous', 'moodleoverflow'), - get_string('allowanonymous_desc', 'moodleoverflow'), + get_string('allowanonymous_desc', 'moodleoverflow', $url->out(false)), 1 )); diff --git a/styles.css b/styles.css index f47cba4cfe..9f517a6591 100644 --- a/styles.css +++ b/styles.css @@ -520,6 +520,17 @@ span.unread { text-align: right; } +.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary { + background-color: #a90000; + border-color: #a90000; +} + +.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:hover, +.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:focus { + background-color: #900000; + border-color: #900000; +} + @media (max-width: 600px) { .hide-600 { display: none; From eaaa47ff84f201eb78e8193de4db9d8f29087b61 Mon Sep 17 00:00:00 2001 From: Nina Herrmann Date: Fri, 15 Jul 2022 15:59:23 +0200 Subject: [PATCH 3/3] Minor lang string changes add one sentence, and change comma --- lang/en/moodleoverflow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php index 7d672d455f..baf22c92b5 100644 --- a/lang/en/moodleoverflow.php +++ b/lang/en/moodleoverflow.php @@ -417,4 +417,4 @@ $string['answerer'] = 'Answerer #{$a}'; $string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.'; $string['desc:anonymous'] = 'No names will be displayed.'; -$string['resetanonymous_warning'] = 'Are you sure? If you are in production, this is most certainly a bad decision, because your students and teachers posted their questions and answers believing they would remain anonymous.

{$a->fullanoncount} forums are currently fully anonymized, and in {$a->questionanoncount} additional forums the questioners are anonymized.

In all these forums, the real names of posters will be displayed again, even in already existing posts!'; +$string['resetanonymous_warning'] = 'Are you sure? If you are in production, this is most certainly a bad decision because your students and teachers posted their questions and answers, believing they would remain anonymous.

{$a->fullanoncount} forums are currently fully anonymized, and in {$a->questionanoncount} additional forums the questioners are anonymized.

In all these forums, the real names of posters will be displayed again, even in already existing posts!There is no way of reverting those changes!';