Moodle

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major 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

Issue Links

Activity

Hide
Chris Fryer added a comment -

I can confirm your code changes work on our installation of Moodle 1.8.3. I've put your changes in a patch file (attached).

Show
Chris Fryer added a comment - I can confirm your code changes work on our installation of Moodle 1.8.3. I've put your changes in a patch file (attached).
Hide
Chris Fryer added a comment -

Can somebody remove the original patch, please? It contains an error (and non-standard whitespace formatting). A proper file is attached (import-corrected.patch).

Sorry,

Chris

Show
Chris Fryer added a comment - Can somebody remove the original patch, please? It contains an error (and non-standard whitespace formatting). A proper file is attached (import-corrected.patch). Sorry, Chris
Hide
Helen Foster added a comment -

Original patch deleted, as requested.

Thanks for the patch, Chris.

Show
Helen Foster added a comment - Original patch deleted, as requested. Thanks for the patch, Chris.
Hide
Helen Foster added a comment -

Reassigning to roles expert Yu

Show
Helen Foster added a comment - Reassigning to roles expert Yu
Hide
Yu Zhang added a comment -

Thanks for the patch, in CVS now. Cheers, Yu

Show
Yu Zhang added a comment - Thanks for the patch, in CVS now. Cheers, Yu
Hide
Sam Hemelryk added a comment -

All works correctly thanks

Show
Sam Hemelryk added a comment - All works correctly thanks
Hide
Jonathan Langevin added a comment -

I'm still getting this same error, in 1.9.8, while the teacher has import permission, and doesn't have restore permission.
Did this error reintroduce itself, or was it included in a release after 1.9.8, or just overlooked entirely?

Show
Jonathan Langevin added a comment - I'm still getting this same error, in 1.9.8, while the teacher has import permission, and doesn't have restore permission. Did this error reintroduce itself, or was it included in a release after 1.9.8, or just overlooked entirely?
Hide
Ing. Arturo Robles added a comment -

i have this problem when i'am importing a course appear this message You need to be an admin user to use this page.i can't fix i don¡t understand how to applicate the solution. can you helpe please? step by step

Show
Ing. Arturo Robles added a comment - i have this problem when i'am importing a course appear this message You need to be an admin user to use this page.i can't fix i don¡t understand how to applicate the solution. can you helpe please? step by step

Dates

  • Created:
    Updated:
    Resolved: