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

Allow user profile fields to be specified as user identity fields

XMLWordPrintable

    • MOODLE_26_STABLE, MOODLE_311_STABLE
    • MOODLE_311_STABLE
    • MDL-45242-master
    • Hide
      1. Create a few custom user profile fields. At least one of these should be a 'text' type, with a maximum length of 255 characters or less, and one should be some other type, such as 'datetime'.
      2. For a test user, set up values for these custom user profile fields.
      3. Go to Site administration > Users > Permissions > User policies and look at the 'Show user identity' setting.
        • EXPECTED: The custom text fields you created (but not the datetime field) should appear in the list of checkboxes, at the bottom, with asterisks * by each name. Text explains the these fields might not work on all screens.
      4. Turn on the checkboxes next to your new field(s).
      5. Go to Site administration > Users > Accounts > Browse list of users, and find the test user you set up.
        • EXPECTED: There should be a column corresponding to the custom field(s) ticked in 'Show user identity'. It should include the value for your test user.
      6. Use the 'Show more' option and find the section about custom profile fields; select the custom field and type in some text for search for, then click 'Add filter'.
        • EXPECTED (no change): The search should find the relevant user.
      7. Go to a course. Enrol the test user in the course (or choose a course they're already enrolled in).
      8. Go to the Participants page.
        • EXPECTED: There should be a column corresponding to the custom field(s) ticked in 'Show user identity'. It should include the value for your test user.
      9. Using the filter section at the top, select 'Keyword' and type the value of a custom field for your test user. Press Return or Tab to finalise the value, then press 'Apply filters'.
        • EXPECTED: Your test user should be selected because they match the filter, while other users should not be shown.
      10. Un-enrol the test user from the course.
      11. Attempt to enrol the test user again, but this time (in the enrol popup) type the value of a custom field for your test user.
        • EXPECTED: It should find the test user based on the custom field.
        • EXPECTED: In the little popup that shows you which user you selected, the value of the custom field should be shown (as well as the name and any other identity fields that were selected e.g. email).
      Show
      Create a few custom user profile fields. At least one of these should be a 'text' type, with a maximum length of 255 characters or less, and one should be some other type, such as 'datetime'. For a test user, set up values for these custom user profile fields. Go to Site administration > Users > Permissions > User policies and look at the 'Show user identity' setting. EXPECTED: The custom text fields you created (but not the datetime field) should appear in the list of checkboxes, at the bottom, with asterisks * by each name. Text explains the these fields might not work on all screens. Turn on the checkboxes next to your new field(s). Go to Site administration > Users > Accounts > Browse list of users, and find the test user you set up. EXPECTED: There should be a column corresponding to the custom field(s) ticked in 'Show user identity'. It should include the value for your test user. Use the 'Show more' option and find the section about custom profile fields; select the custom field and type in some text for search for, then click 'Add filter'. EXPECTED (no change): The search should find the relevant user. Go to a course. Enrol the test user in the course (or choose a course they're already enrolled in). Go to the Participants page. EXPECTED: There should be a column corresponding to the custom field(s) ticked in 'Show user identity'. It should include the value for your test user. Using the filter section at the top, select 'Keyword' and type the value of a custom field for your test user. Press Return or Tab to finalise the value, then press 'Apply filters'. EXPECTED: Your test user should be selected because they match the filter, while other users should not be shown. Un-enrol the test user from the course. Attempt to enrol the test user again, but this time (in the enrol popup) type the value of a custom field for your test user. EXPECTED: It should find the test user based on the custom field. EXPECTED: In the little popup that shows you which user you selected, the value of the custom field should be shown (as well as the name and any other identity fields that were selected e.g. email).

      At present the "Show user identity" option under "User Policies" only permits the following fields to be shown as part of the user identity.

      It would add some additional flexibility if custom user profile fields could be presented as an option.

      For instance, our ID number field is filled with an institutionally unique identifier for each user, however this information is pretty much only internally used.

      Students are issued with a Registration Number each time the start a programme of study. This is much more commonly used to identify students on a daily basis, but as a custom profile field it cannot be shown on some of the more useful locations, such as the list of submissions into a class, user selection lists (e.g. enrolment)

      Implementation

      New behaviour for users

      • The admin setting lists all 'text' type custom fields that have a maximum length of 255 characters or less, so you can choose these fields. Updated description text warns users that the custom fields do not work everywhere. [See screenshot]
      • I have modified the code so that three features work with these options: 'Browse list of users', the Participants page list of users, and the 'Enrol' option on the participants page.
      • In other screens, behaviour will be as before with custom fields not shown.

      Developer changes

      • Custom fields can be specified in $CFG->showuseridentity as 'profile_field_<shortname>', e.g. 'profile_field_favouritecolour'.
      • New API \core\user_fields can be used to create lists of user fields, and SQL query fragments for getting them (which use LEFT JOIN to get any custom fields). It covers identity fields (showuseridentity), fields required for user pictures, and fields required for full names.

      Compatibility

      • The corresponding existing functions are all deprecated: get_extra_user_fields(), get_extra_user_fields_sql(), get_user_field_name(), get_all_user_name_fields(), and user_picture::fields(). All the features from these functions are subsumed into the new API.
      • All existing code that called the deprecated functions, or used the $CFG variable directly, has been modified to use the new API. (The API option to exclude custom profile fields has been used, so that this massive change could be made without significant code changes.)

      Modifying existing code

      • As noted I only made it work for three features because it's far too much effort (and testing) to fix everywhere.
      • It is usually relatively easy to fix each individual feature; the three commits for these features are quite short.

        1. 3.10-backport-of-MDL-45242-MDL-71131-MDL-7109.patch
          75 kB
          Sam Marshall
        2. MDL-45242-browseusers.png
          35 kB
          Sam Marshall
        3. MDL-45242-participants.png
          27 kB
          Sam Marshall
        4. MDL-45242-settings.png
          27 kB
          Sam Marshall
        5. patch-per-extra-fields-report.txt
          10 kB
          Alex Laudani
        6. Screenshot_1.jpg
          81 kB
          Janelle Barcega
        7. Screenshot_2.jpg
          59 kB
          Janelle Barcega

            Votes:
            22 Vote for this issue
            Watchers:
            41 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days
                2d

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