mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-47871 tool_monitor: allow teachers to duplicate site rules
This commit is contained in:
parent
da0ef2e4cf
commit
bb286b6d5f
@ -164,29 +164,32 @@ class renderable extends \table_sql implements \renderable {
|
||||
*/
|
||||
public function col_manage(\tool_monitor\rule $rule) {
|
||||
global $OUTPUT, $CFG;
|
||||
|
||||
$manage = '';
|
||||
// We don't need to check for capability at course level since, user is never shown this page,
|
||||
// if he doesn't have the capability.
|
||||
|
||||
// Do not allow the user to edit the rule unless they have the system capability, or we are viewing the rules
|
||||
// for a course, and not the site. Note - we don't need to check for the capability at a course level since
|
||||
// the user is never shown this page otherwise.
|
||||
if ($this->hassystemcap || ($rule->courseid != 0)) {
|
||||
// There might be site rules which the user can not manage.
|
||||
$editurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/edit.php', array('ruleid' => $rule->id,
|
||||
'courseid' => $rule->courseid, 'sesskey' => sesskey()));
|
||||
$copyurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
|
||||
array('ruleid' => $rule->id, 'action' => 'copy', 'courseid' => $this->courseid, 'sesskey' => sesskey()));
|
||||
$deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', array('ruleid' => $rule->id,
|
||||
'action' => 'delete', 'courseid' => $rule->courseid, 'sesskey' => sesskey()));
|
||||
|
||||
$icon = $OUTPUT->render(new \pix_icon('t/edit', get_string('editrule', 'tool_monitor')));
|
||||
$manage .= \html_writer::link($editurl, $icon, array('class' => 'action-icon'));
|
||||
}
|
||||
|
||||
$icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor')));
|
||||
$manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon'));
|
||||
// The user should always be able to copy the rule if they are able to view the page.
|
||||
$copyurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
|
||||
array('ruleid' => $rule->id, 'action' => 'copy', 'courseid' => $this->courseid, 'sesskey' => sesskey()));
|
||||
$icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor')));
|
||||
$manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon'));
|
||||
|
||||
if ($this->hassystemcap || ($rule->courseid != 0)) {
|
||||
$deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', array('ruleid' => $rule->id,
|
||||
'action' => 'delete', 'courseid' => $rule->courseid, 'sesskey' => sesskey()));
|
||||
$icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor')));
|
||||
$manage .= \html_writer::link($deleteurl, $icon, array('class' => 'action-icon'));
|
||||
} else {
|
||||
$manage = get_string('nopermission', 'tool_monitor');
|
||||
}
|
||||
|
||||
return $manage;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,6 @@ $string['manage'] = 'Manage';
|
||||
$string['managesubscriptions'] = 'Event monitoring';
|
||||
$string['managerules'] = 'Event monitoring rules';
|
||||
$string['messageprovider:notification'] = 'Notifications of rule subscriptions';
|
||||
$string['nopermission'] = 'No permission';
|
||||
$string['messagetemplate'] = 'Notification message';
|
||||
$string['messagetemplate_help'] = 'A notification message is sent to subscribers once the notification threshold has been reached. It can include any or all of the following placeholders:
|
||||
<br /><br />
|
||||
|
@ -78,13 +78,14 @@ if (!empty($action) && $ruleid) {
|
||||
|
||||
echo $OUTPUT->header();
|
||||
$rule = \tool_monitor\rule_manager::get_rule($rule);
|
||||
if ($rule->can_manage_rule()) {
|
||||
switch ($action) {
|
||||
case 'copy' :
|
||||
$rule->duplicate_rule($courseid);
|
||||
echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess');
|
||||
break;
|
||||
case 'delete' :
|
||||
switch ($action) {
|
||||
case 'copy':
|
||||
// No need to check for capability here as it is done at the start of the page.
|
||||
$rule->duplicate_rule($courseid);
|
||||
echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess');
|
||||
break;
|
||||
case 'delete':
|
||||
if ($rule->can_manage_rule()) {
|
||||
$confirmurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
|
||||
array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete',
|
||||
'confirm' => true, 'sesskey' => sesskey()));
|
||||
@ -103,12 +104,12 @@ if (!empty($action) && $ruleid) {
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
// User doesn't have permissions. Should never happen for real users.
|
||||
throw new moodle_exception('rulenopermissions', 'tool_monitor', $manageurl, $action);
|
||||
} else {
|
||||
// User doesn't have permissions. Should never happen for real users.
|
||||
throw new moodle_exception('rulenopermissions', 'tool_monitor', $manageurl, $action);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->header();
|
||||
|
@ -97,7 +97,7 @@ Feature: tool_monitor_rule
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
|
||||
When I click on "Duplicate rule" "link"
|
||||
When I click on "Duplicate rule" "link" in the "New rule course level" "table_row"
|
||||
Then I should see "Rule successfully duplicated"
|
||||
And "#toolmonitorrules_r1" "css_element" should appear before "#toolmonitorrules_r2" "css_element"
|
||||
And I should see "New rule"
|
||||
@ -153,9 +153,10 @@ Feature: tool_monitor_rule
|
||||
And I should see "5 time(s) in 5 minute(s)"
|
||||
|
||||
Scenario: Duplicate a rule on site level
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Event monitoring rules" node in "Site administration > Reports"
|
||||
When I click on "Duplicate rule" "link"
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
|
||||
When I click on "Duplicate rule" "link" in the "New rule site level" "table_row"
|
||||
Then I should see "Rule successfully duplicated"
|
||||
And "#toolmonitorrules_r2" "css_element" should appear after "#toolmonitorrules_r1" "css_element"
|
||||
And I should see "I want a rule to monitor posts created on a forum"
|
||||
|
Loading…
x
Reference in New Issue
Block a user