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

Allow core_user_get_users to use OR as well as AND

    XMLWordPrintable

Details

    • Improvement
    • Status: Reopened
    • Minor
    • Resolution: Unresolved
    • 3.0
    • None
    • Web Services
    • MOODLE_30_STABLE
    • MDL-50508-master
    • Hide

      Automated test

      • Run PHPUnit tests in user/tests/externallib_test.php.

      Manual test

      • Using Chrome, login to your Moodle as an admin with some users enrolled using the MDK users script.
      • Open the web inspector's Javascript console and paste in:

        require(['jquery', 'core/ajax'], function($, ajax, templates) {
            var doTest = function(value) {
                var webservice = 'core_user_get_users';
                var promises = ajax.call([
                    {
                        methodname: webservice,
                        args: {
                            "criteria": [
         
                                { "key": "firstname", "value": value + "%" },
                                { "key": "lastname", "value": value + "%" }
         
                            ],
                            "mode": "loose"
                        }
                    }
                ]);
                promises[0]
                    .done(function(response){
                        console.log(response);
                    });
            }
            // invoke tester
            doTest('ad')
            return doTest;
        });
        

      • Verify that one user is returned without warnings, and it's the admin user.
      • Modify the parameter passed to doTest() to 'st' and paste it in again.
      • Verify that 3 users are returned without warnings, and it's Stan, Butters and Bebe.
      • Set the mode to "strict" and keep the parameter as 'st'.
      • Verify that 0 users are returned without warnings.
      Show
      Automated test Run PHPUnit tests in user/tests/externallib_test.php. Manual test Using Chrome, login to your Moodle as an admin with some users enrolled using the MDK users script. Open the web inspector's Javascript console and paste in: require(['jquery', 'core/ajax'], function($, ajax, templates) { var doTest = function(value) { var webservice = 'core_user_get_users'; var promises = ajax.call([ { methodname: webservice, args: { "criteria": [   { "key": "firstname", "value": value + "%" }, { "key": "lastname", "value": value + "%" }   ], "mode": "loose" } } ]); promises[0] .done(function(response){ console.log(response); }); } // invoke tester doTest('ad') return doTest; }); Verify that one user is returned without warnings, and it's the admin user. Modify the parameter passed to doTest() to 'st' and paste it in again. Verify that 3 users are returned without warnings, and it's Stan, Butters and Bebe. Set the mode to "strict" and keep the parameter as 'st'. Verify that 0 users are returned without warnings.

    Description

      Currently criteria passed to the external function core_user_get_users are concatenated together using AND; kind of like:

      give me users that haven't been deleted AND criteria1 AND criteria2
      

      Unfortunately, there are some cases where you'll want to do a query with an OR, e.g.

      give me users that haven't been deleted AND ( criteria2 OR criteria2 )
      

      This patch makes the external function in question accessible from core/ajax and introduces a new optional parameter, mode, which can have two values:

      • 'strict': group criteria using AND, which is extant behavior)
      • 'loose': group criteria using OR

      As the parameter is optional (and defaults to extant behavior), existing uses of the function do not need to be updated - the previous calling convention can be used.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jethac Jetha Chan
              Ankit Agarwal Ankit Agarwal
              David Monllaó David Monllaó
              Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: