Moodle
  1. Moodle
  2. MDL-8902

get_my_courses returns all courses with permission to access, not just enrolled courses

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8, 1.9
    • Fix Version/s: 2.0
    • Component/s: Libraries
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      3440

      Description

      The datalib function get_my_courses returns all courses that the current user has permission to view. For example, for an admin it returns every course on the site. This can cause performance and also interface problems.

      In the past for a quick fix I added a limit parameter which you can use to resolve performance problems (calling the function as-is for admin requires many thousand database queries if you have thousands of courses). However the real issue is that usually when this function is called, you actually want the enrolled courses i.e. courses which people have an actual role in.

      I would suggest making get_my_courses deprecated and creating two functions get_my_permitted_courses (which is the same as current, and is what get_my_courses calls) and get_my_enrolled_courses. get_my_enrolled_courses would basically restrict the list to include only those courses you have a specific role in (as well as having the course:view permission).

      (note, eloy asked me to file this bug! blame him!

        Issue Links

          Activity

            People

            • Votes:
              12 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: