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

Allow core_user_get_users to use OR as well as AND

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Reopened
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.0
    • Fix Version/s: None
    • Component/s: Web Services
    • Labels:
    • Testing Instructions:
      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.
    • Affected Branches:
      MOODLE_30_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-50508-master

      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

              • Assignee:
                jethac Jetha Chan
                Reporter:
                jethac Jetha Chan
                Peer reviewer:
                Ankit Agarwal
                Integrator:
                David Monllaó
                Participants:
                Component watchers:
                Juan Leyva, Jake Dallimore, Jun Pataleta
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: