mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-23839 navigation: Check for assignable course category roles
This commit is contained in:
parent
a74d4743e1
commit
494cf9b81c
42
course/tests/behat/category_role_assignment.feature
Normal file
42
course/tests/behat/category_role_assignment.feature
Normal file
@ -0,0 +1,42 @@
|
||||
@core @core_course
|
||||
Feature: Role assignments can be made at the category level
|
||||
In order to grant a user different capabilities
|
||||
As a user
|
||||
I can assign roles in categories
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname |
|
||||
| manager | Manager | Manager |
|
||||
And the following "categories" exist:
|
||||
| name | category | idnumber |
|
||||
| Cat 1 | 0 | CAT1 |
|
||||
And the following "role assigns" exist:
|
||||
| user | role | contextlevel | reference |
|
||||
| manager | manager | Category | CAT1 |
|
||||
And I log in as "admin"
|
||||
|
||||
|
||||
@javascript
|
||||
Scenario: A user with a category role can assign roles
|
||||
Given I define the allowed role assignments for the "Manager" role as:
|
||||
| Teacher | Assignable |
|
||||
And I log out
|
||||
And I log in as "manager"
|
||||
And I follow "Courses"
|
||||
When I follow "Cat 1"
|
||||
Then I should see "Assign roles"
|
||||
|
||||
@javascript
|
||||
Scenario: A user with a category role cannot assign roles if there are no roles to assign
|
||||
Given I define the allowed role assignments for the "Manager" role as:
|
||||
| Manager | Not assignable |
|
||||
| Course creator | Not assignable |
|
||||
| Teacher | Not assignable |
|
||||
| Non-editing teacher | Not assignable |
|
||||
| Student | Not assignable |
|
||||
And I log out
|
||||
And I log in as "manager"
|
||||
And I follow "Courses"
|
||||
When I follow "Cat 1"
|
||||
Then I should not see "Assign roles"
|
@ -4419,7 +4419,7 @@ class settings_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
// Assign local roles
|
||||
if (has_capability('moodle/role:assign', $catcontext)) {
|
||||
if (!empty(get_assignable_roles($catcontext))) {
|
||||
$assignurl = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid' => $catcontext->id));
|
||||
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
|
||||
}
|
||||
|
@ -176,4 +176,61 @@ class behat_permissions extends behat_base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the allowed role assignments for the specified role.
|
||||
*
|
||||
* @Given /^I define the allowed role assignments for the "(?P<rolefullname_string>(?:[^"]|\\")*)" role as:$/
|
||||
* @param string $rolename
|
||||
* @param TableNode $table
|
||||
* @return void Executes other steps
|
||||
*/
|
||||
public function i_define_the_allowed_role_assignments_for_a_role_as($rolename, $table) {
|
||||
$parentnodes = get_string('administrationsite') . ' > ' .
|
||||
get_string('users', 'admin') . ' > ' .
|
||||
get_string('permissions', 'role');
|
||||
return array(
|
||||
new Given('I am on homepage'),
|
||||
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'),
|
||||
new Given('I follow "Allow role assignments"'),
|
||||
new Given('I fill in the allowed role assignments form for the "' . $rolename . '" role with:', $table),
|
||||
new Given('I press "' . get_string('savechanges') . '"')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the allowed role assignments form for the specied role.
|
||||
*
|
||||
* Takes a table with two columns. Each row should contain the target
|
||||
* role, and either "Assignable" or "Not assignable".
|
||||
*
|
||||
* @Given /^I fill in the allowed role assignments form for the "(?P<rolefullname_string>(?:[^"]|\\")*)" role with:$/
|
||||
* @param String $sourcerole
|
||||
* @param TableNode $table
|
||||
* @return void
|
||||
*/
|
||||
public function i_fill_in_the_allowed_role_assignments_form_for_a_role_with($sourcerole, $table) {
|
||||
foreach ($table->getRows() as $key => $row) {
|
||||
list($targetrole, $allowed) = $row;
|
||||
|
||||
$node = $this->find('xpath', '//input[@title="Allow users with role ' .
|
||||
$sourcerole .
|
||||
' to assign the role ' .
|
||||
$targetrole . '"]');
|
||||
|
||||
if ($allowed == 'Assignable') {
|
||||
if (!$node->isChecked()) {
|
||||
$node->click();
|
||||
}
|
||||
} else if ($allowed == 'Not assignable') {
|
||||
if ($node->isChecked()) {
|
||||
$node->click();
|
||||
}
|
||||
} else {
|
||||
throw new ExpectationException(
|
||||
'The provided permission value "' . $allowed . '" is not valid. Use Assignable, or Not assignable',
|
||||
$this->getSession()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user