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

API core_group_create_groups() does NOT accept the same group id between the different courses

XMLWordPrintable

    • MOODLE_33_STABLE
    • MOODLE_33_STABLE, MOODLE_34_STABLE
    • MDL-60637-master
    • Hide

      The goal of this test is to make sure you can create groups and groupings using an ID number that is being used by another group/grouping in a different course.

      SETUP
      1. You will need 2 courses (A, B) can be existing, please make note of the course ids.
      2. On course B, click on the cog and then select Moore...
      3. On Course administration, click on Users tab and then click Groups.
      4. Create a group (A) and a grouping (A) and set the ID number to something unique for both and make note of this ID NUMBER.
      5. On your moodle integration instance, run the command: mdk run webservices and make note of the token.
      GROUPS
      1. Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the group on the course B:

        curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groups&groups[0][courseid]=COURSE_A_ID_HERE&groups[0][name]=group1&groups[0][idnumber]=UNIQUE_ID_NUMBER_HERE&groups[0][description]=desc&wstoken=WEB_SERVICE_TOKEN_HERE' | python -m json.tool
        

        It should return something like this:

        [
            {
                "courseid": 1,
                "description": "desc",
                "descriptionformat": 1,
                "enrolmentkey": "",
                "id": 14,
                "idnumber": "123",
                "name": "group1"
            }
        ]
        

      2. Execute the exact same WS request again and this time, you should get an exception:

        {
            "debuginfo": "Group with the same name already exists in the course",
            "errorcode": "invalidparameter",
            "exception": "invalid_parameter_exception",
            "message": "Invalid parameter value detected"
        }
        

      GROUPINGS
      1. Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the grouping on the course B:

        curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groupings&groupings[0][courseid]=COURSE_A_ID_HERE&groupings[0][name]=grouping1&groupings[0][description]=groupingdescription&groupings[0][idnumber]=UNIQUE_ID_NUMBER_HERE&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool
        

        #It should return something like this, make note of the id:

        [
            {
                "courseid": 1,
                "description": "groupingdescription",
                "descriptionformat": 1,
                "id": 2,
                "idnumber": "123",
                "name": "grouping1"
            }
        ]
        

      2. Run the same WS request again, just changing the name now It should return an exception saying the

        {
            "errorcode": "idnumbertaken",
            "exception": "moodle_exception",
            "message": "This ID number is already in use"
        }
        

      3. Now, let's test grouping update. Create another grouping in the course A and try to change its ID number to the already existing one.

        curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_update_groupings&groupings[0][id]=GROUPING_ID&groupings[0][name]=grouping2&groupings[0][description]=groupingdescription&groupings[0][idnumber]=IDNUMBER&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool
        

      4. You should see something like:

        {
            "errorcode": "idnumbertaken",
            "exception": "moodle_exception",
            "message": "This ID number is already in use"
        }
        

      Show
      The goal of this test is to make sure you can create groups and groupings using an ID number that is being used by another group/grouping in a different course. SETUP You will need 2 courses (A, B) can be existing, please make note of the course ids. On course B, click on the cog and then select Moore... On Course administration, click on Users tab and then click Groups . Create a group (A) and a grouping (A) and set the ID number to something unique for both and make note of this ID NUMBER . On your moodle integration instance, run the command: mdk run webservices and make note of the token . GROUPS Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the group on the course B : curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groups&groups[0][courseid]=COURSE_A_ID_HERE&groups[0][name]=group1&groups[0][idnumber]=UNIQUE_ID_NUMBER_HERE&groups[0][description]=desc&wstoken=WEB_SERVICE_TOKEN_HERE' | python -m json.tool It should return something like this: [ { "courseid": 1, "description": "desc", "descriptionformat": 1, "enrolmentkey": "", "id": 14, "idnumber": "123", "name": "group1" } ] Execute the exact same WS request again and this time, you should get an exception: { "debuginfo": "Group with the same name already exists in the course", "errorcode": "invalidparameter", "exception": "invalid_parameter_exception", "message": "Invalid parameter value detected" } GROUPINGS Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the grouping on the course B : curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groupings&groupings[0][courseid]=COURSE_A_ID_HERE&groupings[0][name]=grouping1&groupings[0][description]=groupingdescription&groupings[0][idnumber]=UNIQUE_ID_NUMBER_HERE&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool #It should return something like this, make note of the id: [ { "courseid": 1, "description": "groupingdescription", "descriptionformat": 1, "id": 2, "idnumber": "123", "name": "grouping1" } ] Run the same WS request again, just changing the name now It should return an exception saying the { "errorcode": "idnumbertaken", "exception": "moodle_exception", "message": "This ID number is already in use" } Now, let's test grouping update. Create another grouping in the course A and try to change its ID number to the already existing one. curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_update_groupings&groupings[0][id]=GROUPING_ID&groupings[0][name]=grouping2&groupings[0][description]=groupingdescription&groupings[0][idnumber]=IDNUMBER&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool You should see something like: { "errorcode": "idnumbertaken", "exception": "moodle_exception", "message": "This ID number is already in use" }

      We can make the sage group idnumber between different courses by Moodleweb interface.
      But using API core_group_create_groups(), same idnumber is prohibited with the message of 'Invalid parameter'.
      The API core_group_create_groupings() has the same problem.

        1. screenshot-1.png
          94 kB
          David Mudrák (@mudrd8mz)

            lameze Simey Lameze
            matsuzakit Takeshi Matsuzaki
            Shamim Rezaie Shamim Rezaie
            Jun Pataleta Jun Pataleta
            David Mudrák (@mudrd8mz) David Mudrák (@mudrd8mz)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.