Moodle
  1. Moodle
  2. MDL-18531

Students locally assigned as teachers can't create new questions

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.2
    • Fix Version/s: 1.9.5
    • Component/s: Questions, Quiz
    • Labels:
      None
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      26250

      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

      1. default_category.patch.txt
        2 kB
        Tim Hunt
      2. newpatch_questionlib.txt
        0.5 kB
        Yolanda Ordoñez Rufat
      3. patch_questionlib.txt
        0.4 kB
        Yolanda Ordoñez Rufat
      1. edit_quiz.png
        64 kB

        Activity

        Hide
        Tim Hunt added a comment -

        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?

        Show
        Tim Hunt added a comment - 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?
        Hide
        Yolanda Ordoñez Rufat added a comment -

        new patch reflecting Tim's comments

        Show
        Yolanda Ordoñez Rufat added a comment - new patch reflecting Tim's comments
        Hide
        Yolanda Ordoñez Rufat added a comment -

        You're right, I just didn't think about the rest of the quizzes for the theacher to share the questions.

        So we should check first if the user has the capability for adding question in the course context and if he doesn't default to the quiz context.

        I come up with this new patch

        — questionlib.original.php,v 1.119.2.13 2008/07/10 09:48:44 +0200
        +++ questionlib.php 2009-03-12 10:09:29.000000000 +0100
        @@ -1903,7 +1903,9 @@
        }
        }
        }

        • if ($context->contextlevel == CONTEXT_COURSE)
          Unknown macro: {+ if ($context->contextlevel == CONTEXT_COURSE and has_capability('moodle/question}
        Show
        Yolanda Ordoñez Rufat added a comment - You're right, I just didn't think about the rest of the quizzes for the theacher to share the questions. So we should check first if the user has the capability for adding question in the course context and if he doesn't default to the quiz context. I come up with this new patch — questionlib.original.php,v 1.119.2.13 2008/07/10 09:48:44 +0200 +++ questionlib.php 2009-03-12 10:09:29.000000000 +0100 @@ -1903,7 +1903,9 @@ } } } if ($context->contextlevel == CONTEXT_COURSE) Unknown macro: {+ if ($context->contextlevel == CONTEXT_COURSE and has_capability('moodle/question}
        Hide
        Tim Hunt added a comment -

        Here is a further improved patch it finds the best choice of category in which the user has 'moodle/question:add', where best is defined as COURSE > MODULE> COURSECAT > SYSTEM. I'll commit this tomorrow, after the weekly builds have been released.

        Show
        Tim Hunt added a comment - Here is a further improved patch it finds the best choice of category in which the user has 'moodle/question:add', where best is defined as COURSE > MODULE> COURSECAT > SYSTEM. I'll commit this tomorrow, after the weekly builds have been released.
        Hide
        Tim Hunt added a comment -

        Fixed. Thanks for the report.

        Show
        Tim Hunt added a comment - Fixed. Thanks for the report.
        Hide
        Sam Hemelryk added a comment -

        Tested and passed, the issue appears resolved Thanks guys

        Show
        Sam Hemelryk added a comment - Tested and passed, the issue appears resolved Thanks guys

          People

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

            Dates

            • Created:
              Updated:
              Resolved: