Skip to content

Commit

Permalink
Merge branch 'wip_MDL-40949_m28_pathsettings' of https://github.com/s…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Oct 29, 2014
2 parents 5d5e545 + 5aaac8b commit 4f82670
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
$string['errorwithsettings'] = 'Some settings were not changed due to an error.';
$string['everyonewhocan'] = 'Everyone who can \'{$a}\'';
$string['exceptions'] = 'exceptions';
$string['execpathnotallowed'] = 'Setting executable paths disabled in config.php';
$string['execpathnotallowed'] = 'Setting executable and local paths disabled in config.php';
$string['experimental'] = 'Experimental';
$string['experimentalsettings'] = 'Experimental settings';
$string['extendedusernamechars'] = 'Allow extended characters in usernames';
Expand Down
20 changes: 17 additions & 3 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,7 @@ public function __construct($name, $visiblename, $description, $defaultdirectory
* @return string XHTML field
*/
public function output_html($data, $query='') {
global $CFG;
$default = $this->get_defaultsetting();

if ($data) {
Expand All @@ -2436,9 +2437,14 @@ public function output_html($data, $query='') {
} else {
$executable = '';
}
$readonly = '';
if (!empty($CFG->preventexecpath)) {
$this->visiblename .= '<div class="form-overridden">'.get_string('execpathnotallowed', 'admin').'</div>';
$readonly = 'readonly="readonly"';
}

return format_admin_setting($this, $this->visiblename,
'<div class="form-file defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
'<div class="form-file defaultsnext"><input '.$readonly.' type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
$this->description, true, '', $default, $query);
}

Expand Down Expand Up @@ -2490,12 +2496,14 @@ public function output_html($data, $query='') {
} else {
$executable = '';
}
$readonly = '';
if (!empty($CFG->preventexecpath)) {
$this->visiblename .= '<div class="form-overridden">'.get_string('execpathnotallowed', 'admin').'</div>';
$readonly = 'readonly="readonly"';
}

return format_admin_setting($this, $this->visiblename,
'<div class="form-file defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
'<div class="form-file defaultsnext"><input '.$readonly.' type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
$this->description, true, '', $default, $query);
}
}
Expand All @@ -2516,6 +2524,7 @@ class admin_setting_configdirectory extends admin_setting_configfile {
* @return string XHTML
*/
public function output_html($data, $query='') {
global $CFG;
$default = $this->get_defaultsetting();

if ($data) {
Expand All @@ -2527,9 +2536,14 @@ public function output_html($data, $query='') {
} else {
$executable = '';
}
$readonly = '';
if (!empty($CFG->preventexecpath)) {
$this->visiblename .= '<div class="form-overridden">'.get_string('execpathnotallowed', 'admin').'</div>';
$readonly = 'readonly="readonly"';
}

return format_admin_setting($this, $this->visiblename,
'<div class="form-file defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
'<div class="form-file defaultsnext"><input '.$readonly.' type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
$this->description, true, '', $default, $query);
}
}
Expand Down
24 changes: 23 additions & 1 deletion lib/tests/admintree_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function test_preventexecpath() {
$setting->write_setting('/mm/nn');
$this->assertSame('', get_config('abc_cde', 'execpath'));

// This also (most probably incorrectly) affects admin_setting_configfile.
// This also affects admin_setting_configfile and admin_setting_configdirectory.

set_config('preventexecpath', 0);
set_config('execpath', null, 'abc_cde');
Expand All @@ -297,5 +297,27 @@ public function test_preventexecpath() {
$setting->write_setting('/mm/nn');
$this->assertSame('', get_config('abc_cde', 'execpath'));

set_config('preventexecpath', 0);
set_config('execpath', null, 'abc_cde');
$this->assertFalse(get_config('abc_cde', 'execpath'));
$setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', '/xx/yy');
$setting->write_setting('/oo/pp');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));

// Prevent changes.
set_config('preventexecpath', 1);
$setting->write_setting('/mm/nn');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));

// Use default in install.
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('/xx/yy', get_config('abc_cde', 'execpath'));

// Use empty value if no default.
$setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', null);
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('', get_config('abc_cde', 'execpath'));
}
}

0 comments on commit 4f82670

Please sign in to comment.