MDL-35661 Loading of plugin settings for webservices plugins (plugininfo_webservice)

- webservicesettings must be only created if user has site:config capability, otherwise the nodes are added to non-existing parent
This commit is contained in:
Marina Glancy
2012-10-09 09:58:00 +08:00
parent c517dd68f7
commit 2567584d5e
2 changed files with 47 additions and 12 deletions
+44
View File
@@ -2786,3 +2786,47 @@ class plugininfo_plagiarism extends plugininfo_base {
}
}
}
/**
* Class for webservice protocols
*/
class plugininfo_webservice extends plugininfo_base {
public function get_settings_section_name() {
return 'webservicesetting' . $this->name;
}
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them
$ADMIN = $adminroot; // may be used in settings.php
$webservice = $this; // also can be used inside settings.php
$section = $this->get_settings_section_name();
$settings = null;
if ($hassiteconfig && file_exists($this->full_path('settings.php'))) {
$settings = new admin_settingpage($section, $this->displayname,
'moodle/site:config', $this->is_enabled() === false);
include($this->full_path('settings.php')); // this may also set $settings to null
}
if ($settings) {
$ADMIN->add($parentnodename, $settings);
}
}
public function is_enabled() {
global $CFG;
if (empty($CFG->enablewebservices)) {
return false;
}
$active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
if (in_array($this->name, $active_webservices)) {
return true;
}
return false;
}
public function get_uninstall_url() {
return new moodle_url('/admin/webservice/protocols.php',
array('sesskey' => sesskey(), 'action' => 'uninstall', 'webservice' => $this->name));
}
}