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

Unique user profile fields do not allow duplicate empty values

    Details

    • Testing Instructions:
      Hide

      Pre-requisite:

      1. Custom profile field (Text input) with "Should the data be unique" set to YES and "Is this field required" set to NO
      2. Custom profile field (Text input) with "Should the data be unique" set to YES and "Is this field required" set to YES

      Steps to create custom profile field.

      1. Log in as admin
      2. Click on user profile field (Site administration ► Users ► Accounts ► User profile fields)
      3. Select "Text input"

      Test 1

      1. Log in as student, click edit profile (Home ► My profile settings ► Edit profile)
      2. Click "Update profile" and you should see "Required" error on Unique-required field.
      3. Input "TEST" in Unique-required field and leave Unique custom field blank.
      4. Click update profile and it should update student profile.
      5. Log in as another student and edit profile.
      6. Input "TEST" in Unique-required field and leave Unique custom field blank.
      7. You should see error (This value has already been used) for Unique-required field.
      8. Change "Unique-required" field value to "TEST1"
      9. Update profile and you should not see any problem.

      Test 2:

      1. Log in as student 1 and go to edit profile.
      2. Input "TEST" in Unique profile field and click update profile
      3. Log in as another student and go to edit profile
      4. Input "TEST" in Unique profile field and click update profile
      5. You should see error.
      6. Change it to "TEST1" and click update profile
      7. Profile should be updated without error.
      Show
      Pre-requisite: Custom profile field (Text input) with "Should the data be unique" set to YES and "Is this field required" set to NO Custom profile field (Text input) with "Should the data be unique" set to YES and "Is this field required" set to YES Steps to create custom profile field. Log in as admin Click on user profile field (Site administration ► Users ► Accounts ► User profile fields) Select "Text input" Test 1 Log in as student, click edit profile (Home ► My profile settings ► Edit profile) Click "Update profile" and you should see "Required" error on Unique-required field. Input "TEST" in Unique-required field and leave Unique custom field blank. Click update profile and it should update student profile. Log in as another student and edit profile. Input "TEST" in Unique-required field and leave Unique custom field blank. You should see error (This value has already been used) for Unique-required field. Change "Unique-required" field value to "TEST1" Update profile and you should not see any problem. Test 2: Log in as student 1 and go to edit profile. Input "TEST" in Unique profile field and click update profile Log in as another student and go to edit profile Input "TEST" in Unique profile field and click update profile You should see error. Change it to "TEST1" and click update profile Profile should be updated without error.
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull Master Branch:
      wip-mdl-37339

      Description

      The user profile fields allow 2 settings: Required and Unique.

      It appears from edit_validate_field() function in /user/profile/lib.php that required-ness is only checked by the form's UI and unique-ness by the edit_validate_field() function.

      It appears that empty values are subjected to a unique-ness check. We store user matriculation numbers and library numbers in profile fields, which are unique but not required (as only students have matric. numbers and only library users have library numbers).

      In this case with Required == 0 and Unique == 1, adding a new staff (matric =="" and librarycard = "") results in the value already used message. We've fudge it by making the field's non-unique...but they should be if they have a value!

      I would suggest that either there is an option that allows or prevents empty values thus excluding "" from the unique-ness check, but controllable on a per-field basis (as there may be valid cases when it should never be emtpy)
      -or -
      to ensure that the "required" setting is used for this purpose in the edit_validate_field() function.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Mar/13