mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-47871 tool_monitor: allow teachers to duplicate site rules
This commit is contained in:
parent
da0ef2e4cf
commit
bb286b6d5f
4 changed files with 34 additions and 30 deletions
|
@ -164,29 +164,32 @@ class renderable extends \table_sql implements \renderable {
|
||||||
*/
|
*/
|
||||||
public function col_manage(\tool_monitor\rule $rule) {
|
public function col_manage(\tool_monitor\rule $rule) {
|
||||||
global $OUTPUT, $CFG;
|
global $OUTPUT, $CFG;
|
||||||
|
|
||||||
$manage = '';
|
$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)) {
|
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,
|
$editurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/edit.php', array('ruleid' => $rule->id,
|
||||||
'courseid' => $rule->courseid, 'sesskey' => sesskey()));
|
'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')));
|
$icon = $OUTPUT->render(new \pix_icon('t/edit', get_string('editrule', 'tool_monitor')));
|
||||||
$manage .= \html_writer::link($editurl, $icon, array('class' => 'action-icon'));
|
$manage .= \html_writer::link($editurl, $icon, array('class' => 'action-icon'));
|
||||||
|
}
|
||||||
|
|
||||||
$icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor')));
|
// The user should always be able to copy the rule if they are able to view the page.
|
||||||
$manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon'));
|
$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')));
|
$icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor')));
|
||||||
$manage .= \html_writer::link($deleteurl, $icon, array('class' => 'action-icon'));
|
$manage .= \html_writer::link($deleteurl, $icon, array('class' => 'action-icon'));
|
||||||
} else {
|
|
||||||
$manage = get_string('nopermission', 'tool_monitor');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $manage;
|
return $manage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ $string['manage'] = 'Manage';
|
||||||
$string['managesubscriptions'] = 'Event monitoring';
|
$string['managesubscriptions'] = 'Event monitoring';
|
||||||
$string['managerules'] = 'Event monitoring rules';
|
$string['managerules'] = 'Event monitoring rules';
|
||||||
$string['messageprovider:notification'] = 'Notifications of rule subscriptions';
|
$string['messageprovider:notification'] = 'Notifications of rule subscriptions';
|
||||||
$string['nopermission'] = 'No permission';
|
|
||||||
$string['messagetemplate'] = 'Notification message';
|
$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:
|
$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 />
|
<br /><br />
|
||||||
|
|
|
@ -78,13 +78,14 @@ if (!empty($action) && $ruleid) {
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
$rule = \tool_monitor\rule_manager::get_rule($rule);
|
$rule = \tool_monitor\rule_manager::get_rule($rule);
|
||||||
if ($rule->can_manage_rule()) {
|
switch ($action) {
|
||||||
switch ($action) {
|
case 'copy':
|
||||||
case 'copy' :
|
// No need to check for capability here as it is done at the start of the page.
|
||||||
$rule->duplicate_rule($courseid);
|
$rule->duplicate_rule($courseid);
|
||||||
echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess');
|
echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess');
|
||||||
break;
|
break;
|
||||||
case 'delete' :
|
case 'delete':
|
||||||
|
if ($rule->can_manage_rule()) {
|
||||||
$confirmurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
|
$confirmurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
|
||||||
array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete',
|
array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete',
|
||||||
'confirm' => true, 'sesskey' => sesskey()));
|
'confirm' => true, 'sesskey' => sesskey()));
|
||||||
|
@ -103,12 +104,12 @@ if (!empty($action) && $ruleid) {
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
default:
|
// 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.
|
break;
|
||||||
throw new moodle_exception('rulenopermissions', 'tool_monitor', $manageurl, $action);
|
default:
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
|
@ -97,7 +97,7 @@ Feature: tool_monitor_rule
|
||||||
Given I log in as "teacher1"
|
Given I log in as "teacher1"
|
||||||
And I follow "Course 1"
|
And I follow "Course 1"
|
||||||
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
|
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"
|
Then I should see "Rule successfully duplicated"
|
||||||
And "#toolmonitorrules_r1" "css_element" should appear before "#toolmonitorrules_r2" "css_element"
|
And "#toolmonitorrules_r1" "css_element" should appear before "#toolmonitorrules_r2" "css_element"
|
||||||
And I should see "New rule"
|
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)"
|
And I should see "5 time(s) in 5 minute(s)"
|
||||||
|
|
||||||
Scenario: Duplicate a rule on site level
|
Scenario: Duplicate a rule on site level
|
||||||
Given I log in as "admin"
|
Given I log in as "teacher1"
|
||||||
And I navigate to "Event monitoring rules" node in "Site administration > Reports"
|
And I follow "Course 1"
|
||||||
When I click on "Duplicate rule" "link"
|
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"
|
Then I should see "Rule successfully duplicated"
|
||||||
And "#toolmonitorrules_r2" "css_element" should appear after "#toolmonitorrules_r1" "css_element"
|
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"
|
And I should see "I want a rule to monitor posts created on a forum"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue