MDL-15594 url: Add setting to enable parameters for URL

This commit is contained in:
Kevin Percy
2024-04-04 12:35:30 +08:00
parent 4da813d35e
commit a7cb6a8de6
8 changed files with 99 additions and 25 deletions
+10
View File
@@ -1144,5 +1144,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2024032600.01);
}
if ($oldversion < 2024040200.01) {
// Enable variables to be set for URL resource.
if (!get_config('url', 'allowvariables')) {
set_config('allowvariables', true, 'url');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2024040200.01);
}
return true;
}
+2
View File
@@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['allowvariables'] = 'Allow URL variables';
$string['allowvariables_desc'] = 'Allow variables to be added to URLs. Variables enable you to pass internal information, such as the user\'s name, as part of the URL. Be aware of potential privacy risks when using this feature.';
$string['clicktoopen'] = 'Click on {$a} to open the resource.';
$string['configdisplayoptions'] = 'Select all options that should be available, existing settings are not modified. Hold CTRL key to select multiple fields.';
$string['configframesize'] = 'When a web page or an uploaded file is displayed within a frame, this value is the height (in pixels) of the top frame (which contains the navigation).';
+5 -4
View File
@@ -114,11 +114,12 @@ function url_get_full_url($url, $cm, $course, $config=null) {
$fullurl = str_replace('>', '%3E', $fullurl);
}
if (!$config) {
$config = get_config('url');
}
// add variable url parameters
if (!empty($parameters)) {
if (!$config) {
$config = get_config('url');
}
if ($config->allowvariables && !empty($parameters)) {
$paramvalues = url_get_variable_values($url, $cm, $course, $config);
foreach ($parameters as $parse=>$parameter) {
+21 -19
View File
@@ -100,27 +100,29 @@ class mod_url_mod_form extends moodleform_mod {
}
//-------------------------------------------------------
$mform->addElement('header', 'parameterssection', get_string('parametersheader', 'url'));
$mform->addElement('static', 'parametersinfo', '', get_string('parametersheader_help', 'url'));
if ($config->allowvariables) {
$mform->addElement('header', 'parameterssection', get_string('parametersheader', 'url'));
$mform->addElement('static', 'parametersinfo', '', get_string('parametersheader_help', 'url'));
if (empty($this->current->parameters)) {
$parcount = 5;
} else {
$parcount = 5 + count((array) unserialize_array($this->current->parameters));
$parcount = ($parcount > 100) ? 100 : $parcount;
}
$options = url_get_variable_options($config);
if (empty($this->current->parameters)) {
$parcount = 5;
} else {
$parcount = 5 + count((array)unserialize_array($this->current->parameters));
$parcount = ($parcount > 100) ? 100 : $parcount;
}
$options = url_get_variable_options($config);
for ($i=0; $i < $parcount; $i++) {
$parameter = "parameter_$i";
$variable = "variable_$i";
$pargroup = "pargoup_$i";
$group = array(
$mform->createElement('text', $parameter, '', array('size'=>'12')),
$mform->createElement('selectgroups', $variable, '', $options),
);
$mform->addGroup($group, $pargroup, get_string('parameterinfo', 'url'), ' ', false);
$mform->setType($parameter, PARAM_RAW);
for ($i = 0; $i < $parcount; $i++) {
$parameter = "parameter_$i";
$variable = "variable_$i";
$pargroup = "pargoup_$i";
$group = [
$mform->createElement('text', $parameter, '', ['size' => '12']),
$mform->createElement('selectgroups', $variable, '', $options),
];
$mform->addGroup($group, $pargroup, get_string('parameterinfo', 'url'), ' ', false);
$mform->setType($parameter, PARAM_RAW);
}
}
//-------------------------------------------------------
+3
View File
@@ -46,8 +46,11 @@ if ($ADMIN->fulltree) {
get_string('framesize', 'url'), get_string('configframesize', 'url'), 130, PARAM_INT));
$settings->add(new admin_setting_configpasswordunmask('url/secretphrase', get_string('password'),
get_string('configsecretphrase', 'url'), ''));
$settings->add(new admin_setting_configcheckbox('url/allowvariables',
get_string('allowvariables', 'url'), get_string('allowvariables_desc', 'url'), false));
$settings->add(new admin_setting_configcheckbox('url/rolesinparams',
get_string('rolesinparams', 'url'), get_string('configrolesinparams', 'url'), false));
$settings->hide_if('url/rolesinparams', 'url/allowvariables');
$settings->add(new admin_setting_configmultiselect('url/displayoptions',
get_string('displayoptions', 'url'), get_string('configdisplayoptions', 'url'),
$defaultdisplayoptions, $displayoptions));
+52
View File
@@ -0,0 +1,52 @@
@mod @mod_url @javascript
Feature: Manage URL variables
In order to maintain privacy for URLs
As a teacher
I need to be able to manage URL variables safely
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
Scenario: Disabling URL variables hides Role names as URL variables check box
Given the following config values are set as admin:
| allowvariables | 1 | url |
And I log in as "admin"
And I navigate to "Plugins > Activity modules > URL" in site administration
When I click on "Allow URL variables" "checkbox"
Then I should not see "Role names as URL variables"
And I click on "Allow URL variables" "checkbox"
And I should see "Role names as URL variables"
Scenario: Disable the use of URL variables
Given the following config values are set as admin:
| allowvariables | 0 | url |
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "URL" to section "1" using the activity chooser
Then I should not see "URL variables"
Scenario: Enable the use of URL variables without role names
Given the following config values are set as admin:
| allowvariables | 1 | url |
| rolesinparams | 0 | url |
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "URL" to section "1" using the activity chooser
Then I should see "URL variables"
And I expand all fieldsets
And I should see "Full site name" in the "id_variable_0" "select"
But I should not see "Roles" in the "id_variable_0" "select"
Scenario: Enable the use of URL variables with role names
Given the following config values are set as admin:
| allowvariables | 1 | url |
| rolesinparams | 1 | url |
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "URL" to section "1" using the activity chooser
Then I should see "URL variables"
And I expand all fieldsets
And I should see "Full site name" in the "id_variable_0" "select"
And I should see "Your word for 'Student'" in the "id_variable_0" "select"
+5 -1
View File
@@ -1,4 +1,8 @@
This files describes API changes in the quiz code.
This files describes API changes in the URL code.
=== 4.4 ===
* A new admin setting "Allow URL variables" has been added, which allows/disallows the use of variables for URL resources. Variables enable you to pass internal information, such as the user's name, as part of the URL.
=== 4.0 ===
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2024040200.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2024040200.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.4dev+ (Build: 20240402)'; // Human-friendly version name