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

User profile field names should be filtered in WebServices

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE
    • MDL-77967-403
    • MDL-77967-main
    • Hide
      1. As admin, enable "Enable web services for mobile devices": Site administration ► Advanced features
      2. Install Spanish additional language packs in your site via Site administration ► Language ► Language packs
        • Search for Spanish (international) and install it
      3. Create or use an existing student user in the platform (no admin)
      4. Create a Token in the mobile app service for the student user:
        • Click on Site administration ► Server ► Web services ► Manage tokens
      5. Create a "User profile field": Site administration ► Users ► Accounts ►  User profile fields ► Create a new profile field
        • Select and create a checkbox
        • Put this HTML in the Name of the profile field to add the multilang filter in it: 

          <span lang="en" class="multilang">Check in english</span><span lang="es" class="multilang">Check en español</span>

      1. Enable Multilang filter: Site administration ► Plugins ► Filters ► Manage filters ► Multi-language content
        • Enable it and set "Apply to" to "Content and headings"
      2. Go to the student profile and check if the filter is working
        • The profile field name must see just: Check in english

      TESTING THE WEB SERVICES

      1. Do the CURL REST calling simulating a WS client with the student user.
        • You need to replace the wstoken, studentemail is the email from the student, and the URL of your moodle instance

          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the field with type "checkbox" and the "name" is: Check in english
      2. Now add the moodlewssettingfilter param as true in the request to enable the filtering in the request, and moodlewssettinglang to specify we want the contents in English.

        curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail&moodlewssettingfilter=true&moodlewssettinglang=en' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english
      2. Now repeat the request but changing the value of moodlewssettinglang to 'es'.

        curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail&moodlewssettingfilter=true&moodlewssettinglang=es' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the a field with type "checkbox" and the "name" is: Check en español
      2. Now we'll do the same for WS core_user_get_course_user_profiles.
      3. Create an empty or testing course and enrol the student user in it. Save the course id to use in the request
      4. Do the CURL REST calling simulating a WS client with the student user. 
        • You need to replace the $wstoken, $userid and $courseid, and the URL of your moodle instance

          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=false' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english
      2. Now set the moodlewssettingfilter param as true in the request to enable the filtering in the request, and moodlewssettinglang to specify we want the contents in English.
      3. curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=true&moodlewssettinglang=en' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english
      2. Now repeat the request but changing the value of moodlewssettinglang to 'es'.

        curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=true&moodlewssettinglang=es' --compressed

      1. Confirm that:
        • You receive the student object in the response
        • The "customfields" contains the a field with type "checkbox" and the "name" is: Check en español
      Show
      As admin, enable "Enable web services for mobile devices": Site administration ► Advanced features Install Spanish additional language packs in your site via Site administration ► Language ► Language packs Search for Spanish (international) and install it Create or use an existing student user in the platform (no admin) Create a Token in the mobile app service for the student user: Click on Site administration ► Server ► Web services ► Manage tokens Create a "User profile field": Site administration ► Users ► Accounts ►  User profile fields ► Create a new profile field Select and create a checkbox Put this HTML in the Name of the profile field to add the multilang filter in it:  <span lang="en" class="multilang">Check in english</span><span lang="es" class="multilang">Check en español</span> Enable Multilang filter: Site administration ► Plugins ► Filters ► Manage filters ► Multi-language content Enable it and set "Apply to" to "Content and headings" Go to the student profile and check if the filter is working The profile field name must see just: Check in english TESTING THE WEB SERVICES Do the CURL REST calling simulating a WS client with the student user. You need to replace the wstoken, studentemail is the email from the student, and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail' --compressed Confirm that: You receive the student object in the response The "customfields" contains the field with type "checkbox" and the "name" is: Check in english Now add the moodlewssettingfilter param as true in the request to enable the filtering in the request, and moodlewssettinglang to specify we want the contents in English. curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail&moodlewssettingfilter=true&moodlewssettinglang=en' --compressed Confirm that: You receive the student object in the response The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english Now repeat the request but changing the value of moodlewssettinglang to 'es'. curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_users_by_field&wstoken=$wstoken&field=email&values[]=$studentemail&moodlewssettingfilter=true&moodlewssettinglang=es' --compressed Confirm that: You receive the student object in the response The "customfields" contains the a field with type "checkbox" and the "name" is: Check en español Now we'll do the same for WS core_user_get_course_user_profiles. Create an empty or testing course and enrol the student user in it. Save the course id to use in the request Do the CURL REST calling simulating a WS client with the student user.  You need to replace the $wstoken, $userid and $courseid, and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=false' --compressed Confirm that: You receive the student object in the response The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english Now set the moodlewssettingfilter param as true in the request to enable the filtering in the request, and moodlewssettinglang to specify we want the contents in English. curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=true&moodlewssettinglang=en' --compressed Confirm that: You receive the student object in the response The "customfields" contains the a field with type "checkbox" and the "name" is: Check in english Now repeat the request but changing the value of moodlewssettinglang to 'es'. curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_user_get_course_user_profiles&wstoken=$wstoken&userlist%5B0%5D%5Buserid%5D=$userid&userlist%5B0%5D%5Bcourseid%5D=$courseid&moodlewssettingfilter=true&moodlewssettinglang=es' --compressed Confirm that: You receive the student object in the response The "customfields" contains the a field with type "checkbox" and the "name" is: Check en español

      Some user WebServices return the custom profile fields (e.g. core_user_get_course_user_profiles and core_user_get_users_by_field). The name of these fields can have multilang tags, so it should be filtered but right now it isn't.

      The signup WebService (auth_email_get_signup_settings) does filter this field, so that one shouldn't be changed.

      To reproduce:

      • Enable the multi-lang filter in name
      • Install a couple of additional language packs
      • Create a new user profile field, using as the name of the field a text including multi-lang strings (span lang="en" class="multilang">Name in english</span><span lang="es" class="multilang">Nombre en español</span>)
      • Retrieve via WebServices the user information, for example calling core_user_get_course_user_profiles
      • Confirm that you are always receiving the names with multi-langs regardless if you pass as parameter &moodlewssettingfilter=true to force text filtering or not

      The expected result once this is fixed would be:

      • The name with multi-lang tags not filtered is returned when &moodlewssettingfilter is set to false
      • The name filtered (in your current language) without tags when &moodlewssettingfilter is set to true

            rodrigo.mady@moodle.com Rodrigo Mady
            dpalou Dani Palou
            Dani Palou Dani Palou
            Andrew Lyons Andrew Lyons
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 days, 4 hours, 41 minutes
                3d 4h 41m

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