* @param \core\event\base $event event object
*/
public static function process_event(\core\event\base $event) {
+ if (!get_config('tool_monitor', 'enablemonitor')) {
+ return; // The tool is disabled. Nothing to do.
+ }
if (empty(self::$instance)) {
self::$instance = new static();
public function execute() {
global $DB;
+ if (!get_config('tool_monitor', 'enablemonitor')) {
+ return; // The tool is disabled. Nothing to do.
+ }
+
// Array to store which events have been triggered in which course.
$courses = array();
'manager' => CAP_ALLOW
),
),
-);
+ 'tool/monitor:managetool' => array(
+ 'riskbitmask' => RISK_XSS, RISK_CONFIG,
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ 'archetypes' => array(
+ 'manager' => CAP_ALLOW
+ ),
+ ),
+);
$coursename = format_string($course->fullname, true, array('context' => $coursecontext));
}
+if (!get_config('tool_monitor', 'enablemonitor')) {
+ // This should never happen as the this page does not appear in navigation when the tool is disabled.
+ throw new coding_exception('Event monitoring is disabled');
+}
+
// Always build the page in site context.
$context = context_system::instance();
$sitename = format_string($SITE->fullname, true, array('context' => $context));
$string['allmodules'] = 'All instances';
$string['area'] = 'Area';
$string['areatomonitor'] = 'Area to monitor';
+$string['contactadmin'] = 'Contact your administrator to enable it.';
$string['core'] = 'Core';
$string['currentsubscriptions'] = 'Your current subscriptions';
$string['defaultmessagetemplate'] = 'Rule name: {rulename}<br />Description: {description}<br />Event name: {eventname}';
$string['disablefieldswarning'] = 'Some fields can not be edited as this rule already has subscriptions.';
$string['duplicaterule'] = 'Duplicate rule';
$string['editrule'] = 'Edit rule';
+$string['enablehelp'] = 'Enable/disable event monitoring';
+$string['enablehelp_help'] = 'Event monitoring must be enabled before it can be used. Please note that enabling event monitoring can have associated permformance implications.';
$string['event'] = 'Event';
$string['eventnotfound'] = 'Event not found';
$string['eventrulecreated'] = 'Rule created';
* Event {eventname}';
$string['messagetemplate_link'] = 'admin/tool/monitor/managerules';
$string['moduleinstance'] = 'Instance';
+$string['monitorenabled'] = 'Event monitoring is currently enabled. ';
+$string['monitordisabled'] = 'Event monitoring is currently disabled.';
$string['monitor:managerules'] = 'Manage event monitor rules';
+$string['monitor:managetool'] = 'Enable/disable event monitoring';
$string['monitor:subscribe'] = 'Subscribe to event monitor rules';
$string['norules'] = 'There are no event monitoring rules.';
$string['pluginname'] = 'Event monitor';
* @param context $context The context of the course
*/
function tool_monitor_extend_navigation_course($navigation, $course, $context) {
-
- if (has_capability('tool/monitor:managerules', $context)) {
+ if (has_capability('tool/monitor:managerules', $context) && get_config('tool_monitor', 'enablemonitor')) {
$url = new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $course->id));
$settingsnode = navigation_node::create(get_string('managerules', 'tool_monitor'), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/settings', ''));
*/
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) {
global $USER;
- if (($USER->id == $user->id) && (has_capability('tool/monitor:subscribe', $coursecontext))) {
+ if (($USER->id == $user->id) && (has_capability('tool/monitor:subscribe', $coursecontext)
+ && get_config('tool_monitor', 'enablemonitor'))) {
$url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $course->id));
$subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
$ruleid = optional_param('ruleid', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$confirm = optional_param('confirm', false, PARAM_BOOL);
+$status = optional_param('status', 0, PARAM_BOOL);
// Validate course id.
if (empty($courseid)) {
admin_externalpage_setup('toolmonitorrules', '', null, '', array('pagelayout' => 'report'));
}
+if (!empty($action) && $action == 'changestatus') {
+ require_sesskey();
+ require_capability('tool/monitor:managetool', context_system::instance());
+ // Toggle status of the plugin.
+ set_config('enablemonitor', $status, 'tool_monitor');
+ redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => 0)));
+}
+
// Copy/delete rule if needed.
if (!empty($action) && $ruleid) {
require_sesskey();
}
echo $OUTPUT->heading(get_string('managerules', 'tool_monitor'));
+$status = get_config('tool_monitor', 'enablemonitor');
+$help = new help_icon('enablehelp', 'tool_monitor');
+
+// Display option to enable/disable the plugin.
+if ($status) {
+ if (has_capability('tool/monitor:managetool', context_system::instance())) {
+ // We don't need to show enabled status to everyone.
+ echo get_string('monitorenabled', 'tool_monitor');
+ $disableurl = new moodle_url("/admin/tool/monitor/managerules.php",
+ array('courseid' => $courseid, 'action' => 'changestatus', 'status' => 0, 'sesskey' => sesskey()));
+ echo ' ' . html_writer::link($disableurl, get_string('disable'));
+ echo $OUTPUT->render($help);
+ }
+} else {
+ echo get_string('monitordisabled', 'tool_monitor');
+ if (has_capability('tool/monitor:managetool', context_system::instance())) {
+ $enableurl = new moodle_url("/admin/tool/monitor/managerules.php",
+ array('courseid' => $courseid, 'action' => 'changestatus', 'status' => 1, 'sesskey' => sesskey()));
+ echo ' ' . html_writer::link($enableurl, get_string('enable'));
+ echo $OUTPUT->render($help);
+ } else {
+ echo get_string('contactadmin', 'tool_monitor');
+ }
+ echo $OUTPUT->footer(); // Do not render anything else.
+ exit();
+}
// Render the rule list.
$renderable = new \tool_monitor\output\managerules\renderable('toolmonitorrules', $manageurl, $courseid);
--- /dev/null
+@javascript @tool @tool_monitor
+Feature: Enable/disable managment of the event monitor
+ In order to manage event monitoring
+ As an admin
+ I need to enable/disable it
+
+ @javascript
+ Scenario: Tool is disabled by default.
+ Given I log in as "admin"
+ When I navigate to "Event monitoring rules" node in "Site administration > Reports"
+ Then I should see "Event monitoring is currently disabled"
+ And I should see "Enable"
+ And I should not see "Add a new rule"
+ And I click on "Enable" "link"
+ And I should see "Event monitoring is currently enabled"
+ And I should see "Disable"
+ And I should see "Add a new rule"
+ And I click on "Disable" "link"
+ And I should see "Event monitoring is currently disabled"
+ And I should not see "Add a new rule"
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "admin"
+ And I navigate to "Event monitoring rules" node in "Site administration > Reports"
+ And I click on "Enable" "link"
+ And I am on homepage
And I follow "Course 1"
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
And I press "Add a new rule"
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "admin"
+ And I navigate to "Event monitoring rules" node in "Site administration > Reports"
+ And I click on "Enable" "link"
+ And I am on homepage
And I follow "Course 1"
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
And I press "Add a new rule"
* Tests for event observers
*/
class tool_monitor_eventobservers_testcase extends advanced_testcase {
+ /**
+ * Set up method.
+ */
+ public function setUp() {
+ // Enable monitor.
+ set_config('enablemonitor', 1, 'tool_monitor');
+ }
/**
* Test observer for course delete event.
* Tests set up.
*/
public function setUp() {
+ set_config('enablemonitor', 1, 'tool_monitor');
$this->resetAfterTest();
}
*/
class tool_monitor_generator_testcase extends advanced_testcase {
+ /**
+ * Set up method.
+ */
+ public function setUp() {
+ // Enable monitor.
+ set_config('enablemonitor', 1, 'tool_monitor');
+ }
+
/**
* Test create_rule data generator.
*/
*/
class tool_monitor_rule_manager_testcase extends advanced_testcase {
+ /**
+ * Set up method.
+ */
+ public function setUp() {
+ // Enable monitor.
+ set_config('enablemonitor', 1, 'tool_monitor');
+ }
+
/**
* Test add_rule method.
*/
* Test set up.
*/
public function setUp() {
+ set_config('enablemonitor', 1, 'tool_monitor');
$this->resetAfterTest(true);
}