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

New web Services for checking access requirements to quizzes and attempts

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.2, 3.1
    • Fix Version/s: 3.1
    • Component/s: Quiz, Web Services
    • Labels:
    • Testing Instructions:
      Hide
      1. Bump your /version.php file to force Moodle to reload the Mobile service
      2. Create a course with a student.
      3. Create a new quiz with 3 different question types, the last one should be a random question type pointing to a category with at least two different question types
      4. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      5. Create a Token for the student user
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Next, you can do a CURL REST call simulating a WS client with the student user .
        • You need to replace the wstoken, quizid (the quiz instance value) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      7. Confirm that
        • You see the following values to true: canattempt, canreviewmyattempts
      8. Execute the following curl request

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_required_qtypes&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      9. And check that you receive all the question types used, including the ones in the random category
      10. Now as admin or teacher edit the quiz settings, add a password restriction, limit the number of attempts two 1 and add a future date for time open and time close
      11. Run the WS again, check that now: in accessrules you see listed all the new settings you applied, in preventaccessreasons you see "This quiz is not currently available" (because is not open yet)
      12. Now, as admin, remove all the restrictions except the attempt number that must be 1
      13. Now, as the student, access the Moodle web interface and do the quiz one time (do one attempt and ensure that is finished)
      14. Run the following query using the student token again

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_attempt_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      15. You should see that preventnewattemptreasons says "No more attempts are allowed" and isfinished set to true
      Show
      Bump your /version.php file to force Moodle to reload the Mobile service Create a course with a student. Create a new quiz with 3 different question types, the last one should be a random question type pointing to a category with at least two different question types As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student user Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with the student user . You need to replace the wstoken, quizid (the quiz instance value) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed Confirm that You see the following values to true: canattempt, canreviewmyattempts Execute the following curl request curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_required_qtypes&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed And check that you receive all the question types used, including the ones in the random category Now as admin or teacher edit the quiz settings, add a password restriction, limit the number of attempts two 1 and add a future date for time open and time close Run the WS again, check that now: in accessrules you see listed all the new settings you applied, in preventaccessreasons you see "This quiz is not currently available" (because is not open yet) Now, as admin, remove all the restrictions except the attempt number that must be 1 Now, as the student, access the Moodle web interface and do the quiz one time (do one attempt and ensure that is finished) Run the following query using the student token again curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_attempt_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed You should see that preventnewattemptreasons says "No more attempts are allowed" and isfinished set to true
    • Affected Branches:
      MOODLE_30_STABLE, MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-52767-master

      Description

      This function returns general access information, is basically a wrapper of the access manager class that returns some capabilities information too.

      Information returned will be:

      canmanage
      canattempt
      canreviewmine
      canpreview
      canviewreports
      canreviewmyattempts
      endtime
      isfinished
      ispreflightcheckrequired
      accessrules
      preventaccessreasons
      preventnewattemptreasons

      This web service also returns the question types used in the quiz, including the potential ones (in case random questions are used).
      This is necessary because we'll need to check the question types before starting a new attempt to determine if the quiz can be open in the app (initially the app won't support all question types or contrib add-ons)

      Please, note that we finally decided to split in 3 functions:

      • mod_quiz_get_quiz_access_information
      • mod_quiz_get_attempt_access_information
      • mod_quiz_get_quiz_required_qtypes

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  23/May/16