Moodle

Unable to assign capability to view hidden categories.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9, 1.9.1, 1.9.2
  • Fix Version/s: 1.9.4
  • Component/s: Course
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

We have a series of nested hidden categories and would like to give some teachers and possibly some students access to view them. Created a role called CanSeeHiddenCats that only has the moodle/category:visibility capability assigned.

Then, went to the category and assigned that role to the selected user, that user gets an error stating 'That is not currently available'.

Looking at /course/category.php, I see two sections of code that seem to control this:

Lines 42 - 57:

if (has_capability('moodle/course:create', $context)) {
if ($categoryedit !== -1) { $USER->categoryediting = $categoryedit; }
$navbaritem = update_category_button($category->id);
$creatorediting = !empty($USER->categoryediting);
$adminediting = (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and $creatorediting);

} else {
if (!$category->visible) { print_error('notavailable', 'error'); }
$navbaritem = print_course_search("", true, "navbar");
$adminediting = false;
$creatorediting = false;

and lines 266-287:

/// Print out all the sub-categories
if ($subcategories = get_records("course_categories", "parent", $category->id, "sortorder ASC")) {
$firstentry = true;
foreach ($subcategories as $subcategory) {
if ($subcategory->visible or has_capability('moodle/course:create', $context)) {
$subcategorieswereshown = true;
if ($firstentry) { echo '<table border="0" cellspacing="2" cellpadding="4" class="generalbox boxaligncenter">'; echo '<tr><th scope="col">'.get_string('subcategories').'</th></tr>'; echo '<tr><td style="white-space: nowrap">'; $firstentry = false; }
$catlinkcss = $subcategory->visible ? "" : " class=\"dimmed\" ";
echo '<a '.$catlinkcss.' href="category.php?id='.$subcategory->id.'">'.
format_string($subcategory->name).'</a><br />';
}
}
if (!$firstentry) { echo "</td></tr></table>"; echo "<br />"; }
}

In both of these two sections of code, we are dealing with category visibility, and yet the check is for moodle/course:create. I suggest that this be changed to moodle/category:visibility instead.

Making this change now allows those users with the CanSeeHiddenCats capability on the category level to actually see those hidden categories, by going to the URL we give them.

Activity

Hide
Ron Meske added a comment -

We would rather see the ability of allowing a user to see a hidden category at the root level and only those categories they have been given a role that allows them to see it. That way you can have a mix of hidden and visible categories at the root level and selectively assign users to see only those hidden categories they should have access to.

Show
Ron Meske added a comment - We would rather see the ability of allowing a user to see a hidden category at the root level and only those categories they have been given a role that allows them to see it. That way you can have a mix of hidden and visible categories at the root level and selectively assign users to see only those hidden categories they should have access to.
Hide
Tim Hunt added a comment -

Grabbing a bunch of related course category editing bugs that I plan to work on. Sorry for all the emails.

Show
Tim Hunt added a comment - Grabbing a bunch of related course category editing bugs that I plan to work on. Sorry for all the emails.
Hide
Ron Meske added a comment -

Please see this forum post (http://moodle.org/mod/forum/discuss.php?d=105409#p465110) for a solution, that is currently being tested, that allows hidden categories to be selectively assigned to users. This allows a user assigned to a hidden category to only see that hidden category and none of the other hidden categories.

This does not limit the users seen by a "teacher" when given the capability to Assign Roles. This type of change requires the ability of limiting users to some subset of all users based on a user profile field.

Show
Ron Meske added a comment - Please see this forum post (http://moodle.org/mod/forum/discuss.php?d=105409#p465110) for a solution, that is currently being tested, that allows hidden categories to be selectively assigned to users. This allows a user assigned to a hidden category to only see that hidden category and none of the other hidden categories. This does not limit the users seen by a "teacher" when given the capability to Assign Roles. This type of change requires the ability of limiting users to some subset of all users based on a user profile field.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: