From ce9d54b9f3de1a359ff985b69cd863ddc0f1c1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 24 Feb 2013 13:28:48 +0100 Subject: [PATCH] MDL-38096 use separate manual enrol and unenrol capabilities in UI --- enrol/manual/lib.php | 6 ++++-- enrol/manual/manage.php | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 5b6ae7ecb5e..9dae1075546 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -68,7 +68,9 @@ class enrol_manual_plugin extends enrol_plugin { $context = context_course::instance($instance->courseid, MUST_EXIST); - if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) { + if (!has_capability('enrol/manual:enrol', $context) and !has_capability('enrol/manual:unenrol', $context)) { + // Note: manage capability not used here because it is used for editing + // of existing enrolments which is not possible here. return NULL; } @@ -111,7 +113,7 @@ class enrol_manual_plugin extends enrol_plugin { $icons = array(); - if (has_capability('enrol/manual:manage', $context)) { + if (has_capability('enrol/manual:enrol', $context) or has_capability('enrol/manual:unenrol', $context)) { $managelink = new moodle_url("/enrol/manual/manage.php", array('enrolid'=>$instance->id)); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall'))); } diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index f7eab0442f3..7d91e4b6017 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -35,9 +35,17 @@ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_ $context = context_course::instance($course->id, MUST_EXIST); require_login($course); -require_capability('enrol/manual:enrol', $context); -require_capability('enrol/manual:manage', $context); -require_capability('enrol/manual:unenrol', $context); +$canenrol = has_capability('enrol/manual:enrol', $context); +$canunenrol = has_capability('enrol/manual:unenrol', $context); + +// Note: manage capability not used here because it is used for editing +// of existing enrolments which is not possible here. + +if (!$canenrol and !$canunenrol) { + // No need to invent new error strings here... + require_capability('enrol/manual:enrol', $context); + require_capability('enrol/manual:unenrol', $context); +} if ($roleid < 0) { $roleid = $instance->roleid; @@ -95,7 +103,7 @@ if ($course->startdate > 0) { $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; // Process add and removes. -if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { +if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoassign = $potentialuserselector->get_selected_users(); if (!empty($userstoassign)) { foreach($userstoassign as $adduser) { @@ -126,7 +134,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { } // Process incoming role unassignments. -if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { +if ($canunenrol && optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { $userstounassign = $currentuserselector->get_selected_users(); if (!empty($userstounassign)) { foreach($userstounassign as $removeuser) { @@ -145,6 +153,9 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { echo $OUTPUT->header(); echo $OUTPUT->heading($instancename); +$addenabled = $canenrol ? '' : 'disabled="disabled"'; +$removeenabled = $canunenrol ? '' : 'disabled="disabled"'; + ?>
@@ -157,7 +168,7 @@ echo $OUTPUT->heading($instancename);
-
+ id="add" type="submit" value="larrow().' '.get_string('add'); ?>" title="" />
@@ -174,7 +185,7 @@ echo $OUTPUT->heading($instancename);
- + type="submit" value="rarrow(); ?>" title="" />