Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-12081

Teachers cannot import courses despite moodle/site:import = allow

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: 1.8.4, 1.9, 2.0
    • Component/s: Backup, Roles / Access
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE

      Description

      Teacher role:

      • moodle/site:restore = prevent/prohibit (to prevent teachers from restoring courses from zipped course backups)
      • moodle/site:import = allow (to allow teachers to import activities etc. directly from other courses)

      Behavior:

      • Teachers don't see the restore icon in admin block and cannot restore courses --> ok
      • Teachers do see the import icon in admin block --> ok
      • Teachers cannot import activities etc. from other courses --> BUG (error message: "You need to be a teacher or admin user to use this page.")

      Cause:
      Several files used during the import process only check for moodle/site:restore but NOT for moodle/site:import

      Fix:

      PART 1: /moodle/backup/restore.php, 1.40.6.2, line 48:

      if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id))

      { $to = $SESSION->restore->course_id; }

      if (!empty($id)) {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id)) and !has_capability('moodle/site:import', get_context_instance(\CONTEXT_COURSE, $id))) { // Knierim: grant access if import is allowed
      if (empty($to))

      { error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); } else {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) and !has_capability('moodle/site:import', get_context_i\nstance(CONTEXT_COURSE, $to))) { // Knierim: grant access if import is allowed error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); }
      }
      }

      PART 2: /moodle/backup/restore_execute.html, 1.61.6.1, line 23:

      {{{
      //Check admin
      if (!empty($id)) {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
      if (empty($to)) { error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); }

      else {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) and !has_capability('moodle/site:import', get_context_i\nstance(CONTEXT_COURSE, $to)))

      { // Knierim: grant access if import is allowed error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); }

      }
      }
      } else {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID)))

      { error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php"); }
      }
      }}}

      PART 3: /moodle/backup/restore_precheck.html, 1.18 ,line 15:

      {{{
      //Check admin
      if (!empty($id)) {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
      if (empty($to)) { error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); } else {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) and !has_capability('moodle/site:import', get_context_i\nstance(CONTEXT_COURSE, $to))) { // Knierim: grant access if import is allowed error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); }
      }
      }
      } else {
      if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) { error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php"); }

      }
      }}}

      Can someone verify this bug and my fix? TIA

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Jan/08