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

core_messages_search_contacts external service doesn't work

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Enable messaging in the site
      2. Create a couple of users accounts, user1 and user2
      3. Enable "Mobile services": Plugins ► Web Services ► External services
      4. Create a Token for the Mobile app service (for user1):
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
        • Note that this only will work for Moodle 2.8 and master, for older versions you need to create a custom service named "whatever" including the core_messages_search_contacts function and create the token for this service
      5. Next, you can do a CURL REST call simulating a WS client:
        • Replace searchtext with the first name of user2
        • You also need to replace the wstoken and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'searchtext=something&onlymycourses=0&wsfunction=core_message_search_contacts&wstoken=6137368848c2710566a04917efd5d74d' --compressed
          

      6. Confirm that:
        • The command returns a list of users matching the name you used for searching (except the current user that is excluded from the search)
      Show
      Enable messaging in the site Create a couple of users accounts, user1 and user2 Enable "Mobile services": Plugins ► Web Services ► External services Create a Token for the Mobile app service (for user1): Click on Site administration ► Plugins ► Web services ► Manage tokens Note that this only will work for Moodle 2.8 and master, for older versions you need to create a custom service named "whatever" including the core_messages_search_contacts function and create the token for this service Next, you can do a CURL REST call simulating a WS client: Replace searchtext with the first name of user2 You also need to replace the wstoken and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'searchtext=something&onlymycourses=0&wsfunction=core_message_search_contacts&wstoken=6137368848c2710566a04917efd5d74d' --compressed Confirm that: The command returns a list of users matching the name you used for searching (except the current user that is excluded from the search)
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-48578-master

      Description

      It returns a 500 error since it's calling the function user_get_details that it's in user/lib.php. The function doesn't require that file.

      The fix is obvious, just include after the search_contacts function declaration the require:

      public static function search_contacts() {
                global $CFG;
                require_once($CFG->dirroot . '/user/lib.php');
      

        Attachments

          Activity

            People

            Assignee:
            jleyva Juan Leyva
            Reporter:
            jleyva Juan Leyva
            Peer reviewer:
            David Monllaó
            Integrator:
            Eloy Lafuente (stronk7)
            Tester:
            John Okely
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              9/Mar/15