mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
enrol MDL-23447 Others users page now only lists roles that have moodle/course:view
This commit is contained in:
parent
cb184beb24
commit
9f15347e2c
@ -86,7 +86,8 @@ switch ($action) {
|
||||
break;
|
||||
|
||||
case 'getassignable':
|
||||
$outcome->response = $manager->get_assignable_roles();
|
||||
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
|
||||
$outcome->response = $manager->get_assignable_roles($otheruserroles);
|
||||
break;
|
||||
case 'getcohorts':
|
||||
require_capability('moodle/course:enrolconfig', $context);
|
||||
|
@ -90,6 +90,7 @@ class course_enrolment_manager {
|
||||
private $_plugins = null;
|
||||
private $_roles = null;
|
||||
private $_assignableroles = null;
|
||||
private $_assignablerolesothers = null;
|
||||
private $_groups = null;
|
||||
/**#@-*/
|
||||
|
||||
@ -438,11 +439,25 @@ class course_enrolment_manager {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_assignable_roles() {
|
||||
public function get_assignable_roles($otherusers = false) {
|
||||
if ($this->_assignableroles === null) {
|
||||
$this->_assignableroles = get_assignable_roles($this->context, ROLENAME_ALIAS, false); // verifies unassign access control too
|
||||
}
|
||||
return $this->_assignableroles;
|
||||
|
||||
if ($otherusers) {
|
||||
if (!is_array($this->_assignablerolesothers)) {
|
||||
$this->_assignablerolesothers = array();
|
||||
list($courseviewroles, $ignored) = get_roles_with_cap_in_context($this->context, 'moodle/course:view');
|
||||
foreach ($this->_assignableroles as $roleid=>$role) {
|
||||
if (isset($courseviewroles[$roleid])) {
|
||||
$this->_assignablerolesothers[$roleid] = $role;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_assignablerolesothers;
|
||||
} else {
|
||||
return $this->_assignableroles;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ $table->set_fields($fields);
|
||||
$renderer = $PAGE->get_renderer('core_enrol');
|
||||
$canassign = has_capability('moodle/role:assign', $manager->get_context());
|
||||
$users = $manager->get_other_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
|
||||
$assignableroles = $manager->get_assignable_roles();
|
||||
$assignableroles = $manager->get_assignable_roles(true);
|
||||
foreach ($users as $userid=>&$user) {
|
||||
$user['picture'] = $OUTPUT->render($user['picture']);
|
||||
$user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $pageurl);
|
||||
|
@ -494,7 +494,8 @@ class course_enrolment_table extends html_table implements renderable {
|
||||
$arguments = array(
|
||||
'containerId'=>$this->id,
|
||||
'userIds'=>array_keys($users),
|
||||
'courseId'=>$this->manager->get_course()->id);
|
||||
'courseId'=>$this->manager->get_course()->id,
|
||||
'otherusers'=>isset($this->otherusers));
|
||||
$page->requires->yui_module($modules, $function, array($arguments));
|
||||
}
|
||||
}
|
||||
@ -719,6 +720,8 @@ class course_enrolment_users_table extends course_enrolment_table {
|
||||
*/
|
||||
class course_enrolment_other_users_table extends course_enrolment_table {
|
||||
|
||||
public $otherusers = true;
|
||||
|
||||
/**
|
||||
* Constructs the table
|
||||
*
|
||||
|
@ -208,7 +208,7 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) {
|
||||
getAssignableRoles : function() {
|
||||
Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
|
||||
method:'POST',
|
||||
data:'id='+this.get(COURSEID)+'&action=getassignable&sesskey='+M.cfg.sesskey,
|
||||
data:'id='+this.get(COURSEID)+'&action=getassignable&otherusers=true&sesskey='+M.cfg.sesskey,
|
||||
on: {
|
||||
complete: function(tid, outcome, args) {
|
||||
try {
|
||||
@ -340,8 +340,10 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) {
|
||||
var options = args.node.ancestor('.'+CSS.OPTIONS);
|
||||
if (options.all('.'+CSS.ROLEOPTION).size() == 1) {
|
||||
// This is the last node so remove the options div
|
||||
if (options.ancestor('.'+CSS.USER)) {
|
||||
options.ancestor('.'+CSS.USER).addClass(CSS.ALLROLESASSIGNED);
|
||||
}
|
||||
options.remove();
|
||||
options.ancestor(CSS.USER).addClass(CSS.ALLROLESASSIGNED);
|
||||
} else {
|
||||
// There are still more assignable roles
|
||||
args.node.remove();
|
||||
|
@ -1,4 +1,4 @@
|
||||
.enrolpanel {display:none;position:absolute;background-color:#666;padding:0 5px;}
|
||||
.enrolpanel {display:none;position:absolute;background-color:#666;padding:0 5px;min-width:200px;}
|
||||
.enrolpanel.visible {display:block;}
|
||||
.enrolpanel .container {position:relative;background-color:#fff;border:1px solid #999;top:-5px;}
|
||||
.enrolpanel .container .header {border-bottom:1px solid #999;}
|
||||
|
26
enrol/yui/rolemanager/rolemanager.js
vendored
26
enrol/yui/rolemanager/rolemanager.js
vendored
@ -14,7 +14,8 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
|
||||
UNASSIGNROLELINKS = 'unassignRoleLinks',
|
||||
UNASSIGNROLELINKSSELECTOR = 'unassignRoleLinksSelector',
|
||||
MANIPULATOR = 'manipulator',
|
||||
CURRENTROLES = 'currentroles';
|
||||
CURRENTROLES = 'currentroles',
|
||||
OTHERUSERS = 'otherusers';
|
||||
|
||||
var ROLE = function(config) {
|
||||
ROLE.superclass.constructor.apply(this, arguments);
|
||||
@ -47,6 +48,9 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
|
||||
},
|
||||
assignableRoles : {
|
||||
value : []
|
||||
},
|
||||
otherusers : {
|
||||
value : false
|
||||
}
|
||||
}
|
||||
Y.extend(ROLE, Y.Base, {
|
||||
@ -144,10 +148,15 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
|
||||
});
|
||||
},
|
||||
_loadAssignableRoles : function() {
|
||||
var c = this.get(COURSEID);
|
||||
var c = this.get(COURSEID), params = {
|
||||
id : this.get(COURSEID),
|
||||
otherusers : (this.get(OTHERUSERS))?'true':'false',
|
||||
action : 'getassignable',
|
||||
sesskey : M.cfg.sesskey
|
||||
};
|
||||
Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
|
||||
method:'POST',
|
||||
data:'id='+this.get(COURSEID)+'&action=getassignable&sesskey='+M.cfg.sesskey,
|
||||
data:build_querystring(params),
|
||||
on: {
|
||||
complete: function(tid, outcome, args) {
|
||||
try {
|
||||
@ -357,10 +366,12 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
|
||||
element.one('.header .close').on('click', this.hide, this);
|
||||
},
|
||||
display : function(user) {
|
||||
var currentroles = user.get(CURRENTROLES);
|
||||
var currentroles = user.get(CURRENTROLES), node = null;
|
||||
for (var i in currentroles) {
|
||||
if (currentroles[i] === true) {
|
||||
this.get('contentNode').one('#add_assignable_role_'+i).setAttribute('disabled', 'disabled');
|
||||
if (node = this.get('contentNode').one('#add_assignable_role_'+i)) {
|
||||
node.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
this.roles.push(i);
|
||||
}
|
||||
}
|
||||
@ -378,8 +389,11 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
|
||||
this._escCloseEvent.detach();
|
||||
this._escCloseEvent = null;
|
||||
}
|
||||
var node = null;
|
||||
for (var i in this.roles) {
|
||||
this.get('contentNode').one('#add_assignable_role_'+this.roles[i]).removeAttribute('disabled');
|
||||
if (node = this.get('contentNode').one('#add_assignable_role_'+i)) {
|
||||
node.removeAttribute('disabled');
|
||||
}
|
||||
}
|
||||
this.roles = [];
|
||||
this.user = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user