Skip to content

Commit

Permalink
Review addition: Add possibility to deactivate re-captcha in accessib…
Browse files Browse the repository at this point in the history
…ility support form
  • Loading branch information
abias committed Dec 29, 2024
1 parent fa34319 commit bd62c55
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
15 changes: 11 additions & 4 deletions classes/form/accessibilitysupport_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,17 @@ public function definition(): void {
$mform->hardFreeze('email');
}

if (!empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey)) {
$mform->addElement('recaptcha', 'recaptcha_element', get_string('security_question', 'auth'));
$mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth');
$mform->closeHeaderBefore('recaptcha_element');
// If the admin enabled re-captcha on this page.
$accessibilitysupportrecaptcha = get_config('theme_boost_union', 'accessibilitysupportrecaptcha');
if (isset($accessibilitysupportrecaptcha) &&
($accessibilitysupportrecaptcha == THEME_BOOST_UNION_SETTING_SELECT_ALWAYS) ||
($accessibilitysupportrecaptcha == THEME_BOOST_UNION_SETTING_SELECT_ONLYGUESTSANDNONLOGGEDIN &&
(!isloggedin() || isguestuser()))) {
if (!empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey)) {
$mform->addElement('recaptcha', 'recaptcha_element', get_string('security_question', 'auth'));
$mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth');
$mform->closeHeaderBefore('recaptcha_element');
}
}

$this->add_action_buttons(true, get_string('submit'));
Expand Down
8 changes: 8 additions & 0 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
$string['configtitle'] = 'Boost Union';
$string['githubissueslink'] = '<a href="https://github.com/moodle-an-hochschulen/moodle-theme_boost_union/issues">Github issues</a>';

// General select options.
$string['never'] = 'Never';
$string['always'] = 'Always';
$string['forguestsonly'] = 'Only for guests and non-logged-in users';

// Settings: General strings.
$string['dontchange'] = 'Do not change anything';

Expand Down Expand Up @@ -1149,6 +1154,9 @@
$string['accessibilitysupportpagesrlinktitledefault'] = 'Get accessibility support';
$string['accessibilitysupportpagesrlinktitlesetting'] = 'Accessibility support page screenreader link title';
$string['accessibilitysupportpagesrlinktitlesetting_desc'] = 'In this setting, you can define the screenreader link title for the accessibility support page. This text will be used as link text which is only shown to screenreaders.';
// ... ... Setting: Add re-captcha to accessibility support page
$string['accessibilitysupportrecaptcha'] = 'Add re-captcha to accessibility support page';
$string['accessibilitysupportrecaptcha_desc'] = 'With this setting, you control if a re-captcha is added to the accessibility support page. This is to prevent spam and abuse of the accessibility support form, just like it is done within <a href="{$a->support}">Moodle core\'s support form</a>. However, adding re-captchas add an additional accessibility barrier for users who use screenreaders or other assistive technologies which might be counter-productive in this case. Thus, please choose wisely if you want to enable this setting. Please also note that, even if enabled, the re-captcha is not shown until you set the necessary <a href="{$a->settings}">API keys in the authentication settings</a>.';

// Settings: Flavours page.
$string['configtitleflavours'] = 'Flavours';
Expand Down
4 changes: 4 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
define('THEME_BOOST_UNION_SETTING_EXTSCSSSOURCE_DOWNLOAD', 1);
define('THEME_BOOST_UNION_SETTING_EXTSCSSSOURCE_GITHUB', 2);

define('THEME_BOOST_UNION_SETTING_SELECT_NEVER', 'never');
define('THEME_BOOST_UNION_SETTING_SELECT_ALWAYS', 'always');
define('THEME_BOOST_UNION_SETTING_SELECT_ONLYGUESTSANDNONLOGGEDIN', 'guestandnonloggedin');

/**
* Returns the main SCSS content.
*
Expand Down
21 changes: 21 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,27 @@
$page->hide_if('theme_boost_union/accessibilitysupportpagesrlinktitle', 'theme_boost_union/enableaccessibilitysupport',
'neq', THEME_BOOST_UNION_SETTING_SELECT_YES);

// Setting: Add re-captcha to accessibility support page.
$name = 'theme_boost_union/accessibilitysupportrecaptcha';
$title = get_string('accessibilitysupportrecaptcha', 'theme_boost_union', null, true);
$authsettingsurl = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
$supportformsurl = new moodle_url('/user/contactsitesupport.php');
$description = get_string('accessibilitysupportrecaptcha_desc', 'theme_boost_union',
['settings' => $authsettingsurl, 'support' => $supportformsurl], true);
$accessibilitysupportrecaptchaoptions = [
THEME_BOOST_UNION_SETTING_SELECT_NEVER =>
get_string('never', 'theme_boost_union'),
THEME_BOOST_UNION_SETTING_SELECT_ALWAYS =>
get_string('always', 'theme_boost_union'),
THEME_BOOST_UNION_SETTING_SELECT_ONLYGUESTSANDNONLOGGEDIN =>
get_string('forguestsonly', 'theme_boost_union'),
];
$setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_NEVER,
$accessibilitysupportrecaptchaoptions);
$tab->add($setting);
$page->hide_if('theme_boost_union/accessibilitysupportrecaptcha', 'theme_boost_union/enableaccessibilitysupport',
'neq', THEME_BOOST_UNION_SETTING_SELECT_YES);

// Add tab to settings page.
$page->add($tab);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,30 @@ Feature: Configuring the theme_boost_union plugin for the "Support page" tab on

# Unfortunately, this can't be tested with Behat yet as we do not have a way to test sent emails yet (or rather block the sending of the email).
# Scenario: Sending the accessibility support form fails and the fallback message is shown

@javascript
Scenario Outline: Setting: Add re-captcha to accessibility support page
Given the following config values are set as admin:
| config | value |
| recaptchapublickey | foo |
| recaptchaprivatekey | bar |
And the following config values are set as admin:
| config | value | plugin |
| enableaccessibilitysupport | yes | theme_boost_union |
| allowaccessibilitysupportwithoutlogin | yes | theme_boost_union |
| accessibilitysupportrecaptcha | <setting> | theme_boost_union |
When I am on accessibilitysupport page
Then "#fitem_id_recaptcha_element" "css_element" <nonshouldornot> exist
And I log in as "guest"
And I am on accessibilitysupport page
And "#fitem_id_recaptcha_element" "css_element" <guestshouldornot> exist
And I log out
And I log in as "student1"
And I am on accessibilitysupport page
And "#fitem_id_recaptcha_element" "css_element" <usershouldornot> exist

Examples:
| setting | nonshouldornot | guestshouldornot | usershouldornot |
| never | should not | should not | should not |
| always | should | should | should |
| guestandnonloggedin | should | should | should not |

0 comments on commit bd62c55

Please sign in to comment.