Details
Description
To reproduce.
Create a quiz
Locally assign in that quiz the teacher role to a student.
Login in the course as that student and enter the quiz (edit tab)
You can't create new questions. You got the message "You don't have permission to add questions here."
a workaround:
create a question subcategory under the default for the quiz
go back editing the quiz, select the subcategory (you can create questions there) and select again the default category for the quiz. Now you can create new questions in the quiz's default category. As long as there's another category in the quiz this trick works (selecting the subcategory and back again the default category in the category select menu)
We track down the problem to the function question_make_default_categories() as it returns only the categories in the course context. So to fix this we change the CONTEXT_COURSE for the CONTEXT_MODULE. The function is always called from a quiz so the module context makes more sense than the course context.
— moodle/lib/questionlib.original.php,v 1.119.2.13 2008/07/10 09:48:44
+++ moodle/lib/questionlib.php 2009-03-12 10:09:29.000000000 +0100
@@ -1903,7 +1903,7 @@
}
}
}
- if ($context->contextlevel == CONTEXT_COURSE)Unknown macro: {+ if ($context->contextlevel == CONTEXT_MODULE){ $toreturn = clone($category); } }
We tested this solution on a 1.9.2 moodle with a 8.2.4 postgres installed in a SUSE Linux Enterprise Server 10 SP1
Actually, it is intentional that is uses the course context by default, to make it easy for teacher to share questions between their quizzes.
However, you are right. If the user does not have permission to add questions in the course context, and does have permission in the Quiz context, we should default to the quiz context instead.
Would you like to come up with an alternate patch, or shall I do it?