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

Batch create API for grade categories

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Setup

      1) Enable web services for the site, and enable the rest protocol.

      2) Go to "Admin -> Plugins -> Web services -> External services" and add a service named 'gradecat, enabled, and add the function 'core_grades_create_gradecategories' to it.

      3) Go to "Admin -> Plugins -> Web services -> Manage tokens" and add a token for the Admin user account and the just created "gradecat" service, so there are no permission issues. Annotate it for later use.

      4) Create a blank test course to test the webservice in. Annotate its "courseid" from the url.

      5) Visit the gradebook setup page for the newly created course.

      Testing

      6) Open a terminal (with curl installed)

      7) Execute the following command to call the webservice with basic parameters

       

      curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test" | json_pp
      

       

      (replacing LOCATION with the install location, and TOKEN and COURSEID with the values annotated above)

      8) Verify that the returned JSON in the terminal contains the field 'categoryids' with a number, and the warnings array is empty. Make note of the categoryid

      9) Reload the gradebook setup, and verify that there is now a grade category underneath the course grade category, called 'Test'.

      10) Execute the following command with the annotated token, courseid and categoryid from above.

       

      curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test2&categories[0][options][parentcategoryid]={CATEGORYID}&categories[0][options][idnumber]=IDNumber" | json_pp
      

       

       11) Verify the returned JSON contains a similar response to the above command, with no warnings

      12) Reload the gradebook setup and verify there is now a 'Test 2' category nested as a child of the 'Test category'

      13) Edit the Test2 Gradecategory settings and confirm that the ID number field is set to 'IDNumber'

      15) Now we are going to create 2 categories in a single call, nested  and connected using IDnumbers.

       

      curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Parent&categories[0][options][idnumber]=parent&categories[1][fullname]=Child&categories[1][options][idnumber]=child&categories[1][options][parentcategoryidnumber]=parent" | json_pp
      

       
      16) Verify there is now 2 more categories, under the top level, called Parent and Child, and that Child is a subcategory of Parent

      17) Run one more curl command, with data that is invalid.
       

      curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test4&categories[0][options][grademax]=1&categories[0][options][grademin]=2" | json_pp
      

       

      18) Verify that there  is no category ID returned, and that there is a warning for invalidgrade for item grademax.

      19) Verify that there is no Test4 Category created in the gradebook setup page.

       

      The rest is covered by unit tests

      Show
      Setup 1) Enable web services for the site, and enable the rest protocol. 2) Go to "Admin -> Plugins -> Web services -> External services" and add a service named 'gradecat, enabled, and add the function 'core_grades_create_gradecategories' to it. 3) Go to "Admin -> Plugins -> Web services -> Manage tokens" and add a token for the Admin user account and the just created "gradecat" service, so there are no permission issues. Annotate it for later use. 4) Create a blank test course to test the webservice in. Annotate its "courseid" from the url. 5) Visit the gradebook setup page for the newly created course. Testing 6) Open a terminal (with curl installed) 7) Execute the following command to call the webservice with basic parameters   curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test" | json_pp   (replacing LOCATION with the install location, and TOKEN and COURSEID with the values annotated above) 8) Verify that the returned JSON in the terminal contains the field 'categoryids' with a number, and the warnings array is empty. Make note of the categoryid 9) Reload the gradebook setup, and verify that there is now a grade category underneath the course grade category, called 'Test'. 10) Execute the following command with the annotated token, courseid and categoryid from above.   curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test2&categories[0][options][parentcategoryid]={CATEGORYID}&categories[0][options][idnumber]=IDNumber" | json_pp    11) Verify the returned JSON contains a similar response to the above command, with no warnings 12) Reload the gradebook setup and verify there is now a 'Test 2' category nested as a child of the 'Test category' 13) Edit the Test2 Gradecategory settings and confirm that the ID number field is set to 'IDNumber' 15) Now we are going to create 2 categories in a single call, nested  and connected using IDnumbers.   curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Parent&categories[0][options][idnumber]=parent&categories[1][fullname]=Child&categories[1][options][idnumber]=child&categories[1][options][parentcategoryidnumber]=parent" | json_pp   16) Verify there is now 2 more categories, under the top level, called Parent and Child, and that Child is a subcategory of Parent 17) Run one more curl command, with data that is invalid.   curl "{LOCATION}/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategories&moodlewsrestformat=json&courseid={COURSEID}&categories[0][fullname]=Test4&categories[0][options][grademax]=1&categories[0][options][grademin]=2" | json_pp   18) Verify that there  is no category ID returned, and that there is a warning for invalidgrade for item grademax. 19) Verify that there is no Test4 Category created in the gradebook setup page.   The rest is covered by unit tests
    • Affected Branches:
      MOODLE_311_STABLE, MOODLE_400_STABLE
    • Fixed Branches:
      MOODLE_311_STABLE
    • Pull 3.11 Branch:
      MDL-71031_311
    • Pull Master Branch:

      Description

      This is exactly the same as MDL-67306, but in hindsite that should have always accepted an array of categories and not a single one.

      We'll deprecate the old one as part of this.

       

      See also

      https://github.com/moodle/moodle/blob/master/lib/classes/grades_external.php#L417-L424

       

        Attachments

        1. MDL-71031.jpg
          61 kB
          Anna Carissa Sadia

          Issue Links

            Activity

              People

              Assignee:
              peterburnett Peter Burnett
              Reporter:
              brendanheywood Brendan Heywood
              Peer reviewer:
              Brendan Heywood Brendan Heywood
              Integrator:
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Tester:
              Anna Carissa Sadia Anna Carissa Sadia
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/May/21

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 40 minutes
                  3h 40m