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

Numeric user IDs throws error while creating users in Matrix

XMLWordPrintable

    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MDL-80849-403
    • MDL-80849-404
    • MDL-80849-main
    • Hide

      Setup Matrix mock for testing

      Use the Matrix mock server found here and follow the instructions to set up.

      If the pull request has been accepted, use this mock:

      https://github.com/moodlehq/matrixsynapse_mock

      If it hasn't, get mock below and checkout 'MDL-80849' branch

      https://github.com/davewoloszyn/matrixsynapse_mock

      Test Matrix mock changes

      This scenario will use PHPUnit to confirm the matrixsynapse_mock is throwing an error when it should.

      1. ENSURE you have the Matrix mock running using setup above.
      2. Checkout the 'main' branch (we don't want my patch yet)
      3. Locate the communication/provider/matrix/tests/communication_feature_test.php file
      4. Locate the test_create_members method.
      5. Modify this test to create a user with a numeric username. You can just replace the current $user with this: 

        $user = $this->getDataGenerator()->create_user(['username' => '12345'])
        

      6. Run the test.
      7. CONFIRM you see an error: 

        {"errcode":"M_INVALID_USERNAME","error":"Numeric user IDs are reserved for guest users."}
        

      Setup Matrix for Moodle

      1. Clone Andrew's helper repository:

        git clone https://github.com/andrewnicols/moodle-synapse
        cd moodle-synapse
        chmod 777 *_data
        

      2. Run the docker-compose up command:

        docker compose up -d
        

      3. Wait for about 10 seconds for the first run to complete
      4. Run the setup script:

        ./setup.sh
        

      5. Copy the command it outputs
      6. Change into your Moodle directory
      7. Paste in the command, for EXAMPLE:

        cd path/to/moodle
        sed -i '/^require_once.*lib.*setup.php.*$/i require_once("/Users/nicols/git/moodlehq/synapse/moodle-config.php");' config.php
        cd -
        

      8. If you have not done so already, edit your /etc/hosts file to add:

        127.0.0.1 element.container.docker.internal element
        127.0.0.1 synapse.container.docker.internal synapse
        127.0.0.1 keycloak.container.docker.internal keycloak
        

      9. Follow the instructions at https://github.com/andrewnicols/moodle-synapse#trusting to trust the root CA that is used for this.

      Test Moodle changes

      This scenario will test the changes in Moodle and addresses this tracker issue specifically.

      1. ENSURE you have your Matrix set up for Moodle as described above.
      2. ENSURE you are checked out to this patch branch
      3. Log in as admin.
      4. Create a course.
      5. Enable Matrix as the communication provider on the course (More -> Communication)
      6. Create a user with the username '123456'
      7. Enrol the user into the course.
      8. Run cron (this will create the Matrix room and attempt to enrol the user)
      9. CONFIRM there were no errors during cron.
      10. Go to your Matrix client (E.g. Element)
      11. CONFIRM that the user was added to the room
      12. Go back to Moodle and edit the newly created user's profile.
      13. Locate the 'Communication' section
      14. CONFIRM the value in 'Matrix user id' has the word 'user' prepended to the username. It may look something like this: '@user123456:localhost'

       

      Show
      Setup Matrix mock for testing Use the Matrix mock server found here and follow the instructions to set up. If the pull request has been accepted, use this mock: https://github.com/moodlehq/matrixsynapse_mock If it hasn't, get mock below and checkout ' MDL-80849 ' branch https://github.com/davewoloszyn/matrixsynapse_mock Test Matrix mock changes This scenario will use PHPUnit to confirm the matrixsynapse_mock is throwing an error when it should. ENSURE you have the Matrix mock running using setup above. Checkout the 'main' branch (we don't want my patch yet) Locate the communication/provider/matrix/tests/communication_feature_test.php file Locate the test_create_members method. Modify this test to create a user with a numeric username. You can just replace the current $user with this:  $user = $this ->getDataGenerator()->create_user([ 'username' => '12345' ]) Run the test. CONFIRM you see an error:  {"errcode":"M_INVALID_USERNAME","error":"Numeric user IDs are reserved for guest users."} Setup Matrix for Moodle Clone Andrew's helper repository: git clone https://github.com/andrewnicols/moodle-synapse cd moodle-synapse chmod 777 *_data Run the docker-compose up command: docker compose up -d Wait for about 10 seconds for the first run to complete Run the setup script: ./setup.sh Copy the command it outputs Change into your Moodle directory Paste in the command, for EXAMPLE : cd path/to/moodle sed -i '/^require_once.*lib.*setup.php.*$/i require_once("/Users/nicols/git/moodlehq/synapse/moodle-config.php");' config.php cd - If you have not done so already, edit your /etc/hosts file to add: 127.0.0.1 element.container.docker.internal element 127.0.0.1 synapse.container.docker.internal synapse 127.0.0.1 keycloak.container.docker.internal keycloak Follow the instructions at https://github.com/andrewnicols/moodle-synapse#trusting to trust the root CA that is used for this. Test Moodle changes This scenario will test the changes in Moodle and addresses this tracker issue specifically. ENSURE you have your Matrix set up for Moodle as described above. ENSURE you are checked out to this patch branch Log in as admin. Create a course. Enable Matrix as the communication provider on the course ( More -> Communication ) Create a user with the username '123456' Enrol the user into the course. Run cron (this will create the Matrix room and attempt to enrol the user) CONFIRM there were no errors during cron. Go to your Matrix client (E.g. Element) CONFIRM that the user was added to the room Go back to Moodle and edit the newly created user's profile. Locate the 'Communication' section CONFIRM the value in 'Matrix user id' has the word 'user' prepended to the username. It may look something like this: '@user123456:localhost'  
    • 2
    • Team Hedgehog 2024 Sprint 1.4, Team Hedgehog 2024 Review 1

      When the ad hoc task runs to add users to a room, if any of the users have only numbers as a username, then an error is thrown.

      {"errcode":"M_INVALID_USERNAME","error":"Numeric user IDs are reserved for guest users."}

       

      Important note: We should update the mock for this. Mock will be happy with the change we make, but that is a problem.

        1. confirm 1.png
          41 kB
          Stevani Andolo
        2. confirm 2.png
          357 kB
          Stevani Andolo
        3. confirm 3.png
          91 kB
          Stevani Andolo
        4. MDL-80849_004.png
          155 kB
          Ferran Recio

            david.woloszyn@moodle.com David Woloszyn
            safat.shahin@moodle.com Safat Shahin
            Meirza Meirza
            Huong Nguyen Huong Nguyen
            Stevani Andolo Stevani Andolo
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 4 hours, 28 minutes
                2d 4h 28m

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