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

User fields: Some remaining uses of deprecated functions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.11, 4.0
    • Fix Version/s: 3.11
    • Component/s: User management
    • Labels:
    • Affected Branches:
      MOODLE_311_STABLE, MOODLE_400_STABLE
    • Fixed Branches:
      MOODLE_311_STABLE
    • Pull Master Branch:
      MDL-71215-master
    • Testing Instructions:
      Hide

      The only substantive code change is a change to the get_ws_authorised_users function, only used by service_users.php, here is how to test that page:

      1. Add a custom user profile field to your test Moodle (Users > Accounts > User profile fields). The field should be a text type and with max length e.g. 100 characters (otherwise it doesn't appear on the list for the next step).
      2. Add this field in the 'show user identity' option (Users > Permissions > User policies). You can leave whatever other fields you like ticked, e.g. 'email' from default.
      3. For a test user account, edit their profile and set a value for the new user profile field.
      4. Go to the external services page (Plugins > Web services > External services) and click Add
        • Set the name and short name to any suitable values you like, but make sure to tick the 'Authorised users only' box.
        • When you get to the 'Add functions to the service...' page, don't add functions. Instead, go back to the 'External services' page from the breadcrumbs.
      5. Click on the 'Authorised users' link next to your new service.
      6. In the list of unauthorised users, search for and select the user where you set up the account, and click 'Add'.
        • NOTE: The custom profile field ideally ought to display in the selector and be searchable, but that is an existing TODO elsewhere in the code not implemented here - so in the selector, you won't see the custom field, and that's OK.
      7. Look below the selector.
        • You should see the list of authenticated users including the user you just added.
        • Below the name of the user it should show all the user identity fields including the custom field
      Show
      The only substantive code change is a change to the get_ws_authorised_users function, only used by service_users.php, here is how to test that page: Add a custom user profile field to your test Moodle (Users > Accounts > User profile fields). The field should be a text type and with max length e.g. 100 characters (otherwise it doesn't appear on the list for the next step). Add this field in the 'show user identity' option (Users > Permissions > User policies). You can leave whatever other fields you like ticked, e.g. 'email' from default. For a test user account, edit their profile and set a value for the new user profile field. Go to the external services page (Plugins > Web services > External services) and click Add Set the name and short name to any suitable values you like, but make sure to tick the 'Authorised users only' box. When you get to the 'Add functions to the service...' page, don't add functions. Instead, go back to the 'External services' page from the breadcrumbs. Click on the 'Authorised users' link next to your new service. In the list of unauthorised users, search for and select the user where you set up the account, and click 'Add'. NOTE: The custom profile field ideally ought to display in the selector and be searchable, but that is an existing TODO elsewhere in the code not implemented here - so in the selector, you won't see the custom field, and that's OK. Look below the selector. You should see the list of authenticated users including the user you just added. Below the name of the user it should show all the user identity fields including the custom field

      Description

      Eloy found some uses still in Moodle of the functions that were now deprecated as a result of MDL-45242. These should be fixed to use the new APIs so that we don't have any calls to the deprecated functions (outside of tests etc).

      $ ag \
          'get_extra_user_fields|get_user_field_name|get_all_user_name_fields|user_picture::fields' \
          --ignore='*tests*' --ignore=upgrade.txt --ignore=deprecatedlib.php --ignore=lib/outputcomponents.php
      enrol/locallib.php
      1229:     * @param array $extrafields The list of fields as returned from get_extra_user_fields used to determine which
       
      webservice/renderer.php
      109:        $extrafields = get_extra_user_fields(context_system::instance());
       
      webservice/lib.php
      291:        $namefields = get_all_user_name_fields(true, 'u');
      293:        foreach (get_extra_user_fields(context_system::instance()) as $extrafield) {
       
      lib/datalib.php
      308: *  - those returned by get_extra_user_fields
      337: * @param context $context the context we are in. Use by get_extra_user_fields.
       
      mod/quiz/report/overview/report.php
      485:     * table, with the get_all_user_name_fields from the user table joined in.
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              quen Sam Marshall
              Reporter:
              quen Sam Marshall
              Peer reviewer:
              Huong Nguyen Huong Nguyen
              Integrator:
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Tester:
              Anna Carissa Sadia Anna Carissa Sadia
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/May/21

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 5 minutes
                  3h 5m